User:Happy-melon/monobook.js

From Wikipedia, the free encyclopedia

If a message on your talk page led you here, please be wary of who left it. The code below could contain malicious content capable of compromising your account; if your account appears to be compromised, it will be blocked. If you are unsure whether the code is safe, you can ask at the appropriate village pump.
Note: After saving, you have to bypass your browser's cache to see the changes. In Internet Explorer and Firefox, hold down the Ctrl key and click the Refresh or Reload button. Opera users have to clear their caches through Tools→Preferences, see the instructions for Opera. Konqueror and Safari users can just click the Reload button.
// Originally based on http://en.wikipedia.org/w/index.php?title=User:JesseW/monobook.js&oldid=20755510  
// See [[Wikipedia:WikiProject User scripts/Scripts/Show last diff]]
// addLastDiff
function addLastDiff()
{
    if (wgCanonicalNamespace != "Special") {
        addPortletLink('p-cactions', 'http://en.wikipedia.org/w/index.php?title=' + wgPageName + "&diff=cur&oldid=prev", 'last', 'ca-last', 'Show most recent diff');
}}
addOnloadHook(addLastDiff);
 
 
// Gives assessment data for an article
// Just like [[User:Outriggr/metadata.js]], but this one has [[User:Pyrospirit|a newbie]] hacking around with it.
//if (wgNamespaceNumber==0 && wgAction=='view')
//importScript('User:Pyrospirit/metadata.js');
 
// Adds a tab for "changes since I last edited"
//importScript('User:Happy-melon/since.js');
importScript('Wikipedia:WikiProject User scripts/Scripts/Changes since I last edited');
 
//Toolbox links
 
if (wgNamespaceNumber >= 0){
addOnloadHook(function(){
 addPortletLink('p-tb', wgServer+wgScript+'?title=Special:Log&page='+wgPageName,
 'Page logs', 't-pagelog', 'View logs for this page', '', document.getElementById('t-upload'))
})}
 
if (wgNamespaceNumber == 2){
addOnloadHook(function(){
 addPortletLink('p-tb', wgServer+wgScript+'?title=Special:Listusers&limit=1&username='+wgTitle.split('/')[0],
 'User rights', 't-userrights', 'View rights for this user', '', document.getElementById('t-upload'))
})}
 
if (wgNamespaceNumber > 1){
addOnloadHook(function(){
 addPortletLink('p-tb', wgServer+wgScript+'?title=Special:Prefixindex/'+wgPageName+'&limit=100',
 'Subpages', 't-prefix', 'View subpages of this page', '', document.getElementById('t-upload'))
})}
 
//Collapse FAQ on [[Wikipedia:Village pump (technical)]]
 
function HideVPFAQ(){
    var t=document.getElementById('villagepumpfaq');
    if(!t) return;
    t=t.getElementsByTagName('TABLE');
    if(!t || t.length==0 || t[0].id.substr(0,16)!='collapsibleTable') return;
    collapseTable(t[0].id.substr(16));
}
if(doneOnloadHook) HideVPFAQ(); //if imported dynamically
else addOnloadHook(HideVPFAQ);
 
//Move search bar up
 
addOnloadHook(function() {
    document.getElementById("column-one").insertBefore(document.getElementById("p-search"), document.getElementById("p-interaction"))
})
 
//Swap editbox and diff in undo mode
 
if(queryString('undo') && queryString('undoafter')) addOnloadHook(undoStyle)
function undoStyle() {
  //yes, icky, should work in IE7 though.
  var t = document.getElementById('toolbar');
  var e = document.getElementById('editform')
  var w = document.getElementById('wikiPreview');
  var tb = t.innerHTML
  var tb = '<div id="toolbar">' + tb + '</div>';
  var ef = e.innerHTML
  var efw = e.parentNode.innerHTML.match(/\<form[^>]*\>/ig)[0];
  ef = efw + ef + '</form>';
  w.innerHTML += tb + ef;
  t.innerHTML = ''; t.id = '';
  e.innerHTML = ''; e.id = ''; e.action = '';
}
 
function queryString(p) {
  var re = RegExp('[&?]' + p + '=([^&]*)');
  var matches;
  if (matches = re.exec(document.location)) {
    try { 
      return decodeURI(matches[1]);
    } catch (e) {
    }
  }
  return null;
}