Jump to content

User:Jafeluv/blockToolbox.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// <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>