User:Eissink/watchlist-update-title.js
(Redirected from User:Jürgen Eissink/watchlist-update-title.js)
Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
Documentation for this user script can be added at User:Eissink/watchlist-update-title. |
/**
* 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;
});
}