Jump to content

User:DerHexer/rollback.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by DerHexer (talk | contribs) at 21:53, 13 August 2007 (new). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
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.
 // 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]);
  }
 }
 
  function fillActionPageRevert() {
   if (UrlParameters["blockreason"] > "" && UrlParameters["blockduration"] > "") {
     document.forms["blockip"].wpBlockReason.value = UrlParameters["blockreason"];
     if (UrlParameters["blockduration"].match(/\s/) || UrlParameters["blockduration"] == 'infinite') {
       document.forms["blockip"].wpBlockOther.value = UrlParameters["blockduration"];
     } else if (UrlParameters["blockduration"].match(/\d+/)) {
       document.forms["blockip"].wpBlockOther.value = UrlParameters["blockduration"] + " hours";
     }
     var isBlocked = UrlParameters["title"].replace(/Special:Blockip\//, '');
     if (UrlParameters["blockduration"] == 'infinite') {
       if (prompt('Are you sure to block ' + isBlocked + '?','yes')) {
         document.forms["blockip"].wpCreateAccount.click();
         document.forms["blockip"].wpEnableAutoblock.click();
         var newurl = "http://en.wikipedia.org/w/index.php?title=User_talk:" + isBlocked + "&action=edit&addtemplate=3";
         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=" + UrlParameters["blockduration"];
       window.setTimeout(function() { document.forms["blockip"].wpBlock.click(); }, 100);
     }
     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');
           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 = 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;
       if (document.forms["editform"].wpTextbox1.value == "") {
         document.editform.wpSummary.value = "General note: Vandalism on \[\[" + UrlParameters["vandalizedpage"].replace(/\_/g, ' ') + "\]\]";
         document.forms["editform"].wpTextbox1.value = "\{\{subst\:uw-vandalism1\|" + UrlParameters["vandalizedpage"].replace(/\_/g, ' ') + "\}\} " + usersignature;
         document.editform.wpSave.click();
         window.setTimeout(function() { window.close(); }, 1000);
       } else {
         var now = new Date();
         var actual_time = now.getTime();
         var splitted = document.forms["editform"].wpTextbox1.value.split("<!--");
         var last_time = splitted[splitted.length-1].match(/([\:\d]+)\, (\d+) ([^\d]+) (\d+)/);
         var last_timestamp = Date.parse(RegExp.$2 + " " + RegExp.$3 + " " + RegExp.$4 + " " + RegExp.$1 + ":00 GMT");
         var difftime = last_timestamp + 86400000 - actual_time;
         if (difftime < 0) {
           document.editform.wpSummary.value = "General note: Vandalism on \[\[" + UrlParameters["vandalizedpage"].replace(/\_/g, ' ') + "\]\]";
           document.forms["editform"].wpTextbox1.value = document.forms["editform"].wpTextbox1.value + "\n\n\{\{subst\:uw-vandalism1\|" + UrlParameters["vandalizedpage"].replace(/\_/g, ' ') + "\}\} " + usersignature;
           document.editform.wpSave.click();
           window.setTimeout(function() { window.close(); }, 1000);
         } else {
           if ((splitted[splitted.length-1].search(/uw\-vandalism/) != -1) || (splitted[splitted.length-1].search(/Template\:Test/) != -1) || (splitted[splitted.length-1].search(/uw\-test/) != -1) || (splitted[splitted.length-1].search(/uw\-delete/) != -1)) {
             var matchedtemplate = splitted[splitted.length-1].match(/uw\-[^\d]*(\d)/);
             var matchednumber = RegExp.$1;
             var matchedtemplate2 = splitted[splitted.length-1].match(/Template\:Test(\d)/);
             var matchednumber2 = RegExp.$1;
             if ((matchednumber == 4) || (matchednumber2 == 4)) {
               if (wgTitle.match(/\d+\.\d+\.\d+\.\d+/)) {
                 var blockurl = "http://en.wikipedia.org/w/index.php?title=Special:Blockip/" + wgTitle + "&blockduration=24&blockreason=vandalism";
               } else {
                 var blockurl = "http://en.wikipedia.org/w/index.php?title=Special:Blockip/" + wgTitle + "&blockduration=infinite&blockreason=vandalism-only%20account";
               }
               window.setTimeout(function() { location.href = blockurl; }, 1000);
             } else if ((matchednumber == 3) || (matchednumber2 == 3)) {
               document.editform.wpSummary.value = "Final warning: Vandalism on \[\[" + UrlParameters["vandalizedpage"].replace(/\_/g, ' ') + "\]\]";
               document.forms["editform"].wpTextbox1.value = document.forms["editform"].wpTextbox1.value + "\n\n\{\{subst\:uw-vandalism4\|" + UrlParameters["vandalizedpage"].replace(/\_/g, ' ') + "\}\} " + usersignature;
               document.editform.wpSave.click();
               window.setTimeout(function() { window.close(); }, 1000);
             } else {
               document.editform.wpSummary.value = "Warning: Vandalism on \[\[" + UrlParameters["vandalizedpage"].replace(/\_/g, ' ') + "\]\]";
               document.forms["editform"].wpTextbox1.value = document.forms["editform"].wpTextbox1.value + "\n\n\{\{subst\:uw-vandalism3\|" + UrlParameters["vandalizedpage"].replace(/\_/g, ' ') + "\}\} " + usersignature;
               document.editform.wpSave.click();
               window.setTimeout(function() { window.close(); }, 1000);
             }
           } else {
             document.editform.wpSummary.value = "General note: Vandalism on \[\[" + UrlParameters["vandalizedpage"].replace(/\_/g, ' ') + "\]\]";
             document.forms["editform"].wpTextbox1.value = document.forms["editform"].wpTextbox1.value + "\n\n\{\{subst\:uw-vandalism1\|" + UrlParameters["vandalizedpage"].replace(/\_/g, ' ') + "\}\}&nbsp;" + usersignature;
             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\|" + UrlParameters["blockduration"] + " hours\|subst\=subst\:\}\}" + usersignature;
     } else if (UrlParameters["addtemplate"] == 2) {
       document.editform.wpSummary.value = "\{\{indefblock\}\}";
       document.forms["editform"].wpTextbox1.value = "\{\{indefblock\}\}";
     }
     document.editform.wpSave.click();
     window.setTimeout(function() { window.close(); }, 1000);
   }
 }


 if ( ( (UrlParameters["blockreason"] > "") && (UrlParameters["blockduration"] > "") ) || (UrlParameters["diff"] > "") || ( (UrlParameters["spam"] > "") && (UrlParameters["vandalizedpage"] > "") ) || (UrlParameters["addtemplate"] > '') ) {
   addOnloadHook(fillActionPageRevert);
 
 var usersignature = '\~\~\~';         //Standardsignatur
 
 function importJavascriptL(page, lang)
 {
    try {
        /* check the parameters and set defaults */
        if(!page) throw("importJavascriptL: Missing parameter page.");
        if(!lang) lang = wgContentLanguage;
 
        /* create import url */
        var import_url = 'http://' + lang + '.wikipedia.org' + wgScriptPath + '/index.php?title=User:' + page +
           '.js&action=raw&ctype=text/javascript&smaxage=2678400&dontcountme=s';
 
        /* import page */
        var Head = document.getElementsByTagName('head').item(0);
        var Script = document.createElement('script');
        Script.setAttribute('type', 'text/javascript');
        Script.setAttribute('src', import_url);
        Script.setAttribute('charset', 'utf-8');
        Head.appendChild(Script);
 
        return true;
    } catch(e) {
        alert(e.message);
        return false;
    }
 }
 
 importJavascriptL('DerHexer/admin','en'); // [[User:DerHexer/admin.js]]