User:Shahadat/watchlistnotifier.js
Jump to navigation
Jump to search
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 Justapedia:Bypass your cache.
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", or "iusc", take note that this causes you to dynamically load a remote script, which could be changed by others. If you are unsure whether code you are adding to this page is safe, you can ask at technical help. The code will be executed when previewing this page. |
![]() | This user script seems to have a documentation page at User:Shahadat/watchlistnotifier. |
/* Watchlist notifier ([[User:Shahadat/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;
if(xmlreq.responseText.indexOf('revid=')==-1)
{
document.getElementById('mw-content-subtitle').innerHTML+=
"<div class='watchlistnotify'>(<i>watchlistnotifier can't determine whether a "+
"watched page has changed<i>)</div>";
return;
}
watchrev=xmlreq.responseText.split('revid="')[1].split('"')[0];
try
{
watchrevold=document.cookie.split('Shahadatwmwatchrev=')[1].split('.')[0];
}
catch(junk) {watchrevold=0;}
if( mw.config.get('wgPageName') == "Special:Watchlist")
{
document.cookie="Shahadatwmwatchrev="+watchrev+".; path=/";
var aas=document.getElementById('bodyContent').getElementsByTagName('a');
var i=aas.length;
while(i--)
{
if(aas[i].href.indexOf('diff=')!=-1&&watchrevold)
if(+(aas[i].href.split('diff=')[1].split('&')[0])>watchrevold)
aas[i].parentNode.style.fontWeight='bold';
}
}
else
{
watchsum=xmlreq.responseText.split('comment="')[1].split('"')[0];
watchpage=xmlreq.responseText.split('title="')[1].split('"')[0];
watchuser=xmlreq.responseText.split('user="')[1].split('"')[0];
watchsum=watchsum.split('<').join('<').split('>').join('>');
watchpage=watchpage.split('<').join('<').split('>').join('>');
watchuser=watchuser.split('<').join('<').split('>').join('>');
if(watchrev!=watchrevold)
document.getElementById('mw-content-subtitle').innerHTML+=
"<div class='watchlistnotify'>\""+watchpage+'" changed by '+
watchuser+': "'+watchsum+
'". (<a href="/wiki/Special:Watchlist">watchlist</a>)</div>';
}
}
$(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. */
wmwpajax.download({url: mw.config.get('wgScriptPath') + '/api.php?action=query&list=watchlist&wllimit=1&'+
'wlexcludeuser='+mw.config.get('wgUserName')+
'&wldir=older&format=xml&wlprop=comment|ids|title|user', onSuccess: wmWatchEditFound, onFailure: function(){}});
});
// </nowiki></pre>
// [[Category:Justapedia scripts]]