User:Harryboyles/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.
//Wikipedia:WikiProject User scripts/Scripts/Add LI link adds a link function addlilink(node, url, text, id, tooltip, accesskey) { // the code below is mostly copied from addPortletLink() var link = document.createElement( "a" ); link.appendChild( document.createTextNode( text ) ); link.href = href; var item = document.createElement( "li" ); item.appendChild( link ); if ( id ) item.id = id; if ( accesskey ) { link.setAttribute( "accesskey", accesskey ); tooltip += " ["+accesskey+"]"; } if ( tooltip ) { link.setAttribute( "title", tooltip ); } updateTooltipAccessKeys( new Array( link ) ); node.appendChild( item ); return item; } // // [[Wikipedia:WikiProject User scripts/Scripts/Time]] // Adds the date and time in UTC to your monobook "personal menu" list at the very top of the page. // Created by [[User:Mathwiz2020]] // Indicate where you would like the time to appear: // 1 is first (before username), 2 is second (before talk link), ... 7 is last (after log out link) insertBeforeNum = 7; // Do NOT edit below this line unless you're experiened in javascript insertBeforeArr = new Array("","pt-userpage","pt-mytalk","pt-preferences","pt-watchlist","pt-mycontris","pt-logout",""); insertBefore = insertBeforeArr[insertBeforeNum]; function makeTime() { var li = document.createElement( 'li' ); li.id = 'pt-time'; var mySpan = document.createElement( 'span' ); mySpan.appendChild( document.createTextNode( 'date and time' ) ); li.appendChild( mySpan ); if ( insertBefore ) { var before = document.getElementById( insertBefore ); before.appendChild( li, before ); } else // append to end (right) of list { document.getElementById( 'pt-logout' ).parentNode.appendChild( li ); } getTime(); } if ( window.addEventListener ) window.addEventListener ( 'load', makeTime, false ); else if ( window.attachEvent ) window.attachEvent ( 'onload', makeTime ); function getTime() { var time = new Date(); var date = time.getUTCDate(); var months = 'Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'.split(' '); month = months[time.getUTCMonth()]; var year = time.getUTCFullYear(); var hours = '0' + time.getUTCHours(); hours = hours.substr(hours.length-2, hours.length); var minutes = '0' + time.getUTCMinutes(); minutes = minutes.substr(minutes.length-2, minutes.length); var seconds = '0' + time.getUTCSeconds(); seconds = seconds.substr(seconds.length-2, seconds.length); var curTime = hours + ":" + minutes + ":" + seconds + ", " + date + " " + month + " " + year + " (UTC)"; datePlace = document.getElementById('pt-time').childNodes[0].childNodes[0]; datePlace.replaceData(0, datePlace.length, curTime); doTime = window.setTimeout("getTime()", 1000); } // // [[Wikipedia:Tools/Navigation popups]] 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>'); //Adjusts the popup delay popupDelay=1.0; popupHideDelay=0.25; //Popups will not appear in the edit box popupOnEditSelection=false; //Popups won't appear when pointing at a link in a popup popupSubpopups=false; //Adds the ability to fix a link that links to a disambiguation page popupFixDabs=true; //Adjusts the number of contributions shown for a user popupContribsPreviewLimit=15; //[[Wikipedia;WikiProject User scripts/Scripts/Unwatch]] //Adds an unwatch link directly after an entry in the watchlist addOnloadHook(function () { var query_prefix = "title=Special:Watchlist&action=submit&remove=1&id[]="; //var query_prefix = "action=unwatch&title="; if (window.location.href.indexOf("Special:Watchlist") < 0) return; if (window.location.href.indexOf("Special:Watchlist/edit") >= 0) return; var links = document.getElementById('content').getElementsByTagName('a'); for (var i = 0; i < links.length; i++) { if (links[i].href.substring(links[i].href.length-15) != '&action=history') continue; var unwatch = document.createElement('a'); unwatch.href = "/w/index.php?" + query_prefix + encodeURIComponent(links[i].title); unwatch.title = "Unwatch "+links[i].title; unwatch.appendChild(document.createTextNode("unwatch")); links[i].parentNode.insertBefore(unwatch, links[i].nextSibling); // kluge to handle case where "diff" is unlinked: var delim = links[i].previousSibling; delim = (delim.nodeType == 3 ? delim.nodeValue : ""); links[i].parentNode.insertBefore(document.createTextNode(delim.replace(/^.*diff/, "")), unwatch); } }); // // Wikipedia:WikiProject User scripts/Scripts/Add purge to tabs addPurge addOnloadHook(function () { var hist; var url; if (!(hist = document.getElementById('ca-history') )) return; if (!(url = hist.getElementsByTagName('a')[0] )) return; if (!(url = url.href )) return; addPortletLink('p-cactions', url.replace(/([?&]action=)history([&#]|$)/, '$1purge$2'), 'purge', 'ca-purge', 'Purge server cache for this page'); }); // // [[Wikipedia:WikiProject User scripts/Scripts/Logs link]] addOnloadHook(function () { // if this is a user, show the logs for the user rather than the page if ( wgCanonicalNamespace == "User" || wgCanonicalNamespace == "User_talk" ) { url = wgServer + "/w/index.php?title=Special:Log&user=" + wgTitle.split("/")[0]; } else if ( wgCanonicalNamespace == "Special" ) { // don't display link for special pages return; } else { url = wgServer + "/w/index.php?title=Special:Log&page=" + wgPageName; } addPortletLink("p-cactions", url, "Logs", "pt-logs"); }); //If you are not editing a page, a tab will appear allowing you to edit the 0th section of a page //(the top area usually used as an introduction. addOnloadHook(function () { var x; if (!(x = document.getElementById('ca-edit') )) return; var url; if (!(url = x.getElementsByTagName('a')[0] )) return; if (!(url = url.href )) return; var y = addPortletLink('p-cactions', url+"§ion=0", '0', 'ca-edit-0', 'Edit the lead section of this page', '0', x.nextSibling); y.className = x.className; // steal classes from the the edit tab... x.className = 'istalk'; // ...and make the edit tab have no right margin // exception: don't steal the "selected" class unless actually editing section 0: if (/(^| )selected( |$)/.test(y.className)) { if (!document.editform || !document.editform.wpSection || document.editform.wpSection.value != "0") { y.className = y.className.replace(/(^| )selected( |$)/g, "$1"); x.className += ' selected'; } } }); // adds a view source tab to the tab bar addOnloadHook(function () { if (location.href.indexOf('viewsource=1') != -1) { sl = document.getElementById('wpSummaryLabel'); sl.parentNode.removeChild(sl); ed = document.getElementById('wpSummary').parentNode; ed.parentNode.removeChild(ed); return; } editbutton = document.getElementById('ca-edit'); if (editbutton && location.href.indexOf('action=edit')==-1) { editlink = editbutton.getElementsByTagName('a')[0].href + '&viewsource=1'; tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0]; na = document.createElement('a'); na.href = editlink; na.appendChild(document.createTextNode('view source')); li = document.createElement('li'); li.id = 'ca-viewsource'; li.appendChild(na); tabs.insertBefore(li,editbutton); } }); //Adds a link to "Changes since last load" on watchlist addOnloadHook(function () { if (unescape(window.location.href).indexOf("Special:Watchlist") < 0) return; // just one little ID attribute would be _so_ nice... var nsSelectForm = document.getElementById('namespace'); while (nsSelectForm && !(nsSelectForm.tagName && nsSelectForm.tagName.toLowerCase() == 'form')) nsSelectForm = nsSelectForm.parentNode; if (!nsSelectForm) return; var link = document.createElement('a'); link.id = 'listSince'; link.href = '#listSince'; // must have a href to show as link! var then = +(new Date()); var fixLinkHref = function () { var url = window.location.href.split('#')[0]; var days = ( +(new Date()) - then )/(1000 * 3600 * 24); if (url.match(/[?&]days=/)) this.href = url.replace(/([?&]days=)[^&]*/, '$1'+days); else this.href = url + (url.indexOf('?') < 0 ? '?':'&') + 'days=' + days; return true; }; link.onclick = fixLinkHref; link.onmousedown = fixLinkHref; // react to middle clicks too var frag = document.createDocumentFragment(); frag.appendChild(document.createTextNode(' | ')); frag.appendChild(link); link.appendChild(document.createTextNode('Changes')); frag.appendChild(document.createTextNode(' since last load.')); nsSelectForm.parentNode.insertBefore(frag, nsSelectForm); }); // // Script from [[User:Dr pda/articlehistory.js]] document.write('<script type="text/javascript" src="' + 'http://en.wikipedia.org/w/index.php?title=User:Dr pda/articlehistory.js' + '&action=raw&ctype=text/javascript&dontcountme=s"></s'+'cript>'); // [[Wikipedia:WikiProject User scripts/Scripts/Compare link]] function fixCompare() { var histForm=document.getElementsByTagName("form")[0]; var finalButton=document.getElementById("historysubmit"); var firstButton=histForm.getElementsByTagName("input")[1]; histForm.removeChild(finalButton); histForm.removeChild(firstButton); var compareLink=document.createElement("a"); var genLink="http://en.wikipedia.org/w/index.php?title=" + histForm.title.value + "&diff=" + histForm.diff[0].value + "&oldid=" + histForm.oldid[1].value; compareLink.setAttribute("href", genLink); compareLink.appendChild(document.createTextNode("Compare selected versions")); histForm.insertBefore(compareLink, document.getElementById("pagehistory")); var endLink=compareLink.cloneNode(true); histForm.appendChild(endLink); var diffList=document.getElementById("pagehistory"); diffList.setAttribute("onchange", "updateCompare()"); } function updateCompare() { var histForm=document.getElementsByTagName("form")[0]; var diffList=document.getElementById("pagehistory"); var compareLink=diffList.previousSibling; var endLink=diffList.nextSibling; var oldInd=-1; var i=0; while(oldInd==-1 & i<histForm.oldid.length) { if(histForm.oldid[i].checked) oldInd=i; i++; } var diffInd=-1; var j=0; while(diffInd==-1 & j<histForm.diff.length) { if(histForm.diff[j].checked) diffInd=j; j++; } var genLink="http://en.wikipedia.org/w/index.php?title=" + histForm.title.value + "&diff=" + histForm.diff[diffInd].value + "&oldid=" + histForm.oldid[oldInd].value; compareLink.setAttribute("href", genLink); endLink.setAttribute("href", genLink); } if(url.indexOf("action=history")!=-1) addOnloadHook(fixCompare); // /* Watchlist notifier ([[User:Ais523/watchlistnotifier.js]]); displays a message every time a watched page changes. */ //<pre><nowiki> var wmwpajax; // From [[WP:US]] mainpage (wpajax renamed to wmwpajax) wmwpajax={ download:function(bundle) { // mandatory: bundle.url // optional: bundle.onSuccess (xmlhttprequest, bundle) // optional: bundle.onFailure (xmlhttprequest, bundle) // optional: bundle.otherStuff OK too, passed to onSuccess and onFailure var x = window.XMLHttpRequest ? new XMLHttpRequest() : window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : false; if (x) { x.onreadystatechange=function() { x.readyState==4 && wmwpajax.downloadComplete(x,bundle); }; x.open("GET",bundle.url,true); x.send(null); } return x; }, downloadComplete:function(x,bundle) { x.status==200 && ( bundle.onSuccess && bundle.onSuccess(x,bundle) || true ) || ( bundle.onFailure && bundle.onFailure(x,bundle) || alert(x.statusText+': '+bundle.url)); } }; // Example: // function dlComplete(xmlreq, data) { // alert(data.message + xmlreq.responseText); // } // wmwpajax.download({url:'http://en.wikipedia.org/w/index.php?title=Thresher&action=raw', // onSuccess: dlComplete, message: "Here's what we got:\n\n" }); // End of [[WP:US]] quote function wmWatchEditFound(xmlreq, data) { var watchrev, watchsum, watchrevold, watchpage, junk; watchrev=xmlreq.responseText.split('timestamp="')[1].split('"')[0]; if(wgPageName == "Special:Watchlist") document.cookie="ais523wmwatchrev="+watchrev+"."; else { watchsum=xmlreq.responseText.split('comment="')[1].split('"')[0]; watchpage=xmlreq.responseText.split('title="')[1].split('"')[0]; try { watchrevold=document.cookie.split('ais523wmwatchrev=')[1].split('.')[0]; } catch(junk) {watchrevold=0;} watchsum=watchsum.split('<').join('<').split('>').join('>'); watchpage=watchpage.split('<').join('<').split('>').join('>'); if(watchrev!=watchrevold) document.getElementById('contentSub').innerHTML+= "<div class='watchlistnotify'>\""+watchpage+'" changed: "'+watchsum+'".</div>'; } } addOnloadHook(function() { /* Find the top item in the watchlist, and its edit summary. We only need one item, so set the limit to 1 to ease the load on the server. */ if(location.href.indexOf("/wiki/")!=-1) wmwpajax.download({url:'http://en.wikipedia.org/w/api.php?action=query&list=watchlist&wllimit=1&wldir=older&format=xml&wlprop=comment', onSuccess: wmWatchEditFound}); }); // </nowiki></pre> importScript('User:Barticus88/WhatLinksHere.js');