Jump to content

User:Ucucha/hiderefs.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.
var refs_hidden = false;

// hides refs if shown, shows them if hidden
function hiderefs()
{
    // can't use getElementsByClassName because IE apparently doesn't support it
    var refs = document.getElementsByTagName("sup");
    for(var i = 0; i < refs.length; i++)
    {
        if($(refs[i]).hasClass("reference"))
            refs[i].style.display = refs_hidden ? "inline" : "none";
    }
    // also hide reflist
    var reflists = document.getElementsByTagName("div");
    for(var i = 0; i < reflists.length; i++)
    {
        if(hasClass(reflists[i], "references"))
            reflists[i].style.display = refs_hidden ? "block" : "none";  
    }
    refs_hidden = refs_hidden ? false : true;
    document.getElementById("t-hide-refs").getElementsByTagName("span")[0].innerHTML = refs_hidden ? "Show references" : "Hide references";
}

addOnloadHook(
    function()
    {
        mw.util.addPortletLink('p-tb', 'javascript:hiderefs()', 'Hide references', 't-hide-refs', 'Shows/hides references', '', '');
    }
);