User:Here/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.
/*******************************
 * 
 * See [[Wikipedia:WikiProject_User_scripts]] and [[m:Help:User_style]] 
 * for more info on User script customization.
 * 
 * Included, in order:
 * 1. Auto AFD script [[Wikipedia:WikiProject_User_scripts/Scripts/AutoAFD.js]]
 * 2. nav tabs at bottom of page
 *   requires css compliment (see [[m:User_Styles/bottom_tabs]] )
 * 3. Google search tool. [[User:Henrik/sandbox/google-search]]
 * 4. Recent revisions, [[nl:Gebruiker:JePe/recentrevisionsbox.js]]
 * 5. Twinkle + config; [[Wikipedia:WikiProject_User_scripts/Scripts/Twinkle]]
 * 
 * Removed, archived at [[User:Here/monobook.js/old]]
 * 1. godmode-light.js ( http://sam.zoy.org/wikipedia/ )
 *   godmode-light.js 21.06.2006 [[User:Olliminatore/godmode-light.js]]
 *   see aso, [[User:Sam Hocevar]]
 * 2. (broken/removed) Revert tools by Lorian [[Wikipedia:WikiProject_User_scripts/Scripts/Revert_tools]]
 
 
 **********************************/
//<nowiki>
//
// -----------------------------------------------------------------------------
// Auto AFD script
// [[Wikipedia:WikiProject_User_scripts/Scripts/AutoAFD.js]]
// adds tab to nominate page for deletion on AfD
// -----------------------------------------------------------------------------
//Please include the two following lines
//Modified version of AutoVFD script to work with AFD
//Script Modified by User:Jtkiefer
//Further modified to work with [[WP:AFDC]] by [[User:ais523]]
 
// This needs to change depending on skin used.
function add_link(url, name)
{
  var na = document.createElement('a');
  na.setAttribute('href', url);
  na.appendChild(document.createTextNode(name));
 
  var li = document.createElement('li');
  li.appendChild(na);
 
  var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
  tabs.appendChild(li);
}
 
function strip_namespace(target)
{
  var colon = target.indexOf(':');
  if (colon != -1)
    {
      var spaces = new Array('User', 'Wikipedia', 'Image', 'MediaWiki', 'Template', 'Help', 'Category');
      var ns = target.substring(0, colon);
      if (ns == '' || ns == 'Talk')
        return target.substring(colon + 1);
      else
        for (var i = 0; i < spaces.length; ++i)
          {
            if (ns == spaces[i]
                || ns == spaces[i] + '_talk')
              return target.substring(colon + 1);
          }
    }
 
  return target;
}
 
function afd()
{
  document.editform.wpTextbox1.value = '{{' + 'subst:afd}}\n' + document.editform.wpTextbox1.value;
  document.editform.wpSummary.value = 'afd';
 
  var target = document.editform.action;
  target = target.substring(target.indexOf('title=') + 6,
                            target.lastIndexOf('&action=submit'));
 
  var months = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
  var date = new Date();
  date = date.getUTCFullYear() + '_' + months[date.getUTCMonth()] + '_' + date.getUTCDate();
 
  var pagename = strip_namespace(target);
 
  window.open('/w/index.php?title=Wikipedia:Articles_for_deletion/' + pagename + '&action=edit&fakeaction=afdsub&faketarget=' + target,
              'Afd ' + unescape(target),
              'status,toolbar,location,menubar,directories,resizeable,scrollbars');
  window.open('/w/index.php?title=Wikipedia:Articles_for_deletion/Log/' + date + '&action=edit&fakeaction=afdlist&faketarget=' + pagename,
              'AfdLog ' + unescape(target),
              'status,toolbar,location,menubar,directories,resizeable,scrollbars');
}
 
function autoafd()
{
  if (document.title.indexOf('Editing ') == 0)
    {
      var action = '';
      var target = '';
      if (location.search)
        {
          var l = location.search.substring(1).split('&');
          for (var i = 0; i < l.length; ++i)
            {
              var eq = l[i].indexOf('=');
              var name = l[i].substring(0, eq);
              if (name == 'fakeaction')
                action = l[i].substring(eq + 1);
              else if (name == 'faketarget')
                target = unescape(l[i].substring(eq + 1)).replace(/_/g, ' ');
            }
        }
 
      if (action == 'afdlist')
        {
          document.editform.wpTextbox1.value += '{{' + 'Wikipedia:Articles for deletion/' + target + '}}\n';
          document.editform.wpSummary.value = '[[Wikipedia:Articles for deletion/' + target + ']]';
        }
      else if (action == 'afdsub')
        {
          if (document.editform.wpTextbox1.value.length > 0)
            {
              target = document.editform.action;
              target = unescape(target.substring(target.indexOf('title=') + 6, target.lastIndexOf('&action=submit'))).replace(/_/g, ' ');
              window.alert("There's an old afd at the default location already.\n\n" +
                           'Please either move it out of the way (and update existing links to it), or file the Afd by hand in another location (such as [[' + target + ' (2)]]).');
            }
          else
            document.editform.wpTextbox1.value += '===[[' + target + ']]===\n' +
              '{{REMOVE THIS TEMPLATE WHEN CLOSING THIS AfD|>>add cat here<<}}\n'+
              'Reason for nomination. ~~' + '~~\n*\n*\n*\n';
        }
      else
        add_link('javascript:afd()', 'Afd');
    }
}
 
addOnloadHook(autoafd);
 
//////////////////////////////////
/////////////////////////////////
// tabs at the bottom of the page
// requires css compliment (see [[m:User_Styles/bottom_tabs]] )
 
function morelinks() {
  var tabs = document.getElementById('p-cactions').cloneNode(true);
  tabs.id = 'mytabs';
  var listitems = tabs.getElementsByTagName('LI');
  for (i=0;i<listitems.length;i++) {
    if(listitems[i].id) listitems[i].id = 'mytabs-' + listitems[i].id;
  }
  document.getElementById('column-content').appendChild(tabs);
}
if (window.addEventListener) window.addEventListener("load",morelinks,false);
else if (window.attachEvent) window.attachEvent("onload",morelinks);
 
// END Nav Tabs at bottom of page
 
////////////////////////////////
//  Allow google search of en.wikipedia in search bar.
////////////////////////////////
 // [[User:Henrik/sandbox/google-search]] (please include this line)
 function install_search()
 {
 document.getElementById('searchBody').innerHTML+='<div>'+
 '<FORM method=get action="http://www.google.com/search">'+
 '<input type=hidden name="ie" value="UTF-8" /><input type=hidden name="oe" value="UTF-8" />'+
 '<INPUT id="searchInput" name="q" type="text" accesskey="f" value="" />'+
 '<input type="hidden" name="domains" value="en.wikipedia.org" />'+
 '<input type=radio name=sitesearch value="">Web'+
 '<input type=radio name=sitesearch value="en.wikipedia.org" checked />WP'+
 '<INPUT type="submit" name="btnG" VALUE="Google Search"  /></FORM></div>';
 }
 addOnloadHook(install_search);
 
// END Google search tool
 
// BEGIN Recent revisions
 
// (nl) Dit script leest de meest recente bewerkingen van een pagina
// uit de MediaWiki API en plaatst die in een box in de zijbalk
// boven de navigatie na het indrukken van een knop. In de box staan de
// gebruikersnamen met een link naar de betreffende paragraaf. 
// Voor de naam staat het tijdstip van de bewerking met een
// link die een diff met het verschil tussen de vorige bewerking
// boven de pagina plaatst. In de tooltip staat de bewerkingssamenvatting.
//
// (en) This script reads the most recent versions off a page
// from the MediaWiki API and places them in a box in the sidebar
// above the navigation after the press of a button. In the box are the
// usernames listed with a link to the corresponding paragraph.
// Before the name you can find the time of the edit with a
// link what places a diff with the differences with the previous version
// on top of the page. The tooltip contains the edit summary.
//
// Auteur/author: nl:User:JePe
 
 
function removeDiff()
{
   var diffFrame = document.getElementById("revisionsBoxDiff");
   if (diffFrame) diffFrame.parentNode.removeChild(diffFrame);
}
 
function makeCloseButton(position)
{
    var closeButton = document.createElement("img");  
    with (closeButton) {
       style.cssFloat = position; 
       style.styleFloat = position;
       style.verticalAlign = "auto";
       title = closeButtonTitle; 
       src = "http://upload.wikimedia.org/wikipedia/commons/thumb/8/8d/No-Symbol.svg/9px-No-Symbol.svg.png";    
       height = "9";                                                                                            
       width = "9"; }                                                                                          
    return closeButton;
}
 
function processDiff()
{
    if (diffReq.readyState != 4) return;
    if (diffReq.status != 200) return;
    var bodyContent = document.getElementById("bodyContent");                  
    var diffFrame = document.createElement("div");                              
    diffFrame.id = "revisionsBoxDiff";                                           
    diffFrame.innerHTML = diffReq.responseText;                                 
    diffTable = diffFrame.getElementsByTagName("table")[0];   
    if (!diffTable) return;
    if (diffTable.className != "diff") return;                  
    diffTable.style.border = "1px solid #ccc";                                  
    diffTable.style.width = "100%";                                             
    diffTable.style.paddingBottom = ".5em";                                     
    diffTable.style.marginBottom = "1em";                                       
    diffTable.style.marginTop = ".5em";                                         
    var closeButton = makeCloseButton("left"); 
    closeButton.onclick = removeDiff;
    var otitle = diffTable.getElementsByTagName("td");    
    for (i=0; i < otitle.length; i++) {
       if (otitle[i].className == "diff-otitle") {
          otitle[i].insertBefore(closeButton, otitle[i].firstChild); }
    }                                        
    var diffFrameOld = document.getElementById("revisionsBoxDiff");              
    if (diffFrameOld) diffFrameOld.parentNode.removeChild(diffFrameOld);        
    bodyContent.parentNode.insertBefore(diffFrame,bodyContent);                 
    window.location.hash = "revisionsBoxDiff";
    var prevLink = document.getElementById("differences-prevlink");  
    if (prevLink) {      
       var oldid = prevLink.href.replace(/[\s\S]+&oldid=(\d+)[\s\S]*/,"$1");    
       prevLink.href = "javascript:loadDiff("+oldid+",'prev')"; }                                                      
    var nextLink = document.getElementById("differences-nextlink");  
    if (nextLink) {           
       var oldid = nextLink.href.replace(/[\s\S]+&oldid=(\d+)[\s\S]*/,"$1");   
       nextLink.href = "javascript:loadDiff("+oldid+",'next')"; }                                                   
}    
 
function loadDiff(oldid,diffDir)
{
    var url = "/w/index.php?title=" + wgPageName;
    url += "&diff=" + diffDir;
    url += "&oldid=" + oldid;
    url += "&diffonly=1&action=render";
    if (window.XMLHttpRequest) { // native XMLHttpRequest
        diffReq = new XMLHttpRequest();
        diffReq.onreadystatechange = processDiff;
        diffReq.open("GET", url, true);
        diffReq.send(null);
    } else if (window.ActiveXObject) { // activeX version
        diffReq = new ActiveXObject("Microsoft.XMLHTTP");
        if (diffReq) {
            diffReq.onreadystatechange = processDiff;
            diffReq.open("GET", url, true);
            diffReq.send("");
        }
    }
}
 
function nextRevisions()
{
   var revContent = document.getElementById("recRevContent");
   var divNode = revContent.appendChild(document.createElement("div"));
   divNode.id = "nextButton";
   divNode.style.textAlign = "center";   
   var button = divNode.appendChild(document.createElement("button"));
   button.innerHTML = buttonNextText;
   button.title = buttonNextTitle;
   button.onclick = loadXMLDoc;            
   button.style.fontSize = "90%";
   button.style.marginTop = ".3em";
   button.style.padding = "0";
} 
 
function writeResults(rev)
{
   var showButton = document.getElementById('showButton');
   var nextButton = document.getElementById('nextButton');
   var revContent = document.getElementById("recRevContent");
   if (showButton) { 
      showButton.parentNode.removeChild(showButton);
      var closeButton = makeCloseButton("right");
      closeButton.onclick = recentRevisions;
      closeButton.style.marginTop = ".3em"; 
      revContent.appendChild(closeButton); }
   if (nextButton) nextButton.parentNode.removeChild(nextButton);   
   var date = new Date();
   var dateNow = (date.getFullYear()*10000) + ((date.getMonth()+1)*100) + date.getDate();
   for (i = 0; i < rev.length; i++) { 
      var time = rev[i].getAttribute("timestamp");
      var year = time.replace(/^(\d\d\d\d)[\s\S]+/,"$1");
      var month = time.replace(/^\d\d\d\d-(\d\d)[\s\S]+/,"$1");
      var day = time.replace(/^\d\d\d\d-\d\d-(\d\d)[\s\S]+/,"$1");
      var hours = time.replace(/[\s\S]+T(\d\d)[\s\S]+/,"$1");
      var minutes = time.replace(/[\s\S]+T\d\d:(\d\d)[\s\S]+/,"$1");
      date.setUTCFullYear(year,month-1,day);
      date.setUTCHours(hours,minutes);
      var dateRevision = (date.getFullYear()*10000) + ((date.getMonth()+1)*100) + date.getDate();
      if (dateRevision < dateControl) {
         var divNodeDate = revContent.appendChild(document.createElement("div"));
         divNodeDate.style.fontSize = "95%";
         divNodeDate.style.marginTop = ".3em";
         divNodeDate.style.fontWeight = "bold";
         divNodeDate.style.paddingLeft = ".5em";
         divNodeDate.innerHTML = date.getDate() + " " + monthName[date.getMonth()]; 
         if (dateNow - dateRevision > 10000) divNodeDate.innerHTML += " " + date.getFullYear();
         dateControl = dateRevision;   
      }   
      var divNode = revContent.appendChild(document.createElement("div"));
      divNode.style.marginLeft = "1em";
      divNode.style.textIndent = "-1em";
      divNode.style.fontSize = "95%";
      divNode.style.marginTop = ".3em";
      var aNodeTime = divNode.appendChild(document.createElement("a"));
      aNodeTime.innerHTML = (date.getHours() < 10) ? "0" + date.getHours() : date.getHours();
      aNodeTime.innerHTML += ":";
      aNodeTime.innerHTML += (date.getMinutes() < 10) ? "0" + date.getMinutes() : date.getMinutes();
      aNodeTime.style.fontSize = "90%";
      var revid = rev[i].getAttribute("revid");
      aNodeTime.href = "javascript:loadDiff("+revid+",'prev')";
      aNodeTime.title = timeTitle;
      divNode.appendChild(document.createTextNode(" "));
      var aNodeUser = divNode.appendChild(document.createElement("a"));
      aNodeUser.innerHTML = rev[i].getAttribute("user");
      var anchorURL = rev[i].getAttribute("comment");
      if (anchorURL == null) anchorURL = "";
      aNodeUser.title = anchorURL; 
      // convert comment into a usable anchor link
      if (anchorURL.search(/\/\*\s([\s\S]+)\s\*\/[\s\S]*/) != -1) {
         var reg = [ [/\/\*\s([\s\S]+)\s\*\/[\s\S]*/,"$1"], [/\[\[[\s\S]*\|([\s\S]+)\]\]/g,"$1"],
                   [/\[\[\:?([\s\S]+)\]\]/g,"$1"], [/\s/g,"_"] ];
         for (x = 0; x < reg.length; x++) {
            anchorURL = anchorURL.replace(reg[x][0],reg[x][1]); }
         anchorURL = encodeURIComponent(anchorURL); 
         var reg = [ [/%/g,"."], [/\(/g,".28"], [/\)/g,".29"], [/\!/g,".21"], 
                   [/\'/g,".27"], [/\*/g,".2A"], [/.3A/g,":"] ];
         for (x = 0; x < reg.length; x++) {
            anchorURL = anchorURL.replace(reg[x][0],reg[x][1]); }
      } else {
         anchorURL = ""; }   
      aNodeUser.href = document.location.href + "#" + anchorURL;
      aNodeUser.href = aNodeUser.href.replace(/##/,"#");
   } 
}
 
function processReq()
{
    if (apiReq.readyState != 4) return;
    if (apiReq.status != 200) return;                              
    var xmlFile = apiReq.responseXML.documentElement;
    var rev = xmlFile.getElementsByTagName("rev");  
    if (rev.length > 0) writeResults(rev);  
    queryContinue = xmlFile.getElementsByTagName("query-continue")[0];
    if (queryContinue) {
       rvStartId = queryContinue.getElementsByTagName("revisions")[0].getAttribute("rvstartid");
       nextRevisions();
    }   
}    
 
function loadXMLDoc()
{
    var url = "/w/api.php?action=query&prop=revisions&format=xml";             
    url += "&titles=" + wgPageName + "&rvprop=timestamp|user|comment";      
    url += "&rvlimit=" + revCount;                           
    if (rvStartId != 0) url += "&rvstartid=" + rvStartId; 
    if (window.XMLHttpRequest) { // native XMLHttpRequest 
        apiReq = new XMLHttpRequest();
        apiReq.onreadystatechange = processReq;
        apiReq.open("GET", url, true);
        apiReq.send(null);
    } else if (window.ActiveXObject) { // activeX version
        apiReq = new ActiveXObject("Microsoft.XMLHTTP");
        if (apiReq) {
            apiReq.onreadystatechange = processReq;
            apiReq.open("GET", url, true);
            apiReq.send("");
        }
    }
}
 
function recentRevisions()
{
   var revContent = document.getElementById("recRevContent");
   if (revContent) { // when pressed the close button
      revContent.innerHTML = "";
      rvStartId = 0;
      dateControl = 99999999;
   } else {   
      var navigationBox = document.getElementById('p-navigation');                                      
      var revBox = document.createElement("div");                                                
      var revBox = navigationBox.parentNode.insertBefore(document.createElement("div"),navigationBox); 
      revBox.id = "p-rev";                                                                       
      revBox.className = "portlet";                                                              
      var h5Node = revBox.appendChild(document.createElement("h5"));                             
      h5Node.innerHTML = revBoxTitle;                                                            
      revContent = revBox.appendChild(document.createElement("div"));                           
      revContent.id = "recRevContent";                                                              
      revContent.className = "pBody";                                                               
      revContent.style.padding = "0 .3em .3em .3em";                                                
      revContent.style.lineHeight = "1.2em";                                                        
      revContent.style.fontFamily = "Verdana, sans-serif"; 
   }                                            
   var divNode = revContent.appendChild(document.createElement("div"));
   divNode.id = "showButton";
   divNode.style.textAlign = "center";   
   var button = divNode.appendChild(document.createElement("button"));
   button.innerHTML = buttonBeginText;
   button.onclick = loadXMLDoc;            
   button.style.fontSize = "90%";
   button.style.marginTop = ".3em";
   button.style.padding = "0";
}
 
var diffReq;
var apiReq;
var rvStartId = 0;
var revCount = 20; // max 50, higher numbers not possible, they give an error
var dateControl = 99999999; // must only be higher than today (yyyymmdd)
if (wgUserLanguage == "nl") {
   var timeTitle = "Verschillen met de vorige bewerking";
   var closeButtonTitle = "Sluiten";
   var revBoxTitle = "recente bewerkingen"; 
   var buttonBeginText = "Toon bewerkingen";
   var buttonNextText = "Volgende " + revCount;
   var buttonNextTitle = "Toon de volgende "+revCount+" bewerkingen";
   var monthName = ["januari", "februari", "maart", "april", "mei", "juni", "juli",
                    "augustus", "september", "oktober", "november", "december"];
} else {
   var timeTitle = "Differences with the previous revision";
   var closeButtonTitle = "Close";
   var revBoxTitle = "recent revisions"; 
   var buttonBeginText = "Show revisions";
   var buttonNextText = "Next " + revCount;
   var buttonNextTitle = "Show the next "+revCount+" revisions";
   var monthName = ["January", "February", "March", "April", "May", "June", "July",
                    "August", "September", "October", "November", "December"];
}  
document.write('<style type="text/css">/*<![CDATA[*/ table.diff td {vertical-align:top;} /*]]>*/</style>');
if (wgNamespaceNumber != -1)
   addOnloadHook(recentRevisions);
 
// END  Recent revisions
 
////////////////////
// Twinkle 
////////////////////
 
importScript('User:AzaToth/twinkle.js');
 
TwinkleConfig = {
        revertMaxRevisions              :       50,
        userTalkPageMode                :       'tab',
        showSharedIPNotice              :       true,
        openTalkPage                    :       [ ],
        openTalkPageOnAutoRevert        :       false,
        openAOLAnonTalkPage             :       false,
        summaryAd                       :       " (using [[WP:TWINKLE|tw]])",
        deletionSummaryAd               :       " (using [[WP:TWINKLE|tw]])",
        protectionSummaryAd             :       " (using [[WP:TWINKLE|tw]])",
        watchSpeedyPages                :       [ 'g3', 'g5', 'g10', 'g11', 'g12' ],
        watchProdPages                  :       true,
        openUserTalkPageOnSpeedyDelete  :       [ 'g1', 'g2', 'g10', 'g11', 'g12', 'a1', 'a7', 'i3', 'i4', 'i5', 'i6', 'i7', 'u3', 't1' ],
        watchRevertedPages              :       [ 'agf', 'norm', 'vand', 'torev' ],
        markRevertedPagesAsMinor        :       [ 'agf', 'norm', 'vand', 'torev' ],
        deleteTalkPageOnDelete          :       false,
        markWarningsAsMinor             :       false,
        markAIVReportAsMinor            :       false,
        markSpeedyPagesAsMinor          :       false,
        markProdPagesAsMinor            :       false,
        confirmUsernameToAIV            :       true,
        toolboxButtons                  :       [ ]
};
 
// END Twinkle
///////////////////////////
 
//</nowiki>