Jump to content

User:Nihiltres/vector.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Nihiltres (talk | contribs) at 19:07, 20 October 2009 (Forgot the footer in the sidebar-toggling experiment… adding it now.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
// Tab name fixer (copied from User:Anomie/fix-tab-text.js, target content modified)
/* A simple javascript function to change the text in various tabs at the top of the
 * page. Only tested with the monobook skin.
 */
addOnloadHook(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));
    }

    /* Add lines as necessary. Use the Firefox DOM inspector or some such to determine
     * the appropriate IDs.
     */
//(disabled via commenting)    fix('ca-talk', 'discussion');
    fix('pt-preferences', 'Preferences');
    fix('pt-watchlist', 'Watchlist');
    fix('pt-mytalk', 'Talk');
    fix('pt-mycontris', 'Contributions');
});
//end tab name fixer

//Special additions of tabs and personal links
//--personal links
addOnloadHook(function() {
//----link to log
addPortletLink('p-personal','/wiki/Special:Log?user=Nihiltres','Log','pt-log','Log of your non-edit actions','',document.getElementById('pt-mycontris'));
if (wgPageName == "Special:Log" && document.getElementById('mw-log-user').value == "Nihiltres") {document.getElementById('pt-log').className='active';}
//----link to sandbox
addPortletLink('p-personal','/wiki/User:Nihiltres/Sandbox','Sandbox','pt-sandbox','Your sandbox','',document.getElementById('pt-preferences'));
if (wgPageName == "User:Nihiltres/Sandbox") {document.getElementById('pt-sandbox').className='active';}
});
//--tabs
//----purge tab
addOnloadHook(function() {
  if (wgCanonicalNamespace != 'Special')
    {
addPortletLink('p-cactions', wgServer + wgScript + '?title=' + escape(wgPageName) + '&action=purge', 'Purge', 'ca-purge', 'Purge the server cache of this page', null, (document.getElementById('ca-watch') ? document.getElementById('ca-watch') : document.getElementById('ca-unwatch')));
//and apply the "selected" class, so that one can confirm that the page has been purged. This subroutine is all my own, I'm so proud :p (disabled in Vector as the selected class might do funny things in the dropdown list.)
//    if (wgAction == "purge") {document.getElementById('ca-purge').className='selected';}
    }
});
//end special additions

//auto-check the "watch this page" tab when editing the MediaWiki namespace, my own code.
addOnloadHook(function() {
  if (wgCanonicalNamespace == 'MediaWiki' && wgAction == "edit") {document.getElementById('wpWatchthis').checked = true;}
});
//end auto-check for MediaWiki-space editing

//enable special user CSS and JS pages for while using my iPod Touch… somewhat experimental but should be quite useful.
addOnloadHook(function() {
  if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
    importStylesheet('User:Nihiltres/vector-ipod.css');
    importScript('User:Nihiltres/vector-ipod.js');
}});

//moves actions out of the menu and into the action tabs, use 
//moveActionOutOfMenu("ID OF ELEMENT TO BE MOVED", "ID OF ELEMENT IT SHOULD BE PLACED TO THE LEFT OF");
addOnloadHook(function(){
    var moveActionOutOfMenu=function(id, followingElement) {
        var itemToBeMoved = document.getElementById(id);
        if (!itemToBeMoved) return;
        if (!document.getElementById("p-views").contains(document.getElementById(id))) {
            document.getElementById("p-views").lastChild.previousSibling.insertBefore(document.getElementById(id), document.getElementById(followingElement));
            itemToBeMoved.firstChild.innerHTML = "<span>" + itemToBeMoved.firstChild.innerHTML + "</span>"; //so that it looks pretty… :|
            }
        }
//if the page is protected, show the unprotect button; serves also as an indicator for protection, indicating the value in the title. Disabled on iPod as generally unhelpful there.
    if ( (wgRestrictionEdit.concat( wgRestrictionMove )).length > 0 && !(navigator.userAgent.match(/iPhone/i)) && !(navigator.userAgent.match(/iPod/i))) { 
        moveActionOutOfMenu("ca-unprotect", "ca-history");
        if ( wgRestrictionEdit.length > 0 ) {
            var EditRestrictionString = "edit: [" + wgRestrictionEdit.join(", ") + "]";
        }
        else {
            var EditRestrictionString = "";
        }
        if ( wgRestrictionMove.length > 0 ) {
            var MoveRestrictionString = "move: [" + wgRestrictionMove.join(", ") + "]";
        }
        else {
            var MoveRestrictionString = "";
        }
        var RestrictionStringsArray = new Array();
        if (EditRestrictionString != "") {
            RestrictionStringsArray.push(EditRestrictionString)
        }
        if (MoveRestrictionString != "") {
            RestrictionStringsArray.push(MoveRestrictionString)
        }
        document.getElementById("ca-unprotect").firstChild.title = ("Unprotect this page (" + RestrictionStringsArray.join(", ") + ")");
    }
//the below snippet shows the delete tab if the page contains any of the standard class names for the deletion-template boxes.
//Yes, this makes for really ugly code. If you have a more elegant way to do this, I'd love to hear it.
    if (document.getElementsByClassName("ambox-speedy").length >= 1 || document.getElementsByClassName("ambox-delete").length >= 1 || document.getElementsByClassName("ombox-speedy").length >= 1 || document.getElementsByClassName("ombox-delete").length >= 1 || document.getElementsByClassName("imbox-speedy").length >= 1 || document.getElementsByClassName("imbox-delete").length >= 1 || document.getElementsByClassName("cmbox-speedy").length >= 1 || document.getElementsByClassName("cmbox-delete").length >= 1 || document.getElementsByClassName("tmbox-speedy").length >= 1 || document.getElementsByClassName("tmbox-delete").length >= 1 ) {
        moveActionOutOfMenu("ca-delete", "ca-history");
    }
    else {
        if (document.getElementsByClassName("redirectText").length == false) return;
        if (document.getElementsByClassName("redirectText").item(0).firstChild.href.search("redlink=1") != -1) {
            moveActionOutOfMenu("ca-delete", "ca-history");
            var cadeletelinks = document.getElementById("ca-delete").getElementsByTagName("a");
            if (cadeletelinks.length != 1) return;
            cadeletelinks.item(0).href = cadeletelinks.item(0).href + "&wpReason=%5B%5BWP%3ACSD%23G8%7CG8%5D%5D%3A%20Redirect%20to%20a%20deleted%20page";
        }
    }
//this little addendum detects redirects to redlinks (that is, non-existing pages) and both brings out the delete tab and gives it a decent automatic deletion reason.
});
//end element-out-of-menu bit




 var collapseSideBar=function(){
        var ct = document.getElementById("content");
        var ln = document.getElementById("left-navigation");
        var pn = document.getElementById("panel");
        var hb = document.getElementById("head-base");
        var cs = document.getElementById("ca-sidebar");
        var ft = document.getElementById("footer");
        if (!ct || !ln || !pn || !hb || !cs || !ft) return;
       pn.style.display = "none";
       ct.style.marginLeft = 0;
       hb.style.marginLeft = 0;
       ft.style.marginLeft = 0;
       ln.style.left = "1em";
       cs.firstChild.href = "javascript:expandSideBar()"
    }

 var expandSideBar=function(){
        var ct = document.getElementById("content");
        var ln = document.getElementById("left-navigation");
        var pn = document.getElementById("panel");
        var hb = document.getElementById("head-base");
        var cs = document.getElementById("ca-sidebar");
        var ft = document.getElementById("footer");
        if (!ct || !ln || !pn || !hb || !cs || !ft) return;
       pn.style.display = "block";
       ct.style.marginLeft = "10em";
       hb.style.marginLeft = "10em";
       ft.style.marginLeft = "10em";
       ln.style.left = "10em";
       cs.firstChild.href = "javascript:collapseSideBar()"
    }

addOnloadHook(function(){
if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) return;
addPortletLink('p-cactions', 'javascript:collapseSideBar()', 'Toggle sidebar', 'ca-sidebar', 'Hide or show the sidebar', null, 'ca-purge');
});