Jump to content

User:Cenarium/protect-icon.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.
/*
<div class="metadata topicon nopopups" id="protected-icon" style="display:none; right:55px;">[[Image:Padlock.svg|20px|link=Wikipedia:Protection policy|Protected]]</div>
*/

// function to create html elements
function create(htmlStr) {
    var frag = document.createDocumentFragment(),
        temp = document.createElement('div');
    temp.innerHTML = htmlStr;
    while (temp.firstChild) {
        frag.appendChild(temp.firstChild);
    }
    return frag;
}

// protected icon html
var fragment = create('<div class="metadata topicon nopopups" id="protected-icon" style="display:none; right:55px;"><a href="/wiki/Wikipedia:Protection_policy" title="Protected"><img alt="Protected" src="/media/wikipedia/en/thumb/5/59/Padlock.svg/30px-Padlock.svg.png" srcset="/media/wikipedia/en/thumb/5/59/Padlock.svg/30px-Padlock.svg.png 1.5x, /media/wikipedia/en/thumb/5/59/Padlock.svg/40px-Padlock.svg.png 2x" data-file-width="128" data-file-height="128" height="20" width="20"></a></div>');

// insert
if ( $.inArray( 'Wikipedia protected pages', mw.config.get('wgCategories') ) !== -1 ) {
document.getElementById("bodyContent").insertBefore(fragment, document.getElementById("bodyContent").childNodes[0]);
}