User:Jafeluv/closeToolbox.js
Appearance
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:Jafeluv/closeToolbox. |
//<nowiki>
// Adapted from [[User:King of Hearts/closecfd.js]].
var pageTitle = document.getElementById('firstHeading').getElementsByTagName('span')[0].innerHTML;
function closeXfd(headerEnd, top, bottom, summary) {
var form = document.editform;
var textBox = form.wpTextbox1;
if(headerEnd == null) {
textBox.value = top + '\n' + textBox.value + '\n' + bottom;
} else {
textBox.value = textBox.value.split(headerEnd).join(headerEnd + '\n' + top);
textBox.value += bottom;
}
form.wpSummary.value += summary;
}
// Close an AfD discussion.
function closeAfd(result, summary) {
closeXfd(null, '{{subst:' + 'at}} \'\'\'' + result + '\'\'\'. ~~' + '~~', '{{subst:' + 'ab}}', summary);
var textBox = document.editform.wpTextbox1;
var afdTemplateStart = textBox.value.indexOf('{{REMOVE THIS TEMPLATE WHEN CLOSING THIS AfD');
textBox.value = textBox.value.substring(0, afdTemplateStart-1) + textBox.value.substring(textBox.value.indexOf('\n', afdTemplateStart));
}
// Close a CfD discussion.
function closeCfd(result, summary) {
closeXfd(' ====', '{{subst:' + 'cfd top}} \'\'\'' + result + '\'\'\'. ~~' + '~~\n----', '{{subst:' + 'cfd bottom}}', summary);
}
// Relist a CfD discussion.
function relistCfd() {
closeXfd(' ====', '{{subst:' + 'cfd top}} {{relisted' + '}} to [[Wikipedia:Categories for discussion/Log/{{subst:' + '#time:Y F j}}]]. ~~' + '~~\n----', '{{subst:' + 'cfd bottom}}', 'relist discussion');
}
// Close an FfD discussion.
function closeFfd(result, summary) {
closeXfd(']]====', '{{subst:' + 'ffd top|\'\'\'' + result + '\'\'\'.}} ~~' + '~~', '{{subst:' + 'ffd bottom}}', summary);
}
// Close an MfD discussion.
function closeMfd(result, summary) {
closeXfd(null, '{{subst:' + 'mfd top}} \'\'\'' + result + '\'\'\'. ~~' + '~~', '{{subst:' + 'mfd bottom}}', summary);
}
// Close an RfD discussion.
function closeRfd(result, summary) {
closeXfd('</span>====', '{{subst:' + 'rfd top|\'\'\'' + result + '\'\'\'.}} ~~' + '~~', '{{subst:' + 'rfd bottom}}', summary);
}
// Close a TfD discussion.
function closeTfd(result, summary) {
closeXfd(']] ====', '{{subst:' + 'tfd top|\'\'\'' + result + '\'\'\'.}} ~~' + '~~', '{{subst:' + 'tfd bottom}}', summary);
}
// Close a move discussion.
function closeRM(result, summary, templateName) {
var form = document.editform;
var textBox = form.wpTextbox1;
var splitText = textBox.value.split('{{' + templateName);
if(splitText[1].indexOf('}}\n\n') == -1) {
splitText[1] = splitText[1].substring(splitText[1].indexOf('}}\n') + 3, splitText[1].length);
} else {
splitText[1] = splitText[1].substring(splitText[1].indexOf('}}\n\n') + 4, splitText[1].length);
}
textBox.value = splitText.join('{{subst:' + 'RM top|\'\'\'' + result + '\'\'\'.}}');
textBox.value += '{{subst:' + 'RM bottom}}';
form.wpSummary.value += summary;
}
// Add link to an old XfD discussion.
function xfdLink(xfdlink, summary) {
var form = document.editform;
var textBox = form.wpTextbox1;
textBox.value = xfdlink + "\n" + textBox.value;
form.wpSummary.value += summary;
form.wpWatchthis.checked = false;
if(form.wpMinoredit)
{
form.wpMinoredit.checked = true;
}
}
jQuery( document ).ready( function( $ ) {
// Toolbox menu for closing move discussions.
var template = /\{\{([Mm]overeq|[Rr]equested move\/dated)/;
var matchRM = false;
if(document.editform) {
matchRM = document.editform.wpTextbox1.value.match(template);
}
if(pageTitle.match(/Editing /) && matchRM) {
addToolbox("Close requested move", "p-close");
mw.util.addPortletLink("p-close", "javascript:closeRM('Move', 'close discussion, result was move', '" + matchRM[1] + "')", "Move");
mw.util.addPortletLink("p-close", "javascript:closeRM('Not moved', 'close discussion, not moved', '" + matchRM[1] + "')", "Not moved");
mw.util.addPortletLink("p-close", "javascript:closeRM('No consensus', 'close discussion, no consensus to move', '" + matchRM[1] + "')", "No consensus");
document.getElementById('p-close').getElementsByTagName('div')[0].style.display = 'block';
}
// Toolbox menu for closing AfD discussions.
else if (pageTitle.match(/Editing Wikipedia:Articles for deletion\//)) {
addToolbox("Close AfD", "p-close");
mw.util.addPortletLink("p-close", "javascript:closeAfd('Delete', 'close discussion, result was delete')", "Delete");
mw.util.addPortletLink("p-close", "javascript:closeAfd('Rename', 'close discussion, result was rename')", "Rename");
mw.util.addPortletLink("p-close", "javascript:closeAfd('Merge', 'close discussion, result was merge')", "Merge");
mw.util.addPortletLink("p-close", "javascript:closeAfd('Keep', 'close discussion, result was keep')", "Keep");
mw.util.addPortletLink("p-close", "javascript:closeAfd('No consensus', 'close discussion, result was no consensus')", "No consensus");
document.getElementById('p-close').getElementsByTagName('div')[0].style.display = 'block';
}
// Toolbox menu for closing CfD discussions.
else if (pageTitle.match(/Editing Wikipedia:Categories for discussion\/Log\/.* \(section\)/)) {
addToolbox("Close CfD", "p-close");
mw.util.addPortletLink("p-close", "javascript:closeCfd('Delete', 'close discussion, result was delete')", "Delete");
mw.util.addPortletLink("p-close", "javascript:closeCfd('Rename', 'close discussion, result was rename')", "Rename");
mw.util.addPortletLink("p-close", "javascript:closeCfd('Merge', 'close discussion, result was merge')", "Merge");
mw.util.addPortletLink("p-close", "javascript:closeCfd('Keep', 'close discussion, result was keep')", "Keep");
mw.util.addPortletLink("p-close", "javascript:closeCfd('No consensus', 'close discussion, result was no consensus')", "No consensus");
mw.util.addPortletLink("p-close", "javascript:relistCfd()", "Relist");
document.getElementById('p-close').getElementsByTagName('div')[0].style.display = 'block';
}
// Toolbox menu for closing FfD discussions.
else if (pageTitle.match(/Editing Wikipedia:Files for deletion\/.* \(section\)/)) {
addToolbox("Close FfD", "p-close");
mw.util.addPortletLink("p-close", "javascript:closeFfd('Delete', 'close discussion, result was delete')", "Delete");
mw.util.addPortletLink("p-close", "javascript:closeFfd('Keep', 'close discussion, result was keep')", "Keep");
mw.util.addPortletLink("p-close", "javascript:closeFfd('No consensus', 'close discussion, result was no consensus')", "No consensus");
document.getElementById('p-close').getElementsByTagName('div')[0].style.display = 'block';
}
// Toolbox menu for closing MfD discussions.
else if (pageTitle.match(/Editing Wikipedia:Miscellany for deletion\//)) {
addToolbox("Close MfD", "p-close");
mw.util.addPortletLink("p-close", "javascript:closeMfd('Delete', 'close discussion, result was delete')", "Delete");
mw.util.addPortletLink("p-close", "javascript:closeMfd('Rename', 'close discussion, result was rename')", "Rename");
mw.util.addPortletLink("p-close", "javascript:closeMfd('Merge', 'close discussion, result was merge')", "Merge");
mw.util.addPortletLink("p-close", "javascript:closeMfd('Keep', 'close discussion, result was keep')", "Keep");
mw.util.addPortletLink("p-close", "javascript:closeMfd('No consensus', 'close discussion, result was no consensus')", "No consensus");
document.getElementById('p-close').getElementsByTagName('div')[0].style.display = 'block';
}
// Toolbox menu for closing RfD discussions.
else if (pageTitle.match(/Editing Wikipedia:Redirects for discussion\/Log\/.* \(section\)/)) {
addToolbox("Close RfD", "p-close");
mw.util.addPortletLink("p-close", "javascript:closeRfd('delete', 'close discussion, result was delete')", "Delete");
mw.util.addPortletLink("p-close", "javascript:closeRfd('retarget', 'close discussion, result was retarget')", "Retarget");
mw.util.addPortletLink("p-close", "javascript:closeRfd('keep', 'close discussion, result was keep')", "Keep");
mw.util.addPortletLink("p-close", "javascript:closeRfd('no consensus', 'close discussion, result was no consensus')", "No consensus");
document.getElementById('p-close').getElementsByTagName('div')[0].style.display = 'block';
}
// Toolbox menu for closing TfD discussions.
else if (pageTitle.match(/Editing Wikipedia:Templates for discussion\/Log\/.* \(section\)/)) {
addToolbox("Close TfD", "p-close");
mw.util.addPortletLink("p-close", "javascript:closeTfd('delete', 'close discussion, result was delete')", "Delete");
mw.util.addPortletLink("p-close", "javascript:closeTfd('merge', 'close discussion, result was merge')", "Merge");
mw.util.addPortletLink("p-close", "javascript:closeTfd('keep', 'close discussion, result was keep')", "Keep");
mw.util.addPortletLink("p-close", "javascript:closeTfd('no consensus', 'close discussion, result was no consensus')", "No consensus");
document.getElementById('p-close').getElementsByTagName('div')[0].style.display = 'block';
}
// Toolbox for adding links to old discussions.
else if(pageTitle.match(/(Editing|Creating) Category talk:/)) {
addToolbox("Add link", "p-xfdlink");
mw.util.addPortletLink("p-xfdlink", "javascript:xfdLink('{{oldcfdfull |action = |date = year|month|day |result = |name = }}', 'link to cfd');", "{{oldcfdfull}}");
document.getElementById('p-xfdlink').getElementsByTagName('div')[0].style.display = 'block';
}
else if(pageTitle.match(/(Editing|Creating) File talk:/)) {
addToolbox("Add link", "p-xfdlink");
mw.util.addPortletLink("p-xfdlink", "javascript:xfdLink('{{oldffdfull |date={{' + 'subst:#time:j F Y|-7 days}}}}', 'link to ffd');", "{{oldffdfull}}");
mw.util.addPortletLink("p-xfdlink", "javascript:xfdLink('{{oldrfd |date={{' + 'subst:#time:j F Y|-7 days}} |page={{'+ 'subst:#time:Y F j|-7 days}}#File:{{' + 'subst:PAGENAME}}}}', 'link to rfd');", "{{oldrfd}}");
document.getElementById('p-xfdlink').getElementsByTagName('div')[0].style.display = 'block';
}
else if(pageTitle.match(/(Editing|Creating) (Wikipedia talk|Help talk|Talk):/)) {
addToolbox("Add link", "p-xfdlink");
mw.util.addPortletLink("p-xfdlink", "javascript:xfdLink('{{oldafd}}', 'link to afd');", "{{oldafd}}");
mw.util.addPortletLink("p-xfdlink", "javascript:xfdLink('{{oldrfd |date={{' + 'subst:#time:j F Y|-7 days}} |page={{'+ 'subst:#time:Y F j|-7 days}}#{{' + 'subst:PAGENAME}}}}', 'link to rfd');", "{{oldrfd}}");
document.getElementById('p-xfdlink').getElementsByTagName('div')[0].style.display = 'block';
}
else if(pageTitle.match(/(Editing|Creating) Template talk:/)) {
addToolbox("Add link", "p-xfdlink");
mw.util.addPortletLink("p-xfdlink", "javascript:xfdLink('{{tfdend |date={{' + 'subst:#time:j F Y|-7 days}} |result= }}', 'link to tfd');", "{{tfdend}}");
mw.util.addPortletLink("p-xfdlink", "javascript:xfdLink('{{oldrfd |date={{' + 'subst:#time:j F Y|-7 days}} |page={{'+ 'subst:#time:Y F j|-7 days}}#{{' + 'subst:PAGENAME}}}}', 'link to rfd');", "{{oldrfd}}");
document.getElementById('p-xfdlink').getElementsByTagName('div')[0].style.display = 'block';
}
});
// Add toolbox.
function addToolbox(name, id) {
var toolboxElement = document.getElementById("p-tb");
var closeElement = toolboxElement.cloneNode(true);
closeElement.id = id;
closeElement.innerHTML = "<h3>" + name + "</h3><div class=body><ul></ul></div>";
toolboxElement.parentNode.insertBefore(closeElement, toolboxElement.nextSibling);
}
//</nowiki>