User:Srikeit/monobook.js

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
//<pre>

/**** Define shortcut function for adding scripts ****/

function winc(s)
{
    s = s.replace(/^\[\[/, '').replace(/\]\]$/, '');
    document.write('<script type="text/javascript" src="http://commons.wikimedia.org/w/index.php?title=' + s
    + '&action=raw&ctype=text/javascript&dontcountme=s"><\/script>');
}

/**** Include common functions ****/

winc("[[User:Alphax/common-functions.js]]");

/**** Add local copy of extra tabs ****/

winc("[[User:Alphax/extra-tabs.js]]");

/**** Move tabs into their own drop-down menu ****/

winc("[[User:Alphax/move-tabs.js]]");

/**** Add navigation popups ****/

// [[User:Lupin/popups.js]] - please include this line 

document.write('<script type="text/javascript" src="http://en.wikipedia.org/w/index.php?title=User:Lupin/popups.js&action=raw&ctype=text/javascript&dontcountme=s"><\/script>');

// customisations = see [[wikipedia:Wikipedia:Tools/Navigation popups]] for more

popupStructure = 'menus';
popupAdminLinks = true;

/**** Add "toggle" button to undelete pages - from [[w:User:Cryptic/toggleundelete.js]] ****/

function toggle_undelete()
{
  var f = document.getElementById("undelete");
  if (f)
    {
      var inputs = f.getElementsByTagName("input");
      var i;
      for (i = 0; i < inputs.length; ++i)
        if (inputs[i].type == "checkbox")
          inputs[i].checked = !inputs[i].checked;
    }
}

function setup_toggle_undelete()
{
    if(wgPageName == "Special:Undelete")
    {
        var f = document.getElementById("undelete");
        if (!f) return null;
        var tr = f.getElementsByTagName("tr")[2];
        if (!tr) return null;
        var td = tr.getElementsByTagName("td")[1];
        if (!td) return null;          
        var button = document.createElement('input');
        button.type = "button";
        button.value = "Invert";
        button.setAttribute('onClick', 'toggle_undelete()');
        td.appendChild(button);
    }
}

/**** Quick-delete - see [[MediaWiki talk:Quick-delete.js]] ****/

// winc("[[MediaWiki:Quick-delete.js]]");

// Custom development version

winc("[[User:Alphax/qd-merged.js]]");

$( myLoadFuncs );

function myLoadFuncs()
{
    // &action=purge
    addPurge();
    
    // &section=0
    addEditSection0();
    
    // cause the personal menu looks bad
    changeLinks();
    
    // and some stuff for the sidebar
    addToolBoxLinks();
    
    // add other stuff
    morelinks();
    
    // add thing to toggle undelete
    setup_toggle_undelete();
    
    // change the title of the edit link
    ta['ca-edit'] = ['e', 'Edit page'];
    
    // remove the logout button
    document.getElementById("pt-logout").parentNode.removeChild(document.getElementById("pt-logout"));
    
    // re-render the title and accesskeys for stuff
    akeytt();
}

/**** Add purge tab ****/

function addPurge()
{
    ta['ca-purge'] = ['g', 'Purge the internal cache for this page'];
    if(!document.getElementById) return;
    var x = document.getElementById('ca-history');
    if(!x) { return; } // if it doesn't have a history tab, it's not purgable
    var tabs = x.parentNode;
    if(x.children) { x = x.children[0]; }
    else { x = x.childNodes[0]; }
    addlilink(tabs, x.href.replace(/=history/, "=purge"), 'purge', 'ca-purge');
}

/**** Add generic tab - now in common-functions.js ****/

/*
function addlilink(tabs, url, name, id)
{
    var na = document.createElement('a');
    na.href = url;
    na.appendChild(document.createTextNode(name));
    var li = document.createElement('li');
    li.id = id;
    li.appendChild(na);
    tabs.appendChild(li);
    return li;
}
*/

/**** Edit section 0 ****/

function addEditSection0()
{
    ta['ca-edit-0'] = ['', 'Edit the zeroth section of this page'];
    if(!document.getElementById) return;
    var x = document.getElementById('ca-edit');
    if(!x) return;
    var y = document.createElement('LI');
    y.id = 'ca-edit-0';
    if(x.className == 'selected'){
      if(/&action=edit&section=0$/.test(window.location.href)){
        x.className = 'istalk';
        y.className = 'selected';
      } else {
        x.className = 'selected istalk';
      }
    } else if(x.className == 'selected istalk'){
      if(/&action=edit&section=0$/.test(window.location.href)){
        x.className = 'istalk';
        y.className = 'selected istalk';
      } else {
        y.className = 'istalk';
      }
    } else {
      y.className = x.className;
      x.className = 'istalk';
    }
    var z = document.createElement('A');
    if(x.children){
        z.href = x.children[0].href + '&section=0';
        z.appendChild(document.createTextNode('0'));
        y.appendChild(z);
        document.getElementById('p-cactions').children[1].insertBefore(y,x.nextSibling);
    }else{
        z.href = x.childNodes[0].href + '&section=0';
        z.appendChild(document.createTextNode('0'));
        y.appendChild(z);
        document.getElementById('p-cactions').childNodes[3].insertBefore(y,x.nextSibling);
    }
}

/**** Make the top links look better ****/

function changeLinks()
{
    if(!document.getElementById) return;
    // remove the "my" bits
    document.getElementById('pt-mytalk').firstChild.innerHTML = 'talk';
    document.getElementById('pt-preferences').firstChild.innerHTML = 'preferences';
    document.getElementById('pt-watchlist').firstChild.innerHTML = 'watchlist';
    document.getElementById('pt-mycontris').firstChild.innerHTML = 'contributions';
    // add a clock
    var toplinks = document.getElementById('p-personal').getElementsByTagName('ul')[0];
    addlilink(toplinks, '#', '', 'utcdate');
    showtime();
}

/**** Get a clock that autoupdates! ****/

function showtime()
{
    var timerID;
    var now = new Date();
    var timeValue = now.toUTCString().replace(/GMT/, "UTC");
    document.getElementById('utcdate').firstChild.innerHTML = timeValue;
    timerID = setTimeout('showtime()', 100);
}

/**** Add links to the toolbox ****/

function addToolBoxLinks()
{
    var tb = document.getElementById('p-tb').getElementsByTagName('ul')[0];
    addlilink(tb, '/wiki/Special:Log', 'Logs', '');
}

/** add other stuff **/

function morelinks()
{
    var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
    if(document.title.indexOf("Editing Commons:Deletion requests") == 0)
    {
        addlilink(tabs, 'javascript:closedel(prompt("Result?"))', 'close deletion request', '');
    }
}

// <nowiki>
function closedel(result)
{
    var txt = document.editform.wpTextbox1;
    txt.value = "{{subst:delh}}\n" + txt.value
    + "\n----\n" + result + " &ndash; ~~~~\n{{subst:delf}}\n";
    txt = document.editform.wpSummary;
    txt.value = "close discussion";
}
// </nowiki>

// Autolink [[wikilinks]] and {{templates}} (especially useful for monobook.js and similar pages)
// From [[wikipedia:Wikipedia:WikiProject User scripts/Scripts/Autolink]], by [[w:User:Omegatron]]

$(function () {
    // Get the HTML of just the main body of the page, not including textareas hopefully
    if (document.title.indexOf("Editing ") != 0 && document.title.indexOf("Template:") != 0) {
        targetdiv = document.getElementById('bodyContent');  // bodyContent div for most pages
    } else 
    if (document.getElementById('wikiPreview')) {
        targetdiv = document.getElementById('wikiPreview');  // wikiPreview if it's there
    } else
    if (document.getElementById('wikiDiff')) {
        targetdiv = document.getElementById('wikiDiff');   // wikiDiff if it's there
    } else {
        return;
    }
    content = targetdiv.innerHTML;
    content = content.replace(/([^\[])\[{2}([^\[\]\|\<\>\n]*)([^\[\]\<\>\n]*?)?\]{2}([^\]])/g, '$1<a class="autolink" href="/wiki/$2">[[$2$3]]</a>$4'); // Make wikilink code into links
    content = content.replace(/([^\{])\{{2}(subst\:|msg\:)?([^\{\}\|\<\>\n]*)([^\{\}\<\>\n]*?)?\}{2}([^\}])/g, '$1<a class="autolink" href="/wiki/Template:$3">{{$2$3$4}}</a>$5'); // Make template code into links
    targetdiv.innerHTML = content; // Write it back
});

//</pre>