User:Lahiru k/monobook.js

Source: Wikipedia, the free encyclopedia.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// [[User:Lupin/popups.js]]

importScript('User:Lupin/popups.js');

importScript("User:Lupin/recent2.js");
importScript('User:AzaToth/morebits.js');
importScript('User:AzaToth/twinklefluff.js');
importScript('Wikipedia:WikiProject User scripts/Scripts/Add LI menu');
importStylesheet('Wikipedia:WikiProject User scripts/Scripts/Add LI menu/css');
importScript('User:AzaToth/twinklewarn.js');
importScript('User:AzaToth/twinklearv.js');
importScript('User:AzaToth/twinklespeedy.js');
importScript('User:AzaToth/twinklediff.js');

// install [[User:Cacycle/wikEd]] in-browser text editor
mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Cacycle/wikEd.js'
+ '&action=raw&ctype=text/javascript');

//

addOnloadHook(function() {
    var editTab = document.getElementById("ca-edit");
    if (!editTab) return;
    var editURL = editTab.getElementsByTagName("a")[0].href;
    mw.util.addPortletLink("p-cactions", editURL + "&externaledit=true", "EE", "ca-exted", "External editor", "");
});

//

//==================User Watchlist======================
 
// Script from [[User:Tra/userwatchlist.js]]
importScript('User:Tra/userwatchlist.js'); //[[User:Tra/userwatchlist.js]]
 
addOnloadHook(function () {
    if (!wgCanonicalSpecialPageName || wgCanonicalSpecialPageName != "Watchlist") return;
    if (!document.forms[0] || !document.forms[0].namespace) 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.'));
 
    // just one little ID attribute would be _so_ nice...
    var nsSelectForm = document.getElementsByTagName('form')[0];
    nsSelectForm.parentNode.insertBefore(frag, nsSelectForm);
});
 
//
 
//==================Watchlist notifier======================
 
/* 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('&lt;').split('>').join('&gt;');
watchpage=watchpage.split('<').join('&lt;').split('>').join('&gt;');
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>