Jump to content

User:Cryptic/transwiki.js

From Wikipedia, the free encyclopedia

This is the current revision of this page, as edited by Cryptic (talk | contribs) at 20:52, 17 December 2005 (addOnloadHook). The present address (URL) is a permanent link to this version.

(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
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.
//<pre>
function add_link(url, name)
{
  //replace_editing_help(url, name);    // remove the "//" at the start of this line to replace the "editing help" under the edit window with the links
  //before_editbox(url, name);          // remove the "//" at the start of this line to place the links before the editing box

  //the following options are skin-specific.
  //monobook_tab(url, name);            // remove the "//" at the start of this line to place the links in tabs in the monobook skin
  //monobook_toolbox(url, name);        // remove the "//" at the start of this line to place the links in the toolbox in the monobook skin
  //classic_header(url, name);          // remove the "//" at the start of this line to place the links in the header in the classic skin
  //classic_quickbar(url, name);        // remove the "//" at the start of this line to place the links in the quickbar in the classic skin
  //nostalgia_header(url, name);        // remove the "//" at the start of this line to place the links in the header in the nostalgia skin
  //cologneblue_quickbar(url, name);    // remove the "//" at the start of this line to place the links in the quickbar in the cologne blue skin
}

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

  var form = document.editform;
  var x;
  for (x = form.firstChild; x; x = x.nextSibling)
    if (x.tagName == 'BR')
      {
        form.insertBefore(document.createTextNode(' | '), x);
        form.insertBefore(na, x);
        break;
      }
    else if (x.tagName == 'TEXTAREA')
      {
        form.insertBefore(na, x);
        form.insertBefore(document.createElement('br'), x);
        break;
      }
}

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

  var form = document.editform;
  var em = form.getElementsByTagName('em');
  if (em.length > 1)
    form.replaceChild(na, em[1]);       // we haven't yet removed the "editing help" link, so replace it
  else
    {
      // either there's a br and a list of templates, or the editpage-copywarn div
      var x;
      for (x = em[0]; x && x.tagName != "BR" && x.tagName != "DIV"; x = x.nextSibling);
      if (!x)
        { // didn't find anything! so just append
          form.appendChild(document.createTextNode(' | '));
          form.appendChild(na);
        }
      else
        {
          form.insertBefore(document.createTextNode(' | '), x);
          form.insertBefore(na, x);
        }
    }
}

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

  var li = document.createElement('li');
  li.appendChild(na);
  document.getElementById('p-cactions').getElementsByTagName('ul')[0].appendChild(li);
}

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

  var li = document.createElement('li');
  li.appendChild(na);
  document.getElementById('p-tb').getElementsByTagName('ul')[0].appendChild(li);
}

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

  var td = document.getElementById('topbar').getElementsByTagName('table')[0].getElementsByTagName('td')[1].getElementsByTagName('p')[0];

  if (td.hasChildNodes())
    td.appendChild(document.createTextNode(' | '));
  td.appendChild(na);
}

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

  document.getElementById('quickbar').appendChild(na);
}

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

  var bar = document.getElementById('topbar');
  var br = bar.getElementsByTagName('br')[1];
  bar.insertBefore(document.createTextNode(' | '), br);
  bar.insertBefore(na, br);
}

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

  var qb = document.getElementById("quickbar");
  qb.appendChild(na);
  qb.appendChild(document.createElement('br'));
}

function sig()
{
  return ' ~~' + '~~';
}

// End of generic code

function transwiki_log()
{
  var title = prompt("Title?");
  if (title)
    {
      var target = prompt("To project?")
      if (target)
        {
          if (target == "k" || target == "K" || target == "d" || target == "D")
            target = "wikt";
          else if (target == "s" || target == "S")
            target = "wikisource";
          else if (target == "c" || target == "C")
            target = "commons";

          var txt = document.editform.wpTextbox1;
          var vfdd = prompt("Vfd at? (y/Y for [[Wikipedia:Votes for deletion/" + title + "]], or empty for none");
          if (vfdd == "y" || vfdd == "Y")
            vfdd = " ([[Wikipedia:Votes for deletion/" + title + "|VfD]])";
          else if (vfdd == "n" || vfdd == "N" || vfdd == "")
            vfdd = "";
          else
            vfdd = " ([[Wikipedia:Votes for deletion/" + vfdd + "|VfD]])";
          txt.value += "*[[" + title + "]] &rarr; [[" + target + ":Transwiki:" + title + "]]" + sig() + vfdd;
          document.editform.wpSummary.value = "[[" + title + "]] transwikied to [[" + target + ":Transwiki:" + title + "]]" + vfdd;
        }
    }
}

function transwiki_to()
{
  var target = prompt("Transwiki to?\nwiKt/Books/Source/Commons/Meta/Quote");
  if (target == "k" || target == "K" || target == "d" || target == "D")
    target = "en.wiktionary";
  else if (target == "b" || target == "B")
    target = "en.wikibooks";
  else if (target == "s" || target == "S")
    target = "wikisource";
  else if (target == "c" || target == "C")
    target = "commons.wikimedia";
  else if (target == "m" || target == "M")
    target = "meta.wikimedia";
  else if (target == "q" || target == "Q")
    target = "en.wikiquote";
  else
    {
      window.alert("Unknown target.");
      return;
    }

  var url = new String(document.location);
  url = url.replace(/en\.wikipedia/, target);
  url = url.replace(/index\.php\?title=/, "index.php?title=Transwiki:");
  window.location = url;
}

function onload_transwiki()
{
  if (document.title.indexOf("Editing ") == 0)
    {
      if (document.title.indexOf("Editing Wikipedia:Transwiki log") == 0)
        add_link('javascript:transwiki_log()', 'Log entry');
      else
        add_link('javascript:transwiki_to()', 'TranswikiTo');
    }
  //add_link("/wiki/Wikipedia:Transwiki log", 'Transwiki log');       // remove the "//" from the start of this line to add a link to the transwiki log.  You may want to use a specific add_link function instead, e.g. monobook_toolbox, so it doesn't appear in the same place as the editting links.
}

addOnloadHook(onload_transwiki);
//</pre>