User:Sportzpikachu/watchlist-notice.js

// This script was taken from User:Enterprisey/watchlist-notice.js and edited to allow customization options. // Backlink: User:Enterprisey/watchlist-notice.js (function (mw, $, window) {   var options = $.extend({ filter: ["unread"], refreshInterval: 120000 }, window.watchlistOptions);    if (!options.filter.indexOf("unread") === -1) {        options.filter.push("unread");    }

function showNotice { // Stick a "Watchlist update!" notice after the notification count $("#pt-notifications-notice").after(           $("").append($("") .text("Watchlist update!") .css({                   "background-color": "green",                    "color": "white",                    "border-radius": "2px",                    "padding": "0.25em 0.45em 0.2em",                    "cursor": "pointer",                    "font-weight": "bold",                    "transition": "background-color 0.5s"                }) .attr("href", "/wiki/Special:Watchlist") .mouseover(updateNotice) )               .attr("id", "watchlist-update-notice")        ); };

function updateNotice { // Lighten the background color so the user knows we're updating $("#watchlist-update-notice a").css("background-color", "#7bff7b");

// Update the notice (new mw.Api).get({           format: "json",            action: "query",            list: "watchlist",            wlshow: options.filter,            wllimit: 1        }).done(function (data) {            if (!data.query) { return; }            if (data.query.watchlist.length) {                // There are new watchlist diffs to read, so show notice                if (!$("#watchlist-update-notice").length) {                    // That is, if it isn't shown already                    showNotice;                } else {                    // There's already a notice, so change background                    $("#watchlist-update-notice a").css("background-color", "green");                }            } else {                // No new watchlist diffs to read, so hide notice                $("#watchlist-update-notice").remove;            }        }        ); };

$(document).ready(function {        updateNotice;        window.setInterval(updateNotice, options.refreshInterval);    }); })(mw, jQuery, window);