User:Steve Crossin/revertall2.js

From Simple English Wikipedia, the free encyclopedia

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
// =-=-=- HELPER FUNCTIONS -=-=-=-
function addlilink(tabs, url, name, id, title, key){
    var na = document.createElement('a');
    na.href = url;
    na.appendChild(document.createTextNode(name));
    var li = document.createElement('li');
    if(id) li.id = id;
    li.appendChild(na);
    tabs.appendChild(li);
    if(id)
    {
        if(key && title)
        {
            ta[id] = [key, title];
        }
        else if(key)
        {
            ta[id] = [key, ''];
        }
        else if(title)
        {
            ta[id] = ['', title];
        }
    }
    // re-render the title and accesskeys from existing code in wikibits.js
    akeytt();
    return li;
}

function addToolboxLink(url, name, id, title){
    var tb = document.getElementById('p-tb').getElementsByTagName('ul')[0];
    addlilink(tb, url, name, id, title);
}

function addTab(url, name, id, title, key) {
    return mw.util.addPortletLink('p-cactions', url, name, id, title, key);
}

function addLink(where, url, name, id, title, key, after){
    var na = document.createElement('a');
    na.href = url;
    na.appendChild(document.createTextNode(name));
    var li = document.createElement('li');
    if(id) li.id = id;
    li.appendChild(na);
    var tabs = document.getElementById(where).getElementsByTagName('ul')[0];
    if(after) {
	tabs.insertBefore(li,document.getElementById(after));
    } else {
	tabs.appendChild(li);
    }
    if(id) {
	if(key && title) { ta[id] = [key, title]; }
	else if(key) { ta[id] = [key, '']; }
	else if(title) { ta[id] = ['', title];} 
    }
    // re-render the title and accesskeys from existing code in wikibits.js
    akeytt();
    return li;
}

function addlimenu(tabs, name, id)
{
    var na = document.createElement('a');
    na.href = '#';
    var mn = document.createElement('ul');
    na.appendChild(document.createTextNode(name));
    var li = document.createElement('li');
    li.id = id;
    li.className = 'tabmenu';
    li.appendChild(na);
    li.appendChild(mn);
    tabs.appendChild(li);
    return li;
}

function addnavbox_link(URL,Name,ID)
{
var portlet = document.getElementById('p-navigation');
var links = portlet.getElementsByTagName('ul')[0];
links.innerHTML += '<li id="' + ID + '"><a href="' + URL + '">' + Name + '</a></li>';
}
/////////////////////////////////////////////

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 UrlParameters(params) {
 if(location.href.indexOf(params + "=") != -1) {
  var parm = location.href.substring(location.href.indexOf(params) + params.length++).split("=")[1];
  return decodeURIComponent((parm.indexOf("&") != -1 ? parm.split("&")[0] : parm));
 } else {
   return undefined;
 }
} */

// Copied from [[User:DerHexer]] with extreme pride


function resetSandbox() {
  if(UrlParameters["sandboxreset"] == 1 && wgPageName == "Wikipedia:Sandbox" && UrlParameters["action"] == "edit") {
    document.forms["editform"].elements["wpTextbox1"].value = "\{\{Please leave this line alone (sandbox heading)\}\}\n<!-- Hello! Feel free to try your formatting and editing skills below this line\. As this page is for editing experiments, this page will automatically be cleaned every 12 hours. -->"; //Add the base text for the sandbox
    document.forms["editform"].elements["wpSummary"].value = "[[User:Animum/reset.js|JS EDIT]]: Reset the Sandbox"; //Make a descriptive edit summary
    document.forms["editform"].elements["wpWatchthis"].checked = false; //Chances are you already have the sandbox watchlisted
    document.forms["editform"].elements["wpMinoredit"].checked = true; //Make it a minor edit
    if(UrlParameters["indirect"] == 1) { //If you've clicked on the toolbox link
      window.setTimeout(function() { document.forms["editform"].elements["wpDiff"].click(); }, 200); //Load the diff if you are resetting it per the toolbox link
      var save = confirm("Save? (click \"OK\" to save; \"cancel\" to abort)"); // Do you want to make these changes?
      if(save == true) { 
        window.setTimeout(function() { document.forms["editform"].elements["wpSave"].click(); }, 200); //Submit it!
      } else { location.href = "http://en.wikipedia.org/wiki/Wikipedia:Sandbox"; } // Go back two pages if you don't want to save it
    } else {
    window.setTimeout(function() { document.forms["editform"].elements["wpSave"].click(); }, 200); //Submit it! 
    }
  }
}
 
$(function () {
    if(wgPageName == "Wikipedia:Sandbox") // If the page you are viewing is the sandbox
      { mw.util.addPortletLink('p-cactions', 'http://en.wikipedia.org/w/index.php?title=Wikipedia:Sandbox&action=edit&sandboxreset=1', 'reset', 'ca-reset', "Reset the Sandbox"); }
    if(wgPageName != "Wikipedia:Sandbox") // If the page you are viewing is NOT the sandbox 
      { addToolboxLink("http://en.wikipedia.org/w/index.php?title=Wikipedia:Sandbox&action=edit&sandboxreset=1&indirect=1", 'Reset the Sandbox', '', '', ''); }
});

$(resetSandbox);