Utilisateur:Golmore/WatchlistNotifs.js
//Idée et code original de [[User:Lepsyleon]]
// Remplacer "Liste de suivi" par "Liste de suivi (nombre de pages suivies non lues)"
// quand toutes les pages de la LDS ne sont pas marquées comme étant visitées.
// Le nombre de pages suivies non lues inclut les articles modifiés via Wikidata selon que
// l'option "Voir les modifications de Wikidata dans votre liste de suivi" est cochée ou non dans les préférences.
// Installation : insérer le code importScript('Utilisateur:Golmore/WatchlistNotifs.js'); dans votre common.js
var tps_refresh = 10; // Rafraîchir la page toutes les 10 secondes
window.RenameLdS = function () {
var LdSLi = new mw.Api();
// Définir si l'option "Voir les modifications de Wikidata dans votre liste de suivi" est cochée dans les préférences
var WDoption = mw.user.options.get('wlshowwikibase');
// Cas 1 : connaître le nombre d'éléments non lus dans la LdS suite modifs faites UNIQUEMENT sur WP fr (avec limite max de 500 selon l'API:Watchlist)
if (!WDoption) {
LdSLi.get( {action: 'query', list: 'watchlist', wlprop: '', wlshow: 'unread', wllimit: '500'}).done( function( data ) {
if (!data.query.watchlist.length) {
$('#pt-watchlist').find('a').text('Liste de suivi').css({ "font-weight": "", "color": "",});
}
else {
$('#pt-watchlist').find('a').text('Liste de suivi (' + data.query.watchlist.length + ')').css({"font-weight": "700",});
}
} );
}
// Fin du cas 1
// Cas 2 : connaître le nombre d'éléments non lus dans la LdS suite modifs faites sur WP fr ET Wikidata
// Rq : dans les préférences, l'option "Voir les modifications de Wikidata dans votre liste de suivi" est alors cochée
else {
LdSLi.get({action: 'query', meta: 'userinfo', uiprop: 'unreadcount'}).done(function (data) {
if (!data.query.userinfo.unreadcount) {
$('#pt-watchlist').find('a').text('Liste de suivi').css({ "font-weight": "", "color": "",});
}
else {
$('#pt-watchlist').find('a').text('Liste de suivi (' + data.query.userinfo.unreadcount + ')').css({"font-weight": "700", "color": "",});
}
});
}
// Fin du cas 2
setTimeout("RenameLdS();", tps_refresh * 1000);
};
mw.loader.using(['mediawiki.api', 'user.options'], function () {
$(document).ready(function () { RenameLdS(); } );
} );
Text is available under the CC BY-SA 4.0 license; additional terms may apply.
Images, videos and audio are available under their respective licenses.