User:Anomie/fix-tab-text.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/* A simple javascript function to change the text in various tabs at the top of the
 * page. Only tested with the monobook skin.
 */
$(document).ready(function(){
    var fix=function(id, text){
        var el=document.getElementById(id);
        if(!el) return;
        for(el=el.firstChild; el && el.nodeName!='A'; el=el.nextSibling);
        if(!el) return;
        while(el.firstChild) el.removeChild(el.firstChild);
        el.appendChild(document.createTextNode(text));
        el.style.textTransform='none';
    }

    /* Add lines as necessary. Use the Firefox DOM inspector or some such to determine
     * the appropriate IDs.
     */
    fix('ca-talk', 'talk');
    fix('ca-edit', 'edit');
    fix('ca-ve-edit', 've');
    fix('ca-addsection', '+');
    fix('ca-move', 'move');
    fix('ca-delete', 'delete');
    fix('ca-protect', 'protect');
    fix('ca-unprotect', 'Δ protect');

    /* Fix the title of the history page */
    if(mw.config.get('wgAction')=='history'){
        document.title=mw.config.get('wgPageName').replace(/_/g,' ').replace(/^Wikipedia:/,'W:')+' - Wikipedia History';
        var h=document.getElementsByTagName('H1');
        if(h.length){
            h=h[0];
            while(h.firstChild) h.removeChild(h.firstChild);
            h.appendChild(document.createTextNode(mw.config.get('wgPageName').replace(/_/g,' ')));
        }
    }

    /* Fix button text to avoid horizontal scroll bars */
    var x=document.getElementById('mw-fr-submit-accept'); if(x) x.value='Accept';
    x=document.getElementById('mw-fr-submit-unaccept'); if(x) x.value='Unaccept';
});