User:IronChris/monobook.js
From Wikipedia, the free encyclopedia
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.
Note: After saving, you have to bypass your browser's cache to see the changes. In Internet Explorer and Firefox, hold down the Ctrl key and click the Refresh or Reload button. Opera users have to clear their caches through Tools→Preferences, see the instructions for Opera. Konqueror and Safari users can just click the Reload button.
// [[User:Lupin/popups.js]] document.write('<script type="text/javascript" src="' + 'http://en.wikipedia.org/w/index.php?title=User:Lupin/popups.js' + '&action=raw&ctype=text/javascript&dontcountme=s"></script>'); document.write('<script type="text/javascript" src="' + 'http://en.wikipedia.org/w/index.php?title=User:Interiot/Tool2/code.js' + '&action=raw&ctype=text/javascript&dontcountme=s"></script>'); // // Edit tools for the vandal whack-a-mole game // [[User:Kbh3rd/whackamole.js]] - please include this line // document.write('<script type="text/javascript" src="' + 'http://en.wikipedia.org/w/index.php?title=User:Kbh3rd/whackamole.js' + '&action=raw&ctype=text/javascript&dontcountme=s"></script>'); 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; } // // function addTab(url, name, id, title, key){ var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0]; return addlilink(tabs, url, name, id, title, key); } // function format() { var txt = document.editform.wpTextbox1; txt.value = fixheadings(txt.value); txt.value = fixsyntax(txt.value); txt.value = linkfixer(txt.value, false); //txt.value = imagefixer(txt.value); txt.value = whitespace(txt.value); txt.value = linksimplifyer(txt.value); txt.value = trim(txt.value); } function whitespace(str){ str = str.replace(/\t/g, " "); str = str.replace(/^ ? ? \n/gm, "\n"); str = str.replace(/(\n\n)\n+/g, "$1"); str = str.replace(/== ? ?\n\n==/g, "==\n=="); str = str.replace(/\n\n(\* ?\[?http)/g, "\n$1"); str = str.replace(/^ ? ? \n/gm, "\n"); str = str.replace(/\n\n\*/g, "\n*"); str = str.replace(/[ \t][ \t]+/g, " "); str = str.replace(/([=\n]\n)\n+/g, "$1"); str = str.replace(/ \n/g, "\n"); return trim(str); } //Fix ==See also== and similar section common errors. function fixheadings(str) { if( !str.match(/= ?See also ?=/) ) str = str.replace(/(== ?)(see also:?|related topics:?|related articles:?|internal links:?|also see:?)( ?==)/gi, "$1See also$3"); str = str.replace(/(== ?)(external links:?|outside links|web ?links:?|exterior links:?)( ?==)/gi, "$1External links$3"); str = str.replace(/(== ?)(external link:?|web ?link:?|exterior link:?)( ?==)/gi, "$1External link$3"); str = str.replace(/(== ?)(reference:?)(s? ?==)/gi, "$1Reference$3"); str = str.replace(/(== ?)(source:?)(s? ?==)/gi, "$1Source$3"); str = str.replace(/(== ?)(further readings?:?)( ?==)/gi, "$1Further reading$3"); return str; } //fixes many common syntax problems function fixsyntax(str) { //replace html with wiki syntax if( !str.match(/'<\/?[ib]>|<\/?[ib]>'/gi) ) { str = str.replace(/<i>(.*?)<\/i>/gi, "''$1''"); str = str.replace(/<b>(.*?)<\/b>/gi, "'''$1'''"); } str = str.replace(/<br\/>/gi, "<br />"); return trim(str); } //formats links in standard fashion function linkfixer(str, checkImages) { str = str.replace(/\]\[/g, "] ["); var m = str.match(/\[?\[[^\]]*?\]\]?/g); if (m) { for (var i = 0; i < m.length; i++) { var x = m[i].toString(); var y = x; if ( y.match(/^\[?\[image:/i) && !checkImages ) break; y = noUnicodify(y); y = y.replace("+", "%2B"); //y = HttpUtility.HtmlDecode(y); //y = HttpUtility.UrlDecode(y); y = unescape(y); //internal links only if ( !y.match(/^\[?\[http:\/\//i) && !y.match(/^\[?\[image:/i) ) { if (y.indexOf(":") == -1 && y.substr(0,3) != "[[_" && y.indexOf("|_") == -1) { if (y.indexOf("|") == -1) y = y.replace(/_/g, " "); else y = y.replace( y.substr(0, y.indexOf("|")), y.substr(0, y.indexOf("|")).replace(/_/g, " ")); } if( y.substr(0, 11) != "[[Category:") y = y.replace(/ ?\| ?/, "|").replace("|]]", "| ]]"); } str = str.replace(x, y); } } //repair bad internal links str = str.replace(/([^\[]|^)\[?\[([^\]]*?)\]\]?([^\]]|$)/gm, "$1[[$2]]$3"); str = str.replace(/\[\[ ?([^\]]*?) ?\]\]/g, "[[$1]]"); str = str.replace(/\[\[([^\]]*?)( |_)#([^\]]*?)\]\]/g, "[[$1#$3]]"); //repair bad external links str = str.replace(/\[?\[http:\/\/([^\]]*?)\]\]?/gi, "[http://$1]"); str = str.replace(/\[http:\/\/([^\]]*?)\|([^\]]*?)\]/gi, "[http://$1 $2]"); return trim(str); } //fixes images function imagefixer(str) { //remove external images str = str.replace(/\[?\[image:http:\/\/([^\]]*?)\]\]?/gi, "[http://$1]"); //fix links within internal images var m = str.match(/\[?\[image:[^\[\]]*?(\[?\[[^\]]*?\]*?[^\[\]]*?)*?\]+/gi); if (m) { for (var i = 0; i < m.length; i++) { var x = m[i].toString(); var y = x; y = y.replace(/^\[\[i/i, "I").replace(/\]\]$/, ""); y = y.replace(/(\[[^\]]*?)$/, "$1]"); y = linkfixer(y, true); y = "[[" + y + "]]"; str = str.replace(x, y); } } return trim(str); } //simplifies some links e.g. [[Dog|dog]] to [[dog]] and [[Dog|dogs]] to [[dog]]s function linksimplifyer(str){ var m = str.match(/\[\[([^[]*?)\|([^[]*?)\]\]/g); if (m) { for (var i = 0; i < m.length; i++) { var n_arr = m[i].toString().match(/\[\[([^[]*?)\|([^[]*?)\]\]/); var n = n_arr[0]; var a = n_arr[1]; var b = n_arr[2]; if (b.indexOf(a) == 0 || b.indexOf(TurnFirstToLower(a)) == 0) { var k = n.replace(/\[\[([^\]\|]*?)\|(\1)([\w]*?)\]\]/i, "[[$2]]$3"); str = str.replace(n, k); } } } str = str.replace(/\[\[([^\]\|]+)\|([^\]\|]+)\]\]([A-Za-z\'][A-Za-z]*)([\.\,\;\:\"\!\?\s\n])/g, "[[$1|$2$3]]$4"); return str; } //trim start and end, trim spaces from the end of lines function trim(str) { str = str.replace(/ $/gm, ""); return str.replace(/^\s*|\s*$/g, ""); } //turns first character to lowercase function TurnFirstToLower(input) { if (input != "") { var input = trim(input); var temp = input.substr(0, 1); return temp.toLowerCase() + input.substr(1, input.length); } else return ""; } addOnloadHook(function () { if(document.forms.editform) { addLink('p-cactions', 'javascript:format()', 'format', 'ca-format', 'Format article', '', 'ca-history'); } }); // function addlilink(tabs, url, name, id, title, key){ 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); 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; } // // STATUS CHANGER addOnloadHook(function (){ var user = document.getElementById( 'pt-userpage' ).firstChild.firstChild.data; var subpage = "/Status"; var scheme = "/StatusTemplate"; var linkprefix = "http://en.wikipedia.org/w/index.php?title=User:"; var contribs = document.getElementById( 'pt-mycontris' ); //Add the links addlilink(contribs, linkprefix+user+subpage+"&action=edit&newstatus=in", "In", "pt-status-in", "I'm in!", ""); addlilink(contribs, linkprefix+user+subpage+"&action=edit&newstatus=busy", "Busy", "pt-status-busy", "I'm busy!", ""); addlilink(contribs, linkprefix+user+subpage+"&action=edit&newstatus=out", "Out", "pt-status-out", "I'm out!", ""); if (location.href.indexOf("User:"+user+subpage+"&action=edit&newstatus=") == -1) return; //Are we here to auto-edit the status? //Get new status status = location.href.split("="); status = status[status.length-1]; //Modify the form document.getElementById('wpTextbox1').value = "{{User:"+user+scheme+"|"+status+"}}"; document.getElementById('wpSummary').value = "Status: "+status; document.getElementById('wpMinoredit').checked = 'checked'; //Submit it! document.getElementById('editform').submit(); }); // //Please leave the following line //user:Where/usertabs addOnloadHook(function() { if (document.title.search("/") != -1 || document.title.search("- History -") != -1) { //no subpages or history return; } if (document.title.indexOf("User:") == 0 || document.title.indexOf("User talk:") == 0) { username_a = document.URL.match(/:.*:(.*)/); username=username_a[1]; addTab("http://en.wikipedia.org/wiki/Special:Contributions/" + username, "contrib", "ca-contrib", "contribs", ""); addTab("http://en.wikipedia.org/w/index.php?title=Special%3ALog&type=move&user=" + username, "page moves", "ca-pagemoves", "page moves", ""); addTab("http://en.wikipedia.org/w/index.php?title=Special%3ALog&type=block&user=" + username, "block log", "ca-blog", "blog", ""); addTab("http://tools.wikimedia.de/~interiot/cgi-bin/count_edits?dbname=enwiki_p&user=" + username, "edit count", "ca-kate", "kate", ""); } }); /**** afd helper ****/ document.write('<script type="text/javascript"' + 'src="http://en.wikipedia.org/w/index.php?title=User:Jnothman/afd_helper/' + 'script.js&action=raw&ctype=text/javascript&dontcountme=s"></script>'); /* This is to keep track of who is using this extension: [[User:Jnothman/afd_helper/script.js]] */ 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|Where" + "}} ~" + "~" + "~" + "~"; 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("test2")',"t2")); tabs.appendChild(tnaddlilink('javascript:testn("test2a")',"t2a")); tabs.appendChild(tnaddlilink('javascript:testn("test3")',"t3")); tabs.appendChild(tnaddlilink('javascript:testn("test4")',"t4")); tabs.appendChild(tnaddlilink('javascript:testn("bv")',"bv")); 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); //<nowiki> Admin-like RC Patrol tools document.write('<script type="text/javascript" src="' + 'http://en.wikipedia.org/w/index.php?title=User:VoA/monobook.js' + '&action=raw&ctype=text/javascript&dontcountme=s"></script>'); //</nowiki>[[Category:Wikipedians who use RC script ]]

