User:Living Concrete/sandboxreset.js

/* Script works with Template:X* and Wikipedia:Sandbox, as well as the introduction sandboxes. */ /* Based off of User:VoA/monobook.js. */ addOnloadHook(function { if(wgPageName == "Wikipedia:Sandbox" || (wgPageName.lastIndexOf("Wikipedia:Tutorial") != -1 && wgPageName.lastIndexOf("/sandbox") != -1))  {    mw.util.addPortletLink('p-cactions', "javascript:sandboxReset(0)", "reset", "ca-sand", "Reset the Sandbox", "");    mw.util.addPortletLink('p-cactions', "javascript:sandboxReset(1)", "rake", "ca-sand", "Rake in Sandbox Header", "");

if(document.URL.lastIndexOf("&sandboxautoreset=true") == -1) return;

var form = document.editform; if(document.URL.lastIndexOf("&rake=yes") == -1) { if(wgPageName.lastIndexOf("Wikipedia:Tutorial") != -1 && wgPageName.lastIndexOf("/sandbox") != -1) form.wpTextbox1.value = "\n" + "";     else form.wpTextbox1.value = "\n" + "";     form.wpSummary.value = "JavaScript assisted edit: Resetting the sandbox."; form.wpSave.click; }   else if(document.URL.lastIndexOf("&rake=no") == -1) { if(wgPageName.lastIndexOf("Wikipedia:Tutorial") != -1 && wgPageName.lastIndexOf("/sandbox") != -1) { if(form.wpTextbox1.value.lastIndexOf("") != -1) { alert("Heading already exists on page. No need for a rake."); return; }     } else { if(form.wpTextbox1.value.lastIndexOf("") != -1) { alert("Heading already exists on page. No need for a rake."); return; }     }

if(wgPageName.lastIndexOf("Wikipedia:Tutorial") != -1 && wgPageName.lastIndexOf("/sandbox") != -1) form.wpTextbox1.value = "\n" + "\n" + form.wpTextbox1.value; else form.wpTextbox1.value = "\n" + "\n" + form.wpTextbox1.value; form.wpSummary.value = "JavaScript assisted edit: Rake in sandbox header."; form.wpSave.click; } }  else if(wgPageName == "Template:X1" || wgPageName == "Template:X2" || wgPageName == "Template:X3" || wgPageName == "Template:X4" || wgPageName == "Template:X5" || wgPageName == "Template:X6" || wgPageName == "Template:X7" || wgPageName == "Template:X8" || wgPageName == "Template:X9" || wgPageName == "Template:Template_sandbox") { mw.util.addPortletLink('p-cactions', "javascript:sandboxReset(0)", "reset", "ca-sand", "Reset the Sandbox", ""); mw.util.addPortletLink('p-cactions', "javascript:sandboxReset(1)", "rake", "ca-sand", "Rake in Sandbox Header", ""); if(document.URL.lastIndexOf("&sandboxautoreset=true") == -1) return;

var form = document.editform; if(document.URL.lastIndexOf("&rake=yes") == -1) { form.wpTextbox1.value = "This sandbox is itself a template. This sandbox is for experimenting with templates.\n" + "\n\n" + "If you defined parameters such as   :\n" + ";First:\n" + ";Second:\n" + ";Name:\n\n" + "\n" + ""; form.wpSummary.value = "JavaScript assisted edit: Resetting the sandbox."; form.wpSave.click; }   else if(document.URL.lastIndexOf("&rake=no") == -1) { if(form.wpTextbox1.value.lastIndexOf("") != -1) { alert("Heading already exists on page. No need for a rake."); return; }

form.wpTextbox1.value = "This sandbox is itself a template. This sandbox is for experimenting with templates.\n" + "\n\n" + "If you defined parameters such as   :\n" + ";First:\n" + ";Second:\n" + ";Name:\n\n" + "\n" + "\n" + form.wpTextbox1.value; form.wpSummary.value = "JavaScript assisted edit: Rake in sandbox header."; form.wpSave.click; } } });

function sandboxReset(num) { if(num == 0) location.assign("/w/index.php?title=" + wgPageName + "&action=edit&sandboxautoreset=true&rake=no"); else location.assign("/w/index.php?title=" + wgPageName + "&action=edit&sandboxautoreset=true&rake=yes"); }