User:Jafeluv/blockToolbox.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/blockToolbox. |
// <nowiki>
// Automatize block notifications for the most common block reasons.
var pageTitle = document.getElementById('firstHeading').getElementsByTagName('span')[0].innerHTML;
function userWarning(template, summary) {
var form = document.editform;
var textBox = form.wpTextbox1;
if(textBox.value == '') {
textBox.value = '{{subst:' + template + '}}';
} else {
textBox.value += '{{subst:' + template + '}}';
}
form.wpSummary.value = summary;
form.wpWatchthis.checked = false;
if(form.wpMinoredit)
{
form.wpMinoredit.checked = false;
}
}
function userpageTag(template, summary, cursor) {
var form = document.editform;
var textBox = form.wpTextbox1;
textBox.value = '{{' + template + '}}';
if(cursor)
{
textBox.focus();
textBox.setSelectionRange(cursor, cursor);
}
form.wpSummary.value = summary;
form.wpWatchthis.checked = false;
if(form.wpMinoredit)
{
form.wpMinoredit.checked = false;
}
}
// Add toolbox
function addBlockToolbox(title) {
var toolboxElement = document.getElementById("p-tb");
var patrollingElement= toolboxElement.cloneNode(true);
patrollingElement.id="p-block";
patrollingElement.innerHTML = "<h3>" + title + "</h3><div class=body><ul></ul></div>";
toolboxElement.parentNode.insertBefore(patrollingElement, toolboxElement.nextSibling);
}
jQuery( document ).ready( function( $ ) {
// Toolbox menu for user notification.
if (pageTitle.match(/(Editing|Creating) User talk:/)) {
addBlockToolbox("Block notice");
mw.util.addPortletLink("p-block", "javascript:userWarning('uw-spamublock|sig=yes', 'block notice');", "Spam block");
mw.util.addPortletLink("p-block", "javascript:userWarning('uw-ublock|sig=yes', 'block notice');", "Username block");
mw.util.addPortletLink("p-block", "javascript:userWarning('uw-softerblock|sig=yes', 'block notice');", "Softer block");
mw.util.addPortletLink("p-block", "javascript:userWarning('uw-uhblock|sig=yes', 'block notice');", "Hard block");
mw.util.addPortletLink("p-block", "javascript:userWarning('uw-soablock|sig=yes', 'block notice');", "Spam-only block");
mw.util.addPortletLink("p-block", "javascript:userWarning('uw-vaublock|sig=yes', 'block notice');", "Vandal-only username block");
mw.util.addPortletLink("p-block", "javascript:userWarning('uw-ipevadeblock|sig=yes', 'block notice');", "IP evade block");
document.getElementById('p-block').getElementsByTagName('div')[0].style.display = 'block';
}
// Sockpuppet tagging.
else if (pageTitle.match(/(Editing|Creating) User:/)) {
addBlockToolbox("Sock tag");
mw.util.addPortletLink("p-block", "javascript:userpageTag('sockpuppeteer|blocked', 'sockpuppeteer tag', null);", "Master");
mw.util.addPortletLink("p-block", "javascript:userpageTag('sockpuppeteer|blocked|checked=yes', 'sockpuppeteer tag', null);", "Master (confirmed)");
mw.util.addPortletLink("p-block", "javascript:userpageTag('sockpuppet||blocked', 'sock tag', 13);", "Sock");
mw.util.addPortletLink("p-block", "javascript:userpageTag('sockpuppet||confirmed', 'confirmed sock', 13);", "Sock (confirmed)");
document.getElementById('p-block').getElementsByTagName('div')[0].style.display = 'block';
}
// Automatic sock category creation.
var pattern = /Creating Category:(Suspected )?Wikipedia sockpuppets of (.*)/
var match = pageTitle.match(pattern);
if(match)
{
var form = document.editform;
var textBox = form.wpTextbox1;
textBox.value = '{{sockpuppet category|' + match[2] + '}}';
form.wpSummary.value = 'create sock category';
form.wpWatchthis.checked = false;
}
});
// </nowiki>