Jump to content

User:Edgar181/monobook.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.
//<nowiki>
 function tnaddlilink(url, name)
 {
  var na = document.createElement('a');
  na.setAttribute('href', url);

  var txt = document.createTextNode(name);
  na.appendChild(txt);

  var li = document.createElement('li');
  li.appendChild(na);
  return li;
 }
  
 function edits(number)
 {
  var page = prompt("Edits to which article?")
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
    t.value += '\n';
  t.value += "\n{{subst:uw-" + number + "|" + page + "}} ~" + "~" + "~" + "~";
  f.wpSummary.value = "Edits to [[" + page + "]] - first warning " ;
  f.submit();
 }
 
 function vandalism(number)
 {
  var page = prompt("Vandalism to which article?")
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
    t.value += '\n';
  t.value += "----\n{{subst:uw-" + number + "|" + page + "}} ~" + "~" + "~" + "~";
  f.wpSummary.value = "Vandalism to [[" + page + "]] - {{uw-" + number + "}}";
  f.submit();
 }

 function attack(number)
 {
  var page = prompt("Attack at which article?")
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
    t.value += '\n';
  t.value += "----\n{{subst:attack" + "|" + page + "}} ~" + "~" + "~" + "~";
  f.wpSummary.value = "Attack page creation";
  f.submit();
 }
 
 function tempblocked(number)
 {
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
    t.value += '\n';
  t.value += "\n{{subst:uw-block" + "|sig=yes}}" ;
  f.wpSummary.value = "Blocked from editing: {{uw-block" + "}}" ;
  f.submit();
 }

 function indefblocked(number)
 {
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
    t.value += '\n';
  t.value += "\n{{subst:uw-blockindef" + "|sig=yes}}" ;
  f.wpSummary.value = "Blocked from editing: {{uw-blockindef" + "}}" ;
  f.submit();
 }

 function username(number)
 {
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
    t.value += '\n';
  t.value += "\n{{subst:uw-ublock" + "|sig=yes}}" ;
  f.wpSummary.value = "Username block" ;
  f.submit();
 }


 function usernames(number)
 {
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
    t.value += '\n';
  t.value += "\n{{subst:uw-softerblock" + "|sig=yes}}" ;
  f.wpSummary.value = "Username block" ;
  f.submit();
 }


 function add_testn_tabs()
 {
  var c1 = document.getElementById('column-one');
  var tabs = c1.getElementsByTagName('div')[0].getElementsByTagName('ul')[0];

  // Only add for pages with "Editing User"/"Creating User" somewhere in the title
  if (document.title.indexOf("ting User") != -1)
    {
      tabs.appendChild(tnaddlilink('javascript:edits("vandalism1")',"v1"));
      tabs.appendChild(tnaddlilink('javascript:vandalism("vandalism2")',"v2"));
      tabs.appendChild(tnaddlilink('javascript:vandalism("vandalism3")',"v3"));
      tabs.appendChild(tnaddlilink('javascript:vandalism("vandalism4")',"v4"));
      tabs.appendChild(tnaddlilink('javascript:tempblocked("tempblocked1")',"blk"));
      tabs.appendChild(tnaddlilink('javascript:indefblocked("indefblocked1")',"ndf"));
      tabs.appendChild(tnaddlilink('javascript:username("usernameblock")',"unb"));
      tabs.appendChild(tnaddlilink('javascript:usernames("usernameblock")',"unbs"));
      tabs.appendChild(tnaddlilink('javascript:edits("delete1")',"d1"));
      tabs.appendChild(tnaddlilink('javascript:vandalism("delete2")',"d2"));
      tabs.appendChild(tnaddlilink('javascript:vandalism("delete3")',"d3"));
      tabs.appendChild(tnaddlilink('javascript:edits("spam1")',"s1"));
      tabs.appendChild(tnaddlilink('javascript:vandalism("spam2")',"s2"));
      tabs.appendChild(tnaddlilink('javascript:vandalism("spam3")',"s3"));
      tabs.appendChild(tnaddlilink('javascript:attack("attack1")',"a"));
 }}
$(add_testn_tabs);







// Please leave the following line
// [[user:Where/usertabs]]
 
$(function() {
  if (wgTitle.indexOf("/") != -1 || document.title.indexOf("- History -") != -1)  //no subpages or history
     return;
  if (wgCanonicalNamespace == "User" || wgCanonicalNamespace == "User_talk") {
     var username = encodeURIComponent( wgTitle );
     mw.util.addPortletLink("p-cactions", wgServer + "/wiki/Special:Contributions/" + username, "Cntr", "ca-contrib", "User contributions");
     mw.util.addPortletLink("p-cactions", "http://en.wikipedia.org/wiki/Special:Blockip/" + username, "Blk", "ca-block", "Block this user");
     mw.util.addPortletLink("p-cactions", wgServer + "/w/index.php?title=Special:Log&type=block&page=User:" + username, "Blks", "ca-blog", "Block log");
     mw.util.addPortletLink("p-cactions", "http://tools.wikimedia.de/~interiot/cgi-bin/count_edits?dbname=enwiki_p&user=" + username, "Edits", "ca-editcount", "Edit count from Interiot's toolserver script");
  }
});






// originally from User:Lupin/popups.js

importScript('User:Edgar181/popups.js');


window.popupStructure='original';
window.popupFixRedirs=true;
window.popupFixDabs=true;
window.popupAdminLinks=true;
window.popupDelay=.5;
window.popupHideDelay=.01;
window.popupWatchRedirredPages=false;
window.popupRedirAutoClick='wpSave'




// DOI bot

importScript('User:Smith609/toolbox.js');



//Adds 'Check Refs' to the toolbox, links to http://toolserver.org/~dispenser/cgi-bin/reflinks.py -- Dispenser's reference title fixer.

function refcheck()
{
  mw.util.addPortletLink("p-tb", "http://toolserver.org/~dispenser/cgi-bin/reflinks.py?citeweb=on&page=" + wgPageName, "Check Refs");
}

if ( wgNamespaceNumber == 0 ) {
 addOnloadHook(refcheck);
}



importScript('User:Smith609/reftool.js');



importScript('User:John254/mass rollback.js')


var cwwpajax;
// From [[WP:US]] mainpage (wpajax renamed to cwwpajax)
cwwpajax={
        download:function(bundle) {
                // mandatory: bundle.url
                // mandatory: bundle.async
                // optional:  bundle.onSuccess (xmlhttprequest, bundle)
                // optional:  bundle.onFailure (xmlhttprequest, bundle)
                // optional:  bundle.otherStuff OK too, passed to onSuccess and onFailure
                
                var x = window.XMLHttpRequest ? new XMLHttpRequest() // Firefox, Safari, Opera, IE7
                : window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") // IE6
                : false;
                
                if (x) {
                        x.onreadystatechange=function() {
                                x.readyState==4 && cwwpajax.downloadComplete(x,bundle);
                        };
                        x.open("GET",bundle.url,bundle.async);
                        x.send(null); 
                }
                return x;
        },

        downloadComplete:function(x,bundle) {
                x.status==200 && ( bundle.onSuccess && bundle.onSuccess(x,bundle) || true )
                || ( bundle.onFailure && bundle.onFailure(x,bundle) || alert(x.statusText));
        }
};

// Example:
// function dlComplete(xmlreq, data) {
//      alert(data.message + xmlreq.responseText);
// }
//  cwwpajax.download({url:'http://en.wikipedia.org/w/index.php?title=Thresher&action=raw', 
//                   onSuccess: dlComplete, message: "Here's what we got:\n\n" });

// End of [[WP:US]] quote

function cwOntoWatchlist(xmlreq, data)
{
  var a=xmlreq.responseText;
  var c=data.catname;
  var i;
  var diag="";
  if(a.indexOf("<categorymembers/>")!=-1) return; //cat is empty, nothing to do here
  if(a.indexOf('title="')==-1) return; // this error happens sometimes, just do nothing here
  var latesttime=0;
  var latestpage="";
  var temp, temp2;
  latestpage=a.split('title="')[1].split('" timestamp=')[0];
  latesttime=a.split('timestamp="')[1].split('"/>')[0];
  a=document.getElementsByTagName("h4"); //get dates in the watchlist
  var monthname=[];
  monthname['01']="January";
  monthname['02']="February";
  monthname['03']="March";
  monthname['04']="April";
  monthname['05']="May";
  monthname['06']="June";
  monthname['07']="July";
  monthname['08']="August";
  monthname['09']="September";
  monthname['10']="October";
  monthname['11']="November";
  monthname['12']="December";
  latesttime=new String(latesttime);
  
  var mn1, mn2, mn3, mn4;
  
  // Allow for different date styles:
  // January 29, 2001
  mn1=""+monthname[latesttime.substr(5,2)]+" "+new Number(latesttime.substr(8,2))+
      ", "+latesttime.substr(0,4);
  // 29 January 2001
  mn2=""+new Number(latesttime.substr(8,2))+" "+monthname[latesttime.substr(5,2)]+
      " "+latesttime.substr(0,4);
  // 2001 January 29
  mn3=""+latesttime.substr(0,4)+" "+monthname[latesttime.substr(5,2)]+
      " "+new Number(latesttime.substr(8,2));
  // 2001-01-29
  mn4=""+latesttime.substr(0,4)+"-"+latesttime.substr(5,2)+"-"+latesttime.substr(8,2);

  i=a.length;
  while(i--)
  {
    if(a[i].innerHTML==mn1||a[i].innerHTML==mn2||a[i].innerHTML==mn3||a[i].innerHTML==mn4)
    {
      diag+=a[i].innerHTML+":";
      temp=a[i].nextSibling.firstChild;
      if(temp==null) temp=a[i].nextSibling.nextSibling.firstChild;
      while(temp!=null)
      {
        diag+=temp.tagname+"!";
        if(temp.tagName!=null)
        if(temp.tagName.toLowerCase()=="li")
        {
          temp2=temp.innerHTML.match(/<span class="mw-changeslist-date">([0-9][0-9]):([0-9][0-9])(:[0-9][0-9])?<\/span>/i);
          temp2=new Number(temp2[1])*100+new Number(temp2[2]);
          diag+=temp2+",";
          if(temp2<new Number(latesttime.substr(11,2)+latesttime.substr(14,2))) {temp2=temp; break;}
        }
        temp2=temp; temp=temp.nextSibling;
        if(temp==null) break;
      }
      temp=document.createElement("li");
      if(temp2==null) {return;}
      if(a[i].nextSibling.firstChild!==null) // IE-like whitespace handling
        a[i].nextSibling.insertBefore(temp,temp2);
      else // Firefox-like whitespace handling
        a[i].nextSibling.nextSibling.insertBefore(temp,temp2);

      temp.innerHTML="(diff | hist) . . <a "+
                     "href='"+mw.config.get('wgScriptPath')+"/index.php?title=Category:"+
                     encodeURI(c)+
                     "'>Category:"+c+"</a>; "+latesttime.substr(11,2)+":"+latesttime.substr(14,2)+
                     " . . (+ <a "+
                     "href='"+mw.config.get('wgScriptPath')+'/index.php?title='+
                     encodeURI(latestpage)+"'>"+latestpage+"</a> "+
                     "(<a href='"+mw.config.get('wgScriptPath')+"/index.php?title="+encodeURI(latestpage)+
                     "&diff=last'>last</a>))";
      return;
    }
  }
}

var WatchedCategories;

//An example of a query to check a category would be

//http://en.wikipedia.org/w/api.php?action=query&list=categorymembers&cmcategory=Wikipedia%20protected%20edit%20requests&cmlimit=1&cmprop=title|timestamp&cmsort=timestamp&cmdir=desc&format=xml
$(function(){
  var scriptPath = mw.config.get('wgScriptPath');
  //DHTMLloadscript( 'http://en.wikipedia.org/w/index.php?title=User:'+wgUserName
  //  +'/WatchedCategories.js&action=raw&ctype=text/javascript');
  if(mw.config.get('wgPageName')=="Special:Watchlist")
  {
    // load the script using AJAX, because DHTML fails in Firefox and document.write fails in Safari
    var sru=scriptPath+'/index.php?title=User:'+mw.config.get('wgUserName')+'/WatchedCategories.js&action=raw&ctype=text/javascript';
    var sr=cwwpajax.download({url:sru,async:false});
    eval(sr.responseText);
    if(WatchedCategories===undefined)
    {
      if(confirm("You don't have a category watchlist yet. Do you want to create one?\n\n"+
                 "(Please provide the following debug information when reporting a problem if "+
                 "this message comes up when you already have a category watchlist: "+
                 (sr.responseText.length<50 ? "responseText='"+sr.responseText+"'" :
                 "responseText.length="+sr.responseText.length)+", statusText='"+sr.statusText
                 +"'.)"))
        location.href=scriptPath+'/index.php?title=User:'+wgUserName+
        '/WatchedCategories.js&action=edit&preload=User:Ais523/WatchedCategoriesTemplate.js';
    }
    else
    {
      var i;
      for(i=0; i<WatchedCategories.length; i++)
      {
        var a=WatchedCategories[i];
        cwwpajax.download({url:scriptPath+'/api.php?action=query&list=categorymembers&'
                           +'cmtitle=Category:'+encodeURI(a)+'&cmlimit=1&cmprop=title'
                           +'|timestamp&cmsort=timestamp&cmdir=desc&format=xml',
                           onSuccess:cwOntoWatchlist,
                           catname:a, async:true});
      }
    }
  }
});

//</nowiki>