User:Cryptic/transwikifrom.js

Within the framework of User:Cryptic/transwikifrom.js, it is relevant to analyze and understand the different aspects that come together around this topic. From its origins to its influence today, User:Cryptic/transwikifrom.js has been the subject of debate and study in various fields of knowledge. Its impact on society, its relevance in the cultural field and its evolution over time are just some of the dimensions that will be addressed in this article. Likewise, the multiple perspectives and opinions that have emerged around User:Cryptic/transwikifrom.js will be explored, in order to provide a comprehensive and objective view of this issue.
//<pre>
var transwiki_log_location = "Wikibooks:Transwiki log";

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);       // 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; 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').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').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').getElementsByTagName('td').getElementsByTagName('p');

  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');
  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_history()
{
  var txt = document.editform.wpTextbox1;

  // Replace double braces, add a newline at end
  txt.value = txt.value.replace(/{/g, "&#123;") + "\n";
  txt.value = txt.value.replace(/}/g, "&#125;");

  // Find minor edits, and make them regexp-friendly
  txt.value = txt.value.replace(/ m \(/g, " (MINOR");
  txt.value = txt.value.replace(/ m$/gm, " (MINOR)");
  // Find edits without summaries, and make them regexp-friendly
  txt.value = txt.value.replace(new RegExp("()\\r", "gm"), "$1 ()\r");
  // Replace the "(cur) (last)  " at the start of each line with "*" and link user names
  txt.value = txt.value.replace(new RegExp("^\\(cur\\) \\(last\\)  (:, ? * 200) (*) (\\(.*\\))$", "gm"), "*$1 ] $3");
  // Fix minor edits
  txt.value = txt.value.replace(/ \(MINOR/g, " '''m''' (");
  // Fix edits without summaries
  txt.value = txt.value.replace(/ \(\)$/gm, "");
  txt.value = txt.value.replace(new RegExp("^(*) \\((.*)\\)$", "gm"), "$1 ''($2)''");

  // Add header
  var title;
  if (!document.title.match(/Talk:Transwiki:(.*) - (Preview|Edit)/))
    title = prompt("Couldn't find article name.");
  else
    title = RegExp.$1;

  txt.value = "This article was ]ed from ]." + sig() + "\n\nThe history of the article there was:\n" + txt.value;

  // And summary
  document.editform.wpSummary.value = "]ed from ]";
}

function transwiki_summary()
{
  var txt = document.editform.wpTextbox1;

  var title;
  if (!document.title.match(/Editing Transwiki:(.*) - (Preview|Edit)/))
    title = prompt("Couldn't find article name.");
  else
    title = RegExp.$1;

  document.editform.wpSummary.value = "]ed from ]";
}

function transwiki_log(title)
{
  var txt = document.editform.wpTextbox1;
  txt.value += "*] &rarr; ]" + sig();
  document.editform.wpSummary.value = "] transwikied from ]";
}

function onload_transwiki()
{
  if (document.title.indexOf("Editing ") == 0)
    {
      if (document.title.indexOf("Editing Talk:Transwiki:") == 0)
        add_link('javascript:transwiki_history()', 'Wikify History');
      else if (document.title.indexOf("Editing Transwiki:") == 0)
        add_link('javascript:transwiki_summary()', 'Transwiki summary');
      else if (document.title.indexOf("Editing " + transwiki_log_location) == 0)
        add_link('javascript:transwiki_log(prompt("Title?"))', 'Log entry');
    }
  //add_link("https://wikifreehand.com/en/" + transwiki_log_location, '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.
}

$(onload_transwiki);
//</pre>