User:Jafeluv/closeToolbox.js

// // 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, ' \'\'\ + result + '\'\'\'. ' + , '', 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(' ====', ' \'\'\ + result + '\'\'\'. ' + '\n', , summary); } // Relist a CfD discussion. function relistCfd { closeXfd(' ====', ' to Categories for discussion/Log/. ' + '\n', '', 'relist discussion'); } // Close an FfD discussion. function closeFfd(result, summary) { closeXfd(']]====', '\'\'\ + result + '\'\'\'. ' + , '', summary); } // Close an MfD discussion. function closeMfd(result, summary) { closeXfd(null, ' \'\'\ + result + '\'\'\'. ' + , '', summary); } // Close an RfD discussion. function closeRfd(result, summary) { closeXfd(' ====', '\'\'\ + result + '\'\'\'. ' + , '', summary); } // Close a TfD discussion. function closeTfd(result, summary) { closeXfd(']] ====', '\'\'\ + result + '\'\'\'. ' + , '', summary); } // Close a move discussion. function closeRM(result, summary, templateName) { var form = document.editform; var textBox = form.wpTextbox1; var splitText = textBox.value.split('\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('\'\'\ + result + '\'\'\'.');  textBox.value += ;  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('', 'link to cfd');", ""); 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('', 'link to ffd');", ""); mw.util.addPortletLink("p-xfdlink", "javascript:xfdLink('', 'link to rfd');", ""); 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('', 'link to afd');", ""); mw.util.addPortletLink("p-xfdlink", "javascript:xfdLink('', 'link to rfd');", ""); 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('', 'link to tfd');", ""); mw.util.addPortletLink("p-xfdlink", "javascript:xfdLink('', 'link to rfd');", ""); 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 = " " + name + "  ";  toolboxElement.parentNode.insertBefore(closeElement, toolboxElement.nextSibling); } //