User:Random832/monobook.js
From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Firefox/Mozilla/Safari: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Internet Explorer: press Ctrl-F5, Opera/Konqueror: press F5.
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.
var pageIsDiscussion = false; var pageParams = new Array(); function $(id) { return document.getElementById(id) } var ø = { makeText: function(text) { return document.createTextNode(text); }, createTag: function(tagName) { var elem = document.createElement(tagName); for(var i=1;i<arguments.length;i++) { var x = arguments[i]; if(typeof(x) == "string") x = ø.makeText(x); elem.appendChild(x); } return elem; }, } addOnloadHook(function() { var query = document.URL.replace(/.*\?/,'').split(/[;&]/); if(wgNamespaceNumber == 4) { if(wgPageName.indexOf("noticeboard") > 0) { pageIsDiscussion = true; return 0; } if(wgPageName.indexOf("Village_pump") > 0) { pageIsDiscussion = true; return 0; } if(wgPageName.indexOf("_for_deletion/") > 0) { pageIsDiscussion = true; return 0; } if(wgPageName.indexOf("_for_discussion/") > 0) { pageIsDiscussion = true; return 0; } if(wgPageName.indexOf("Requests_for_comment/User_names") > 0) { pageIsDiscussion = true; return 0; } } }); // Add symbols to not-votes. importScript('User:Ais523/votesymbols.js'); // Fix fact template to be less obtrusive addOnloadHook(function () { var allspans = document.getElementsByTagName("span") for(var i=0;i<allspans.length;i++) if(allspans[i].textContent == "citation needed") allspans[i].textContent = "cn"; }); // Magically link soft redirects addOnloadHook(function () { var theSpan = $('SoftRedirect'); if (!theSpan) return; var message = document.createTextNode(" Redirecting in 5 seconds."); theSpan.appendChild(message); if(theSpan.getElementsByTagName("a")[0]) { var anchor = theSpan.getElementsByTagName("a")[0]; setTimeout("location.href = '" + anchor.href + "'",5000); } }); // This will add an [edit] link at the top of all pages except for // preview pages and the main page // by User:Pile0nades addOnloadHook(function () { // if this is preview page or generated page, stop /* if( $("wikiPreview") || $("histlegend?") || $("difference?") || $("watchdetails") || $("ca-viewsource") || window.location.href.indexOf("/wiki/Special:") != -1 ) { if(window.location.href.indexOf("&action=edit§ion=0") != -1) { $("wpSummary").value = "/* Intro *"+"/ "; } return; };*/ var mk=ø.createTag; // get the page title var pageTitle = wgPageName; // create div and set innerHTML to link var link; var div = mk('DIV','[',link=mk('A','edit intro'),']') link.title = 'Edit section: '+pageTitle; link.href = '/w/index.php?title='+pageTitle+'&action=edit§ion=0' div.className= 'editsection'; // insert divContainer into the DOM below the h1 if(window.location.href.indexOf("&action=edit") == -1) { $("content").insertBefore(div,document.getElementsByTagName("h1")[0]); } }); // Add a "purge" tab addOnloadHook(function() { ta['ca-purge'] = ['g', 'Purge the internal cache for this page']; var x = $('ca-history'); if(!x) return; if(x.children) x = x.children[0]; else x = x.childNodes[0]; addPortletLink("p-cactions", x.href.replace(/=history/, "=purge"), 'purge', 'ca-purge'); }); // Add an element containing the UTC timestamp addOnloadHook(function() { var div = document.createElement('div'); div.id = "utcdate"; var mytext = document.createTextNode('') document.body.appendChild(div); div.appendChild(mytext); setInterval(function () { var now = new Date(); mytext.nodeValue = [ now.getUTCHours(), ":", function(x){return x>9?x:'0'+x}(now.getUTCMinutes()), ", ", ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"][now.getUTCMonth()], " ", now.getUTCFullYear(), " (UTC)" ].join('') }, 1000); }); // Move the "watch" and "move" tabs to the toolbox addOnloadHook(function() { x = $("ca-watch"); if (!x) x = $("ca-unwatch"); if (x) { var tb = $('p-tb').getElementsByTagName('ul')[0]; tb.appendChild(x); x.id = "t-"+x.id; x.firstChild.firstChild.nodeValue+= " this page"; } x = $("ca-move"); if(x) { var tb = $('p-tb').getElementsByTagName('ul')[0]; tb.appendChild(x); x.id = "t-"+x.id; x.firstChild.firstChild.nodeValue+= " this page"; } }); addOnloadHook(function() { /* (portlet, href, text, id, tooltip, accesskey, nextnode) */ addPortletLink("p-navigation", "/wiki/WP:ANI", "Incidents Noticeboard", "n-WPANI", "Administrators' Noticeboard/Incidents", "", "n-portal"); addPortletLink("p-navigation", "/wiki/Special:Newpages", "New Pages", "n-newpages", "New Pages", "", "n-recentchanges"); }); /* testing */ addOnloadHook(function() { var block = false; if (document.URL.lastIndexOf("&action=edit") != -1) { if( wgTitle == "Like this one") { block = true; } } if (document.URL.lastIndexOf("&bypassblock=true") != -1) block = false; if(block) { $("content").innerHTML = '<'+'h1 class="firstHeading">A Friendly Reminder<'+'/h1><'+'div id="bodyContent"><'+'p>You have agreed to voluntarily limit yourself from performing the action at this page. You can bypass the block, but be aware that your contributions and logs are likely to be closely watched for such activity.<'+'/p><'+'/div>'; $("p-cactions").innerHTML = '<'+'ul><'+'li><'+'a href="'+document.URL+'&bypassblock=true">Bypass<'+'/a>' } }); addOnloadHook(function() { var pres = document.getElementsByTagName("PRE"); var mynode = document.createElement("a"); mynode.style.display = "block"; mynode.style.textAlign = "right"; mynode.style.float = "right"; //yeah, it's a cheat. I don't have the patience for text nodes. mynode.textContent="[wrap]"; for(var i=0;i<pres.length;i++) { var tmp = mynode.cloneNode(true); tmp.onclick = (function (e) { var thislink; var thepre; if (!e) e = window.event; if (e.target) thislink = e.target else if (e.srcElement) thislink = e.srcElement; if (thislink.nodeType == 3) // defeat Safari bug thislink = curobj.parentNode; thepre = thislink.parentNode; if(thepre.style.whiteSpace == "pre") { // todo handle -o-pre-wrap, pre-wrap thepre.style.whiteSpace = '-moz-pre-wrap' thislink.textContent = "[unwrap]" } else { thepre.style.whiteSpace = 'pre'; thislink.textContent = "[wrap]" } }); pres[i].insertBefore(tmp,pres[i].firstChild); } }); // Vaguely based on User:Lupin/summarynag.js, heavily reworked addOnloadHook(function () { if(!($("editform"))) return; $("editform").addEventListener("submit",(function (ev) { var summary = document.getElementsByName('wpSummary'); var submit = true; if (summary.length > 0) { summary = summary[0]; if (RegExp('^ *$|^/[*].*?[*]/ *$').test(summary.value)) { var newSummary = prompt("Enter an edit summary."); if(newSummary != null) summary.value += newSummary; else submit = false; } } if(submit && pageIsDiscussion) { /* is a talk page or other discussion. see above for pageIsDiscussion variable */ var editbox = $("wpTextbox1") if(editbox.value.indexOf('~~'+'~~') == -1) { submit = confirm("Are you sure you want to submit this edit to a discussion page without a signature?") } } if(!submit) ev.preventDefault(); return submit; }),"false"); }); addOnloadHook(function () { var theList = "Wikipedia:Village_pump_(policy) Wikipedia:Village_pump_(news) Wikipedia:Village_pump_(technical) Wikipedia:Village_pump_(proposals) Wikipedia:Village_pump_(assistance) Wikipedia:Village_pump_(miscellaneous) Wikipedia:Community_noticeboard Wikipedia:Administrators'_noticeboard Wikipedia:Administrators'_noticeboard/Incidents Wikipedia:Sandbox"; if(theList.indexOf(wgPageName.replace(/_talk/,"")) != -1) { var wt = document.getElementsByName('wpWatchthis'); if(wt.length > 0) { wt = wt[0]; wt.checked = false; } } }); // soft hyphen workaround. For long words. addOnloadHook(function () { var allspans = document.getElementsByTagName("span") for(var i=0;i<allspans.length;i++) if(allspans[i].className == "soft-hyphens") { allspans[i].innerHTML = allspans[i].innerHTML.replace(/\u00AD/g,"<span class='_shy'>-<wbr/></span>"); } }); addOnloadHook(function () { function interpose(elem,newelem,inside) { if(inside) { while(elem.firstChild) newelem.appendChild(elem.firstChild); elem.appendChild(newelem) } else { elem.parentNode.insertBefore(newelem,elem); newelem.appendChild(elem) } } document.write("<style type='text/css'>.xdiff-col { overflow: auto }</style>"); var diffSigns = new Array(); var tables = document.getElementsByTagName('table'); for (var i = 0; i < tables.length; i++) { if (tables[i].className != 'diff') continue; var difftab = tables[i]; for(var i=2;i<difftab.rows.length;i++) { var y = difftab.rows[i]; for(var j=0;j<y.cells.length;j++) { var x = y.cells[j] if(x.className != "diff-context" && x.className != "diff-addedline" && x.className != "diff-deletedline") continue; var div = document.createElement("DIV"); div.style.overflow = 'auto'; interpose(x,div,true) } } } }); addOnloadHook(function () { function iter(a,f){for(var i=0;i<a.length;i++)f(a[i])} function stCap(strObj){ return(strObj.charAt(0).toUpperCase()+strObj.substr(1).toLowerCase()); } function normalize(s) { if(!s.length) return s; var x = s.replace(/_/g," ") var dots = x.indexOf(':') if(dots != -1) x = stCap(x.substring(0,dots))+':'+stCap(x.substring(dots+1)); else x = stCap(x); return x; } function mk(t,c){var x=document.createElement(t);x.appendChild(document.createTextNode(c));} function eq(a,b) { return (normalize(a) == normalize(b)) } iter($('bodyContent').getElementsByTagName('A'), function(x) { var left = '[[', right = ']]', doit = false if(/\bexternal\b/.test(x.className)) { if(x.textContent == x.href) return; left = '['+x.href+' '; right=']' doit = true; } else { if(x.title) { var tx = x.textContent; var ln = x.title + x.hash; var pt = -1; if(!x.hash) { var p1 = /(.+) \(.*\)/; // [[page (context)|page]] var p3 = /([A-Za-z _]+):(.+)/; // [[namespace:page|page]] var p4 = /([A-Aa-z _]+):(.+) \(.*\)/; // [[ns:page (cont)|page]] var pt = ln pt = pt.replace(p4,'$2'); pt = pt.replace(p1,'$1'); pt = pt.replace(p3,'$2'); } if (!eq(ln,tx)) { if(tx == pt) { left = '[['+ln.substring(0,ln.indexOf(tx)) right = ln.substring(ln.indexOf(tx)+tx.length)+'|]]' } else { left = '[['+ln+'|'; right=']]'; } } else { left = '[['; right = ']]'; } doit = true; } } if(doit) { x.innerHTML = "<span style='display:none'>"+left+"</span>"+x.innerHTML+"<span style='display:none'>"+right+"</span>" } }); }); if(location.host == 'secure.wikimedia.org') { addOnloadHook(function () { for(var i=0;i<document.links.length;i++) { var fixed = document.links[i].href .replace(/^http:\/\/en.(wikipedia|wiktionary|wikiquote|wikisource).org\//,"https://secure.wikimedia.org/$1/en/") .replace(/^http:\/\/(en|fr|de).wikipedia.org\//,"https://secure.wikimedia.org/$1/en/") .replace(/^http:\/\/(meta|commons).wikimedia.org\//,"https://secure.wikimedia.org/wikipedia/$1/") if(document.links[i].href != fixed) document.links[i].href = fixed; } }); }