Jump to content

User:SD0001/watchlist-update-title.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by SD0001 (talk | contribs) at 18:47, 18 July 2019 (Created page with '/** * Updates the document title when the watchlist undergoes a live update * Should work on any wiki. * Per request by Jürgen Eissink * * Watchlist - Wik...'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
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.
/**
 * Updates the document title when the watchlist undergoes a live update
 * Should work on any wiki.
 * Per request by Jürgen Eissink
 * 
 * Watchlist - Wikipedia
 * (1) Watchlist - Wikipedia     // after first update
 * 
 * The title is reset when the window comes into focus.
 * 
 */

if (mw.config.get('wgCanonicalSpecialPageName') === 'Watchlist') {
	var watchlistUpdateNumber = null;
	var watchlistHeading = document.title;
	
	mw.hook('wikipage.content').add(function() {
		if ( watchlistUpdateNumber === null ) { // prevent action immediately after hook is added
		    watchlistUpdateNumber = 0;
		    return;
		}
		
		watchlistUpdateNumber += 0.5;
		document.title = '(' + watchlistUpdateNumber + ') ' + watchlistHeading;
	});
	
	$(window).focus(function() {
		watchlistUpdateNumber = 0;
		document.title = watchlistHeading;
	});
}