User:Cryptic/standard.js

// 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 pipe(td) { td.appendChild(document.createTextNode(' | ')); }

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 t(txt) { return ''; }

function sig { return ' ' + ''; }

function template(tm) { document.editform.wpTextbox1.value = t(tm) + '\n' + document.editform.wpTextbox1.value; document.editform.wpSummary.value = t(tm); }

function user_talk_template(tm, sum) { if (document.editform.wpTextbox1.value.length > 0) document.editform.wpTextbox1.value += '\n'; document.editform.wpTextbox1.value = document.editform.wpTextbox1.value + t(tm) + sig + '\n'; document.editform.wpSummary.value = sum; }

function transwiki_history { var txt = document.editform.wpTextbox1;

// Account for my history-munging javascript at en.wikipedia txt.value = txt.value.replace(/VndTstBlkMsc /g, "");

// 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\\)  ([0-9][0-9]:[0-9][0-9], [0-9][0-9]? [A-Z][a-z]* 200[0-9]) ([^(\\n\\r]*) (\\(.*\\))$", "gm"), "*$1 $2 $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("^([^(\\n\\r]*) \\((.*)\\)$", "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 transwikied from " + title + "." + sig + "\n\nThe history of the article there was:\n" + txt.value;

// And summary document.editform.wpSummary.value = "transwikied from " + title + ""; }

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 = "transwikied from " + title + ""; }

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

function interwiki(lk, td, a, host, abbrev) { host = lk.replace(/source/, host); td.insertBefore(addexplicitlink(host, abbrev), a); if (abbrev == "D" || abbrev == "d") {     td.insertBefore(document.createTextNode('/'), a); td.insertBefore(addexplicitlink(host.toLowerCase, "lc"), a); } td.insertBefore(document.createTextNode(' | '), a); }

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, and replace Main Page with Transwiki log for (a = 0; a < lks.length; ++a) {     txt = lks[a].childNodes[0].data; if (txt == "Main Page") {         lks[a].childNodes[0].data = "TrLog"; lks[a].setAttribute('href', "/w/index.php?title=Wiktionary:Transwiki log/Articles moved to here/staging"); }     else if (txt == "Edit this page") {         txt = lks[a].getAttribute('href'); a = lks[a + 1]; td.insertBefore(addexplicitlink(txt + "&section=new", "Comment"), a); td.insertBefore(document.createTextNode(' | '), a); td.insertBefore(addexplicitlink(txt + "&section=0", "0"), a); td.insertBefore(document.createTextNode(' | '), a); break; }   }

if (document.title.indexOf("User:Cryptic/standard") >= 0) {     a = td.getElementsByTagName('p')[0]; td.insertBefore(document.createTextNode(' | '), a); td.insertBefore(addexplicitlink("/w/index.php?title=User:Cryptic/standard.js&action=raw&ctype=text/javascript", "js"), a); td.insertBefore(document.createTextNode(' | '), a); td.insertBefore(addexplicitlink("/w/index.php?title=User:Cryptic/standard.css&action=raw&ctype=text/css", "css"), a); }

// Remove second line, preserving "Current revision" (on the first line) and // "You have new messages" (replacing (Talk) in upper right) if present td = td.getElementsByTagName('p')[0]; while (td.hasChildNodes) {     lk = td.firstChild; if (lk.nodeName == 'A' && lk.firstChild.data == 'Current revision') {         a = tds[1].getElementsByTagName('p')[0]; tds[1].insertBefore(document.createTextNode(' | '), a); tds[1].insertBefore(lk, a); }     else if (lk.nodeName == 'STRONG' && lk.firstChild.data == 'You have ') {         lks = tds[2].getElementsByTagName('a'); for (a = 0; a < lks.length; ++a) if (lks[a].firstChild.data == 'Talk') {               lks[a].firstChild.data = 'New Messages'; lks[a].setAttribute('style', 'font-style: italic;'); lks[a].setAttribute('href', '/w/index.php?title=User_talk:Cryptic&action=history'); }       }      td.removeChild(td.firstChild); }

// Replace them td.appendChild(addlink('Special:Watchlist', 'Watchlist')); pipe(td); td.appendChild(addlink('Special:Randompage', 'Random')); pipe(td); td.appendChild(addexplicitlink('/w/index.php?title=Special:Contributions&hideminor=0&target=Cryptic&limit=500&offset=0', 'Contribs')); pipe(td); td.appendChild(addlink('Special:Specialpages', 'Special')); pipe(td); td.appendChild(addlink('Wiktionary Appendix:IPA Examples', 'IPA'));

if (document.title.indexOf("Editing ") == 0) {     pipe(td); td.appendChild(addexplicitlink('javascript:replace', 'Replace'));

if (document.title.indexOf("Editing Talk:Transwiki:") == 0) {         pipe(td); td.appendChild(addexplicitlink('javascript:transwiki_history', 'Fixup Transwiki history')); }     else if (document.title.indexOf("Editing Transwiki:") == 0) {         pipe(td); td.appendChild(addexplicitlink('javascript:transwiki_summary', 'Transwiki summary')); }     else if (document.title.indexOf("Editing Wiktionary:Transwiki log") == 0) {         pipe(td); td.appendChild(addexplicitlink('javascript:transwiki_log(prompt("Title?"))', 'Log entry')); }   }

// Interwiki links td = tds[2]; a = td.firstChild; lks = document.getElementsByTagName('a'); for (lk = lks.length - 1; lk >= 0 && lks[lk].firstChild.data != 'What links here'; --lk); if (lk >= 0) {     lk = lks[lk].getAttribute('href'); lk = lk.replace(/en.wiktionary/, "source"); lk = lk.replace(/Special:Whatlinkshere&target=/, ""); interwiki(lk, td, a, "en.wikipedia", "w"); interwiki(lk, td, a, "en.wiktionary", "D"); interwiki(lk, td, a, "en.wikinews", "n"); interwiki(lk, td, a, "en.wikibooks", "b"); interwiki(lk, td, a, "wikisource", "s"); interwiki(lk, td, a, "commons.wikimedia", "c"); interwiki(lk, td, a, "meta.wikimedia", "m"); interwiki(lk, td, a, "en.wikiquote", "q"); } }

function do_onload { morelinks; }

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