User:Tony Sidaway/standard.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>
function addlink(url, name)
{
  var na = document.createElement('a');
  na.setAttribute('href', '/wiki/' + url);

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

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

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

function closevfd(bold, notbold, discuss)
{
  var txt = document.editform.wpTextbox1;
  txt.value = "{{" + "subst:vt}} '''" + bold + "'''" + notbold + discuss + ".  ~~" + "~~\n" + txt.value + "\n{{" + "subst:vb}}\n";
  txt = document.editform.wpSummary;
  txt.value = "close discussion: " + bold + notbold;
}

function replace()
{
  var s = prompt("Search regexp?");
  if (s)
    {
      var r = prompt("Replace regexp?");
      var txt = document.editform.wpTextbox1;
      txt.value = txt.value.replace(new RegExp(s, "g"), r);
    }
}

function vfdresult()
{
  var txt = document.editform.wpSummary;
  txt.value = "Vfd result";
  txt = document.editform.wpTextbox1;
  if (txt.value.length > 0)
    txt.value += '\n';
  txt.value += "==Vfd==\nOn 2005, this article was nominated for deletion.  The result was .  See [[Wikipedia:Votes for deletion/{{" +
               "subst:PAGENAME}}]] for a record of the discussion. ~~" + "~~";
  txt.focus();
}

function morelinks()
{
  var table = document.getElementById('topbar').getElementsByTagName('table')[0];
  var tds = table.getElementsByTagName('td');
  var td = tds[1];
  var lks = td.getElementsByTagName('a');
  var a;
  var txt;
  var lk;

  // Add comment link to top
  for (a = 0; a < lks.length; ++a)
    {
      txt = lks[a].childNodes[0].data;
      if (txt == "Edit this page")
	{
	  txt = lks[a].getAttribute('href') + "&section=new";
	  a = lks[a + 1];
	  td.insertBefore(addexplicitlink(txt, "Comment"), a);
	  td.insertBefore(document.createTextNode(' | '), a);
	  break;
	}
    }

  // Add links
  if (document.title.indexOf("Editing Wikipedia:Articles for deletion") != -1)
    {
      td.appendChild(addexplicitlink('javascript:closevfd("keep", "", "")', 'KEEP'));
      td.appendChild(document.createTextNode(' | '));
      td.appendChild(addexplicitlink('javascript:closevfd("merge and redirect", " to [[" + prompt("Merge and redirect to?") + "]]", "")', 'MERGE'));
      td.appendChild(document.createTextNode(' | '));
      td.appendChild(addexplicitlink('javascript:closevfd("redirect", " to [[" + prompt("Redirect to?") + "]]", "")', 'REDIR'));
      td.appendChild(document.createTextNode(' | '));
      td.appendChild(addexplicitlink('javascript:closevfd("transwiki", " to " + prompt("Transwiki to?"), "")', 'TRANS'));
      td.appendChild(document.createTextNode('/'));
      td.appendChild(addexplicitlink('javascript:closevfd("transwiki", " to Wiktionary", "")', 'WIKI'));
      td.appendChild(document.createTextNode(' | '));
      td.appendChild(addexplicitlink('javascript:closevfd("speedy delete", "", "")', 'SPEEDY'));
      td.appendChild(document.createTextNode(' | '));
      td.appendChild(addexplicitlink('javascript:closevfd("no consensus", "", "; thus, the article is kept")', 'NO/C'));
      td.appendChild(document.createTextNode(' | '));
      td.appendChild(addexplicitlink('javascript:closevfd(prompt("Result?"), "", "")', 'MISC'));
    }
  else if (document.title.indexOf("Editing ") != -1)
    {
      td.appendChild(addexplicitlink('javascript:replace()', 'Replace'));
      td.appendChild(document.createTextNode(' | '));
      td.appendChild(addexplicitlink('javascript:vfdresult()', 'VfDRslt'));
    }
  else
    {
      td.appendChild(addlink('Special:Watchlist', 'Watchlist'));
      td.appendChild(document.createTextNode(' | '));
      td.appendChild(addlink('Special:Randompage', 'Random'));
      td.appendChild(document.createTextNode(' | '));
      td.appendChild(addexplicitlink('/w/index.php?title=Special:Contributions&hideminor=0&namespace=&target=Korath&limit=500&offset=0', 'Contribs'));
      td.appendChild(document.createTextNode(' | '));
      td.appendChild(addlink('Special:Specialpages', 'Special'));
      td.appendChild(document.createTextNode(' | '));
      td.appendChild(addlink('Wikipedia:Featured picture candidates', 'FPC'));
      td.appendChild(document.createTextNode(' | '));
      td.appendChild(addlink('Wikipedia:Votes_for_deletion', 'VfD'));
      td.appendChild(document.createTextNode('/'));
      td.appendChild(addlink('Wikipedia:Votes_for_deletion/Log/Today', 'Today'));
    }

  // Remove logo
  td = tds[0];
  a = td.getElementsByTagName('a')[0];
  txt = a.getElementsByTagName('img')[0];
  a.removeChild(txt);
}

// Change section links in vfd log pages to edit the entire subpage, instead of its section
function vfdsectionlinks()
{
  var divs = document.getElementsByTagName("div");
  var a;
  var url;
  var pos;
  for (var x = 0; x < divs.length; ++x)
    if (divs[x].className == "editsection")
      {
        a = divs[x].getElementsByTagName('a')[0];
        url = a.getAttribute('href');
        pos = url.indexOf("action=edit&section=");
        if (pos != -1)
          {
            url = url.substring(0, pos + 11);
            a.setAttribute('href', url);
          }
      }
}

function do_onload()
{
  morelinks();
  if (document.title.indexOf("Wikipedia:Articles for deletion/Log/2") != -1)
    vfdsectionlinks();
}

if (window.addEventListener) 
  window.addEventListener("load", do_onload, false);
else if (window.attachEvent) 
  window.attachEvent("onload", do_onload);

function hide_spoilerbox(num)
{
  document.getElementById("spoilercontents_" + num).style.display="none";
  var lk = document.getElementById("spoilerlk_" + num);
  lk.replaceChild(document.createTextNode("show"), lk.firstChild);
  lk.setAttribute("href", "javascript:show_spoilerbox(" + num + ")");
}

function show_spoilerbox(num)
{
  document.getElementById("spoilercontents_" + num).style.display="";
  var lk = document.getElementById("spoilerlk_" + num);
  lk.replaceChild(document.createTextNode("hide"), lk.firstChild);
  lk.setAttribute("href", "javascript:hide_spoilerbox(" + num + ")");
}

function setup_spoilerbox(initial)
{
  var divs = document.getElementsByTagName("div");
  var box;
  var contents;
  var lk;
  var txt;
  if (divs && document.getElementById)
    for (var x = 0; x < divs.length; ++x)
      if (divs[x].className.indexOf("spoilerbox") != -1)
	{
	  box = divs[x].getElementsByTagName("table")[0].getElementsByTagName("tr");
	  contents = box[1];
	  contents.id = "spoilercontents_" + x;
	  box = box[0].getElementsByTagName("td")[0].getElementsByTagName("div")[0];
	  var lk = document.createElement('a');
	  if (initial)
	    {
	      lk.setAttribute("href", "javascript:hide_spoilerbox(" + x + ")");
	      lk.appendChild(document.createTextNode("hide"));
	    }
	  else
	    {
	      lk.setAttribute("href", "javascript:show_spoilerbox(" + x + ")");
	      lk.appendChild(document.createTextNode("show"));
	      contents.style.display="none";
	    }
	  lk.id = "spoilerlk_" + x;
	  box.appendChild(document.createTextNode(" ["));
	  box.appendChild(lk);
	  box.appendChild(document.createTextNode("]"));
	}
}

function load_spoilerbox()
{
  // use setup_spoilerbox(false) instead to hide spoiler boxes by default
  setup_spoilerbox(true);
}

if (window.addEventListener) 
  window.addEventListener("load", load_spoilerbox, false);
else if (window.attachEvent) 
  window.attachEvent("onload", load_spoilerbox);
// </nowiki>