MediaWiki:Common.js: Difference between revisions

From Honour Wiki
Jump to navigation Jump to search
(Created page with "→‎Any JavaScript here will be loaded for all users on every page load.: // Redirect top Edit tab to Page Forms edit URL on college pages mw.hook('wikipage.content').add(function () { var formButton = document.querySelector('a[href*="Special:FormEdit/CollegePage"]'); var editTab = document.querySelector('#ca-edit a'); if (formButton && editTab) { editTab.href = formButton.href; editTab.textContent = 'Edit'; } });")
 
No edit summary
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
// Force college page edits to open Page Forms instead of raw wikitext
// Redirect top Edit tab to Page Forms edit URL on college pages


mw.hook('wikipage.content').add(function () {
(function () {
    function pageTitle() {
        return mw.config.get('wgPageName');
    }
 
    function formEditUrl(title) {
        return mw.util.getUrl('Special:FormEdit/CollegePage/' + title);
    }
 
    function redirectIfRawCollegeEdit() {
        var action = mw.config.get('wgAction');
        var title = pageTitle();
 
        if (action === 'edit') {
            var textarea = document.querySelector('#wpTextbox1');
            if (textarea && textarea.value.indexOf('{{CollegePage') !== -1) {
                window.location.href = formEditUrl(title);
            }
        }
    }


     var formButton = document.querySelector('a[href*="Special:FormEdit/CollegePage"]');
     function rewriteEditTab() {
    var editTab = document.querySelector('#ca-edit a');
        var title = pageTitle();
        var formButton = document.querySelector('a[href*="Special:FormEdit/CollegePage"]');
        var editTab = document.querySelector('#ca-edit a');


    if (formButton && editTab) {
        if (formButton && editTab) {
        editTab.href = formButton.href;
            editTab.href = formEditUrl(title);
        editTab.textContent = 'Edit';
            editTab.textContent = 'Edit';
        }
     }
     }


});
    $(function () {
        redirectIfRawCollegeEdit();
        rewriteEditTab();
    });
})();

Revision as of 10:02, 16 May 2026

// Force college page edits to open Page Forms instead of raw wikitext

(function () {
    function pageTitle() {
        return mw.config.get('wgPageName');
    }

    function formEditUrl(title) {
        return mw.util.getUrl('Special:FormEdit/CollegePage/' + title);
    }

    function redirectIfRawCollegeEdit() {
        var action = mw.config.get('wgAction');
        var title = pageTitle();

        if (action === 'edit') {
            var textarea = document.querySelector('#wpTextbox1');
            if (textarea && textarea.value.indexOf('{{CollegePage') !== -1) {
                window.location.href = formEditUrl(title);
            }
        }
    }

    function rewriteEditTab() {
        var title = pageTitle();
        var formButton = document.querySelector('a[href*="Special:FormEdit/CollegePage"]');
        var editTab = document.querySelector('#ca-edit a');

        if (formButton && editTab) {
            editTab.href = formEditUrl(title);
            editTab.textContent = 'Edit';
        }
    }

    $(function () {
        redirectIfRawCollegeEdit();
        rewriteEditTab();
    });
})();