User:King of Hearts/monobook.js

From Wikipedia, the free encyclopedia

Note: After saving, you have to bypass your browser's cache to see the changes. Firefox/Mozilla/Safari: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Internet Explorer: press Ctrl-F5, Opera/Konqueror: press F5.

If a message on your talk page led you here, please be wary of who left it. The code below could contain malicious content capable of compromising your account; if your account appears to be compromised, it will be blocked. If you are unsure whether the code is safe, you can ask at the appropriate village pump.
//

function addLink(where, url, name, id, title, key, after){
    //* where is the id of the toolbar where the button should be added;
    //   i.e. one of "p-cactions", "p-personal", "p-navigation", or "p-tb".
    //
    //* url is the URL which will be called when the button is clicked.
    //   javascript: urls can be used to do more complex things.
    //
    //* name is what will appear as the name of the button.
    //
    //* id is the id of the button; it's best to define one.  
    //   Use a prefix to make sure its unique. Optional.
    //
    //* title is the tooltip title that gives a longer description 
    //   of the button; if you define a accesskey, mention it here. Optional.
    //
    //* key is the char you want for the accesskey. Optional.
    //
    //* after is the id of the button you want to follow this one. Optional.
    //
    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);
    var tabs = document.getElementById(where).getElementsByTagName('ul')[0];
    if(after) {
        tabs.insertBefore(li,document.getElementById(after));
    } else {
        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;
}
    
// 

//this helps automate AfD closing by adding a 'close' tab to AfD debates
//written by [[User:Johnleemk]] based on [[Wikipedia:WikiProject User scripts/Scripts/test-n.js]] by [[User:Celestianpower]]

function autoafd_result()
{
  var close = prompt("Result of debate?")
  var f = document.editform, t = f.wpTextbox1;
  t.value = "{{subst:" + "at" + "}} '''" + close + "'''. " + "~" + "~" + "~" + "~" + '\n' + '\n' + t.value;
  if (t.value.length > 0)
    t.value += '\n';
  t.value += "{{subst:" + "ab" + "}}";
  f.wpSummary.value = "Closing debate; result was " + close;
}

function autoafd_relist()
{
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
    t.value += '\n';
  t.value += "{{subst:" + "relist" + "|~" + "~" + "~" + "~}}";
  f.wpSummary.value = "Relisting debate";
}

function autoafd_keep()
{
  var date = prompt("Nomination was made when?")
  var votepage = prompt("Vote page is? (Enter 'd' for default.)")
  var f = document.editform, t = f.wpTextbox1;

    // If default votepage...
    if (votepage=="d")
      {
        var temp = document.editform.action.split("/w/index.php?title=");
        var temp = temp[1].split("&action=submit");
        var temp = temp[0].substring(5);
        var votepage = temp;
      }

  t.value = "{{" + "oldafdfull" + "|date=" + date + "|votepage=" + votepage + "}}" + '\n' + '\n' + t.value;
  f.wpSummary.value = "Article survived AfD";
}

function autoafd_no_consensus()
{
  var date = prompt("Nomination was made when?")
  var votepage = prompt("Vote page is? (Enter 'd' for default.)")
  var f = document.editform, t = f.wpTextbox1;

    // If default votepage...
    if (votepage=="d")
      {
        var temp = document.editform.action.split("/w/index.php?title=");
        var temp = temp[1].split("&action=submit");
        var temp = temp[0].substring(5);
        var votepage = temp;
      }

  t.value = "{{" + "oldafdfull" + "|date=" + date + "|result='''no consensus'''|votepage=" + votepage + "}}" + '\n' + '\n' + t.value;
  f.wpSummary.value = "Article survived AfD with no consensus";
}

function autoafd_redirect()
{
  var date = prompt("Nomination was made when?")
  var redirect = prompt("Redirect to?")
  var votepage = prompt("Vote page is? (Enter 'd' for default.)")
  var f = document.editform, t = f.wpTextbox1;

    // If default votepage...
    if (votepage=="d")
      {
        var temp = document.editform.action.split("/w/index.php?title=");
        var temp = temp[1].split("&action=submit");
        var temp = temp[0].substring(5);
        var votepage = temp;
      }

  t.value = "{{" + "oldafdfull" + "|date=" + date + "|result='''redirect to [[" + redirect + "]]'''|votepage=" + votepage + "}}" + '\n' + '\n' + t.value;
  f.wpSummary.value = "Article redirected to [[" + redirect + "]] as per AfD";
}

function autoafd_merge()
{
  var date = prompt("Nomination was made when?")
  var redirect = prompt("Merge and redirect to?")
  var votepage = prompt("Vote page is? (Enter 'd' for default.)")
  var f = document.editform, t = f.wpTextbox1;

    // If default votepage...
    if (votepage=="d")
      {
        var temp = document.editform.action.split("/w/index.php?title=");
        var temp = temp[1].split("&action=submit");
        var temp = temp[0].substring(5);
        var votepage = temp;
      }

  t.value = "{{" + "oldafdfull" + "|date=" + date + "|result='''merge and redirect to [[" + redirect + "]]'''|votepage=" + votepage + "}}" + '\n' + '\n' + t.value;
  f.wpSummary.value = "Article merged and redirected to [[" + redirect + "]] as per AfD";
}

function autoafd_other()
{
  var date = prompt("Nomination was made when?")
  var result = prompt("Result was?")
  var votepage = prompt("Vote page is? (Enter 'd' for default.)")
  var f = document.editform, t = f.wpTextbox1;

    // If default votepage...
    if (votepage=="d")
      {
        var temp = document.editform.action.split("/w/index.php?title=");
        var temp = temp[1].split("&action=submit");
        var temp = temp[0].substring(5);
        var votepage = temp;
      }

  t.value = "{{" + "oldafdfull" + "|date=" + date + "|result='''" + result + "'''|votepage=" + votepage + "}}" + '\n' + '\n' + t.value;
  f.wpSummary.value = "AfDed; result was " + result;
}

function autoafd_add_afd_tabs()
{
  // Only add for pages with the right string somewhere in the title
  if (document.title.indexOf("Editing Wikipedia:Articles for deletion/") != -1)
    {
      addLink('p-cactions', 'javascript:autoafd_result()', "close");
      addLink('p-cactions', 'javascript:autoafd_relist()', "relist");
    }
  if (document.title.indexOf("Editing Talk:") != -1)
    {
      addLink('p-cactions', 'javascript:autoafd_keep()', "keep");
      addLink('p-cactions', 'javascript:autoafd_no_consensus()', "no consensus");
      addLink('p-cactions', 'javascript:autoafd_redirect()', "redirect");
      addLink('p-cactions', 'javascript:autoafd_merge()', "merge");
      addLink('p-cactions', 'javascript:autoafd_other()', "other");
    }
}

addOnloadHook(autoafd_add_afd_tabs);

//end AfD closing script

//test-enhanced

function tnaddlilink(url, name)
{
 var na = document.createElement('a');
 na.setAttribute('href', url);

 var txt = document.createTextNode(name);
 na.appendChild(txt);

 var li = document.createElement('li');
 li.appendChild(na);
 return li;
}
 
function testn(number)
{
 var page = prompt("Vandalism to which article?")
 var f = document.editform, t = f.wpTextbox1;
 if (t.value.length > 0)
   t.value += '\n';
 t.value += "{{subst:" + number + "-n|" + page + "}} ~" + "~" + "~" + "~";
 f.wpSummary.value = "Vandalism to " + page + " - warning " + number;
 f.submit();
}

function wA() {
 var f = document.editform, t = f.wpTextbox1;
 if (t.value.length > 0)
   t.value += '\n';
 t.value += "{{subst:" + "welcome-anon-from|King of Hearts" + "}} ~" + "~" + "~" + "~";
 f.wpSummary.value = "Welcome to Wikipedia!";
 f.submit();
}

function wap() {
 var f = document.editform, t = f.wpTextbox1;
 if (t.value.length > 0)
   t.value += '\n';
 t.value += "{{subst:" + "User:Where/pwelcome" + "}} ~" + "~" + "~" + "~";
 f.wpSummary.value = "Use preview; also, welcome!";
 f.submit();
}


function es() {
 var f = document.editform, t = f.wpTextbox1;
 if (t.value.length > 0)
   t.value += '\n';
 t.value += "==Edit summaries==\n{{subst:" + "Edit summary" + "}} ~" + "~" + "~" + "~";
 f.wpSummary.value = "Please use edit summaries";
 f.submit();
}

function add_testn_tabs()
{
 var c1 = document.getElementById('column-one');
 var tabs = c1.getElementsByTagName('div')[0].getElementsByTagName('ul')[0];

 // Only add for pages with "Editing User talk:" somewhere in the title
 if (document.title.indexOf("Editing User talk:") != -1)
   {
     tabs.appendChild(tnaddlilink('javascript:es()', "ES"));
     tabs.appendChild(tnaddlilink('javascript:testn("test1")',"t1"));
     tabs.appendChild(tnaddlilink('javascript:testn("test1a")',"t1a"));
     tabs.appendChild(tnaddlilink('javascript:testn("test-self")',"t-s"));
     tabs.appendChild(tnaddlilink('javascript:testn("test2")',"t2"));
     tabs.appendChild(tnaddlilink('javascript:testn("test2a")',"t2a"));
     tabs.appendChild(tnaddlilink('javascript:testn("test3")',"t3"));
     tabs.appendChild(tnaddlilink('javascript:testn("test3a")',"t3a"));
     tabs.appendChild(tnaddlilink('javascript:testn("bv")',"bv"));
     tabs.appendChild(tnaddlilink('javascript:testn("test4")',"t4"));
     tabs.appendChild(tnaddlilink('javascript:testn("test4a")',"t4a"));
     tabs.appendChild(tnaddlilink('javascript:testn("test5")',"t5"));
     tabs.appendChild(tnaddlilink('javascript:testn("obscene")',"o"));
     tabs.appendChild(tnaddlilink('javascript:testn("joke")',"j"));
     tabs.appendChild(tnaddlilink('javascript:testn("welcomenpov")',"w-N"));
     tabs.appendChild(tnaddlilink('javascript:wA()',"w-A"));
     tabs.appendChild(tnaddlilink('javascript:wap()',"w-A-p"));
}}

addOnloadHook(add_testn_tabs);

//

/* disable Wikipedia access keys/keyboard shortcuts */
ta['pt-login'] = new Array('','You are encouraged to log in, it is not mandatory however.');
ta['pt-logout'] = new Array('','Log out');