User:SD0001/watchlist-update-title.js
Appearance
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", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
This user script seems to have a documentation page at User:SD0001/watchlist-update-title. |
/**
* 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
* [[Wikipedia:User_scripts/Requests/Archive_4#Watchlist_notifier:_number_of_(automated)_updates_in_browser_page_title]]
*
*/
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;
});
}