User:SD0001/watchlist-update-title.js

/** * Updates the document title to show a prefixed number indicating the number of new * changes when the watchlist undergoes a live update * * Should work on any wiki. * * Per request by Jürgen Eissink * User_scripts/Requests/Archive_4 * */

if (mw.config.get('wgCanonicalSpecialPageName') === 'Watchlist') { // Enable "Live updates" every time $.ready.then(function { $('a:contains("' + mw.messages.get('rcfilters-liveupdates-button') + '")').click; }); var watchlistUpdateNumber = 0; var watchlistHeading = document.title; var markSeenButtonPressed = false; $('.mw-rcfilters-ui-markSeenButtonWidget').on('click', function {		markSeenButtonPressed = true;	}); mw.hook('wikipage.content').add(function($content) {		if (!$content.hasClass('mw-rcfilters-ui-changesListWrapperWidget')) {			return;		}		// Handle the hook being fired just after the "Mark all changes as seen" is clicked		if (markSeenButtonPressed) {			watchlistUpdateNumber = 0;			document.title = watchlistHeading;			markSeenButtonPressed = false;			return;		}

$content.find('ul.special').children.each(function(i, e) {			// exit on reaching the horizontal line separator		   if (e.tagName === 'DIV') return false;		    // don't increment counter on one's own edits		    if (e.querySelector('bdi').textContent !== mw.config.get('wgUserName')) {		    	watchlistUpdateNumber += 1;		    }		}); if (watchlistUpdateNumber > 0) { document.title = '(' + watchlistUpdateNumber + ') ' + watchlistHeading; }	});	$(window).focus(function { watchlistUpdateNumber = 0; document.title = watchlistHeading; }); }