Jump to content

User:Pb30/Delsort tab/delsort.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.
<!-- Begin deletion-sorting code --> 

// Sources: [[User:RandyWang/autovgdeletion]], [[Wikipedia:WikiProject User scripts/Scripts/Add tab]], [[Wikipedia:WikiProject User scripts/Scripts/Add LI link]], [[User:Raylu|raylu]]
// This script adds a "afd sort" tab to the top of article pages
// when in edit mode. It is enabled for only the Wikipedia namespace.

function dodeletion() {
      var type = prompt("Enter category");
      if (type == null)
        return;
  document.editform.wpTextbox1.value = document.editform.wpTextbox1.value + '\n*{' + '{' + 'subst' + ':' + 'delsort' + '|' + type + '}' + '}' + ' ' + '--' + ' ' + '~' + '~' + '~' + '~';
  document.editform.wpSummary.value = 'Tagged as [[Wikipedia:WikiProject_Deletion_sorting/' + type + '|' + type + '-related deletion]] for [[WP:DELSORT]]';
  document.editform.wpMinoredit.checked = true;
window.open( mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?action=edit&title=Wikipedia:WikiProject_Deletion_sorting/' + type, 'delsorttab', 'location=no,toolbar=no,status=no,directories=no,scrollbars=yes,width=1000,height=800' );
}

function adddeletion() {
  addTab("javascript:dodeletion()", "afd sort", "ca-Xdeletion", "X Deletion", "");
  akeytt();
}

addOnloadHook(function() {
  if (document.title.indexOf("Wikipedia:") == -1) {
     return;
  }
  if (document.title.indexOf("Editing ") != -1) {
  addOnloadHook(adddeletion);
  }
});

function addTab(url, name, id, title, key){
    var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
    return addlilink(tabs, url, name, id, title, key)
};

function addlilink(tabs, url, name, id, title, key){
    var na = document.createElement('a');
    na.href = url;
    na.appendChild(document.createTextNode(name));
    var li = document.createElement('li');
    if(id) li.id = id;
    li.appendChild(na);
    tabs.appendChild(li);
    if(id)
    {
        if(key && title)
        {
            ta[id] = [key, title];
        }
        else if(key)
        {
            ta[id] = [key, ''];
        }
        else if(title)
        {
            ta[id] = ['', title];
        }
    }
    // re-render the title and accesskeys from existing code in wikibits.js
    akeytt();
    return li;
}