Jump to content

User:Syncategoremata/watchlistnotifier.js

From 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.
/* Watchlist notifier ([[User:Syncategoremata/watchlistnotifier.js]]); displays a message every time a watched page changes. */

switch (skin) {
case 'modern': case 'monobook': case 'vector':
    var query = sajax_init_object();

    query.onreadystatechange = function() {
	with (query) {
	    if (readyState == 4 && status == 200) {
		var api = eval('('+responseText+')');
		var subtitle = document.createElement('div');
		with (subtitle) {
		    className = 'watchlistnotify';
		}
		with (api.query.watchlist[0]) {
		    subtitle.appendChild(
			document.createTextNode(
			    title+'..'+user+' ('+comment+')' ) );
		}
		document.getElementById('contentSub').appendChild(subtitle);
	    }
	}
    }

    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. */
	query.open( 'GET',
		    wgServer +
		    wgScriptPath +
		    '/api.php?format=json&action=query&prop=info&list=watchlist&wllimit=1&wldir=older&wlprop=comment|ids|title|user',
		    true);
	query.send(null);  
    });
}