User:Living Concrete/sandboxreset.js
(Redirected from User:Ember of Light/sandboxreset.js)
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:Living Concrete/sandboxreset. |
/* 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 = "{{Please leave this line alone (tutorial 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. -->";
else
form.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. -->";
form.wpSummary.value = "[[User:Ember of Light/sandboxreset.js|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("{{Please leave this line alone (tutorial sandbox heading)}}") != -1) {
alert("Heading already exists on page. No need for a rake.");
return;
}
} else {
if(form.wpTextbox1.value.lastIndexOf("{{Please leave this line alone (sandbox heading)}}") != -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 = "{{Please leave this line alone (tutorial 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. -->\n" + form.wpTextbox1.value;
else
form.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. -->\n" + form.wpTextbox1.value;
form.wpSummary.value = "[[User:Ember of Light/sandboxreset.js|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" + "{{Please leave this line alone (template sandbox heading)}}\n\n" + "If you defined parameters such as <tt><nowiki>{{Template sandbox|First|Second|name=\"Named\"}}</nowiki></tt>:\n" + ";First:{{{1}}}\n" + ";Second:{{{2}}}\n" + ";Name:{{{name}}}\n\n" + "----\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. -->";
form.wpSummary.value = "[[User:Ember of Light/sandboxreset.js|JavaScript assisted edit]]: Resetting the sandbox.";
form.wpSave.click();
}
else if(document.URL.lastIndexOf("&rake=no") == -1) {
if(form.wpTextbox1.value.lastIndexOf("{{Please leave this line alone (template sandbox heading)}}") != -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" + "{{Please leave this line alone (template sandbox heading)}}\n\n" + "If you defined parameters such as <tt><nowiki>{{Template sandbox|First|Second|name=\"Named\"}}</nowiki></tt>:\n" + ";First:{{{1}}}\n" + ";Second:{{{2}}}\n" + ";Name:{{{name}}}\n\n" + "----\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. -->\n" + form.wpTextbox1.value;
form.wpSummary.value = "[[User:Ember of Light/sandboxreset.js|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");
}