Jump to content

User:DerHexer/rollback.js

From Wikipedia, the free encyclopedia
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
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.
 // originally from [[User:DerHexer]]
 
 // get URL parameters (used for page type variables)
 var UrlParameters = new Array ();
 readparams();
 
 function readparams() {
  var asReadInUrlParameters;
  var asReadInUrlParameter;
 
  // Get URL parameters
  asReadInUrlParameters = location.search.substring(1, location.search.length).split("&");
  for (i = 0; i < asReadInUrlParameters.length; i++) {
    asReadInUrlParameter = asReadInUrlParameters[i].split("=");
    UrlParameters[decodeURIComponent(asReadInUrlParameter[0])] = decodeURIComponent(asReadInUrlParameter[1]);
  }
 }

 if(!usersignature) var usersignature = '\~\~\~\~'         //standard signature
 if(!automaticblock) var automaticblock=false;
 if(!automaticwarning) var automaticwarning=false;
 
 function fillActionPageRevert() {
   if (UrlParameters["blockreason"] > "" && UrlParameters["blockduration"] > "") {
     document.forms["blockip"].wpBlockReason.value = UrlParameters["blockreason"];
     document.forms["blockip"].wpBlockOther.value = UrlParameters["blockduration"];
     var blocktime = UrlParameters["blockduration"];
     var isBlocked = UrlParameters["title"].replace(/Special:Block\//, '');
     if (isBlocked.search(/\d+\.\d+\.\d+\.\d+/) == -1) {
        if (prompt('Are you sure to block, ' + isBlocked + ' ?','ja')) {
         var newurl = "http://en.wikipedia.org/w/index.php?title=User:" + isBlocked + "&action=edit&addtemplate=2";
         if(automaticblock) { window.setTimeout(function() { document.forms["blockip"].wpBlock.click(); }, 100); }
        }
     } else {
       var newurl = "http://en.wikipedia.org/w/index.php?title=User_talk:" + isBlocked + "&action=edit&addtemplate=1&blockduration=" + blocktime;
       if(automaticblock) { window.setTimeout(function() { document.forms["blockip"].wpBlock.click(); }, 100);}
     }
     if(automaticblock) { if ((UrlParameters["blockduration"] != 'infinite') || (isBlocked.search(/\d+\.\d+\.\d+\.\d+/) == -1)) { window.setTimeout(function() { location.href = newurl; }, 1000); } }
   }
 
   if (UrlParameters["diff"] > "") {
     function searchRollbackLink() {
       var tds = document.getElementsByTagName("td");
       for (var i=0; i<tds.length; i++) {
         var td = tds[i]; 
         if (td.className != "diff-ntitle") continue;
         var as = td.getElementsByTagName("a");
         for (var j=0; j<as.length; j++) {
           var a = as[j];
           if (!/.*action=rollback.*/(a.href)) continue;
           var newlink = document.createElement('a');
           a.setAttribute('accesskey', "s");
           newlink.setAttribute('href', a.href);
           var EditTextNode = document.createTextNode("normal rollback");
           newlink.appendChild(EditTextNode);
           as[j].parentNode.insertBefore( newlink, as[j].nextSibling );
           as[j].parentNode.insertBefore( document.createTextNode(' | '), as[j].nextSibling );
           return a;
         }
       }
       return tds;
     }
 
     function RollAndSpam(rolluri) {
       location.href = rolluri;
       var backrolled = rolluri.split("from=")[1].split("&token=")[0];
       var vandalizedpage = mw.config.get('wgPageName');
       var uri = "http://en.wikipedia.org/w/index.php?title=User talk:" + backrolled + "&vandalizedpage=" + vandalizedpage + "&action=edit&spam=1";
       window.setTimeout(function() { location.href = uri; }, 500);
     }
     var revlink = searchRollbackLink();
     revlink.onclick = function() { RollAndSpam(revlink.href); return false; }
   }
 
   if ( (UrlParameters["spam"] > "") && (UrlParameters["vandalizedpage"] > "") ) {
       document.editform.wpMinoredit.checked=true;
       var splitted = document.forms["editform"].wpTextbox1.value.split("<!--");
       var lastsplitted = splitted[splitted.length-1];
 
         var jetzt = new Date();
         var thisyear = jetzt.getFullYear().toString();
         var thismonth = jetzt.getMonth()+1;
         if (thismonth < 10) { thismonth = "0" + thismonth; }
         var thisday = jetzt.getDate();
         if (thisday < 10) { thisday = "0" + thisday; }
         var thishour = jetzt.getHours();
         if (thishour < 10) { thishour = "0" + thishour; }
         var thisminute = jetzt.getMinutes();
         if (thisminute < 10) { var thisminute2 = "0" + thisminute; } else { var thisminute2 = thisminute; }
         var thissecond = jetzt.getSeconds();
         if (thissecond < 10) { thissecond = "0" + thissecond; }
         var thistime = thisyear + thismonth + thisday + thishour + thisminute + thissecond;
         var req;
         if (req = newRequest()) {
           var text = '/w/api.php?format=xml&action=query&prop=revisions&titles=' + mw.config.get('wgPageName') + '&rvlimit=1&rvprop=timestamp&rvdir=older&rvstart=' + thistime;
           req.open("GET", text, false);
           req.send("");
 
           var lasttimestamp = req.responseXML.getElementsByTagName("rev")[0].getAttribute('timestamp');
           var lastminute = lasttimestamp.match(/([^\-]*)\-([^\-]*)\-([^T]*)T([^\:]*)\:([^\:]*)\:([^Z]*)Z/);
           lastyear = RegExp.$1;
           lastmonth = RegExp.$2;
           lastday = RegExp.$3;
           lasthour = parseInt(RegExp.$4)+1;
           if (lasthour < 10) { lasthour = "0" + lasthour.toString(); } else { lasthour = lasthour.toString() }
           lastminute = RegExp.$5;
           lastsecond = RegExp.$6;
           var lastdate = Date.parse(lastmonth + ' ' + lastday + ' ' + lastyear + ' ' + lasthour + ':' + lastminute + ':' + lastsecond);
           var thisdate = Date.parse(thismonth + ' ' + thisday + ' ' + thisyear + ' ' + thishour + ':' + thisminute + ':' + thissecond);
       }
 
       var matchedtemplate = lastsplitted.match(/uw\-([^\d]*)(\d)/);
       var matchedtemplatename = RegExp.$1;
       var matchednumber = RegExp.$2;
       var matchedtemplate2 = lastsplitted.match(/Template\:Test(\d)/);
       var matchednumber2 = RegExp.$1;
       if (lastsplitted.search(/Uw\-Blank(\d)/) != -1) {
         var matchednumber = RegExp.$1;
         var matchedtemplatename = 'vandalism';
       } else if (lastsplitted.search(/Uw\-Blank[^\d]/) != -1) {
         var matchednumber = 1;
         var matchedtemplatename = 'vandalism';
       }
       if ((lastsplitted.search(/Uw\-bv/) != -1) || (lastsplitted.search(/Blatantvandal/) != -1) || (lastsplitted.search(/longterm/) != -1)) {
         var matchednumber = 4;
         var matchedtemplatename = 'vandalism';
       }
       if ((!matchedtemplatename) || (matchedtemplatename == 'cluebotwarning') || (matchedtemplatename == 'block') || (matchedtemplatename == 'huggle') || (matchedtemplatename == 'huggleblock') || (matchedtemplatename.search(/\d/) != -1)) { 
         var matchedtemplatename = 'vandalism';
       }
       if (document.forms["editform"].wpTextbox1.value == "") {
         document.editform.wpSummary.value = "Caution: " + matchedtemplatename + " on \[\[" + UrlParameters["vandalizedpage"].replace(/\_/g, ' ') + "\]\]";
         document.forms["editform"].wpTextbox1.value = document.forms["editform"].wpTextbox1.value + "\{\{subst\:uw-" + matchedtemplatename + "2\|" + UrlParameters["vandalizedpage"].replace(/\_/g, ' ') + "\}\} " + usersignature;
 
         if(automaticwarning) { document.editform.wpSave.click();
         window.setTimeout(function() { window.close(); }, 1000); }
       } else {
 
               var confirmcontinue = true;
               var oldip = false;
               if ((thisdate-lastdate) < 20000) {
                 confirmcontinue = confirm('This IP was warned less than 20 second ago. There might be an edit conflict. Do you want to continue nevertheless?');
               } else if ((thisdate-lastdate) > 86400000) {
                 var oldip = true;
               }
 
         if (confirmcontinue && oldip) {
           document.editform.wpSummary.value = "Caution: " + matchedtemplatename + " on \[\[" + UrlParameters["vandalizedpage"].replace(/\_/g, ' ') + "\]\]";
           document.forms["editform"].wpTextbox1.value = document.forms["editform"].wpTextbox1.value + "\n\n\{\{subst\:uw-" + matchedtemplatename + "2\|" + UrlParameters["vandalizedpage"].replace(/\_/g, ' ') + "\}\} " + usersignature;
           if(automaticwarning) { document.editform.wpSave.click();
           window.setTimeout(function() { window.close(); }, 1000); }
         } else if (confirmcontinue && !oldip) {
             if ((matchednumber == 4) || (matchednumber2 == 4)) {
               if (mw.config.get('wgTitle').match(/\d+\.\d+\.\d+\.\d+/)) {
 
                function newRequest()
                {
                  try {
                    if (window.XMLHttpRequest) {
                      return new XMLHttpRequest();
                    } else {
                      return new ActiveXObject("MSXML2.XMLHTTP");
                    }
                  } catch (e) {
                    return false;
                  }
                }
 
                var req;
                if (req = newRequest()) {
                  var text = "/w/api.php?format=xml&action=query&list=logevents&letype=block&letitle=User:" + mw.config.get('wgTitle');
                  req.open("GET", text, false);
                  req.send("");
      
                  var blocks = req.responseXML.getElementsByTagName("block");
                  if (blocks.length > 0) {
                    if (blocks[0].getAttribute('duration').search(/\./) == -1) {
                      var duration = blocks[0].getAttribute('duration');
                    } else {
                      var duration = "12 hours";
                    }
                  } else {
                    var duration = "12 hours";
                  }
                }
 
                if (duration.search(/(\d+) (\w+)/) != -1) {
                  var newblockdurationnumber = 2 * RegExp.$1;
                  var lastblockdurationname = RegExp.$2;
                  if (lastblockdurationname.search(/s\b/) != -1) {
                    var newblockdurationname = lastblockdurationname;
                  } else {
                    var newblockdurationname = lastblockdurationname + "s";
                  }
                  var blockurl = "http://en.wikipedia.org/w/index.php?title=Special:Block/" + mw.config.get('wgTitle') + "&blockduration=" + newblockdurationnumber + "%20" + newblockdurationname + "&blockreason=vandalism";
                } else {
                  var blockurl = "http://en.wikipedia.org/w/index.php?title=Special:Block/" + mw.config.get('wgTitle');
                }
               } else {
                 var blockurl = "http://en.wikipedia.org/w/index.php?title=Special:Block/" + mw.config.get('wgTitle') + "&blockduration=infinite&blockreason=vandalism-only%20account";
               }
               if(automaticwarning) { window.setTimeout(function() { location.href = blockurl; }, 1000); }
             } else {
               document.editform.wpSummary.value = "Final warning: " + matchedtemplatename + " on \[\[" + UrlParameters["vandalizedpage"].replace(/\_/g, ' ') + "\]\]";
               document.forms["editform"].wpTextbox1.value = document.forms["editform"].wpTextbox1.value + "\n\n\{\{subst\:uw-" + matchedtemplatename + "4\|" + UrlParameters["vandalizedpage"].replace(/\_/g, ' ') + "\}\} " + usersignature;
               if(automaticwarning) { document.editform.wpSave.click();
               window.setTimeout(function() { window.close(); }, 1000); }
             }
         }
       }
   }
 
   if (UrlParameters["addtemplate"] > '') {
     document.editform.wpMinoredit.checked=true;
     if (UrlParameters["addtemplate"] == 1) {
       document.editform.wpSummary.value = "You have been temporarily blocked.";
       document.forms["editform"].wpTextbox1.value = document.forms["editform"].wpTextbox1.value + "\n\n\{\{subst\:uw-block1\|time=" + UrlParameters["blockduration"] + "\|reason\=vandalism\|subst\=subst\:\}\}";
     } else if (UrlParameters["addtemplate"] == 2) {
       document.editform.wpSummary.value = "\{\{indefblockeduser\}\}";
       document.forms["editform"].wpTextbox1.value = "\{\{indefblockeduser\}\}";
     }
     document.editform.wpSave.click();
     window.setTimeout(function() { window.close(); }, 1000);
   }
 }


 if ( (UrlParameters["blockreason"] > "") || (UrlParameters["diff"] > "") || ( (UrlParameters["spam"] > "") && (UrlParameters["vandalizedpage"] > "") ) || (UrlParameters["addtemplate"] > '') ) {
   addOnloadHook(fillActionPageRevert);
 }