User:Yair rand/watchlistnotifications.js

// Notifies the user when something new shows up on their watchlist. Desktop notifications only for Chrome and (I think) Firefox 5. function watchlistNotifier{ var t, nc = window.webkitNotifications || window.mozNotifications || window.oNotifications || window.msNotifications || window.notifications || null; function checkWatchlistForUpdates{ JsMwApi({action:'query',list:'watchlist',wlexcludeuser:wgUserName,wlprop:'user|title|timestamp',wlend:t?t:1,wlshow:mw.user.options.get("watchlisthidebots")=="1"?"!bot":""},function(r){     r = r.query.watchlist;      for(var i = 0; t && t < r[i].timestamp; i++){        if(nc && nc.checkPermission == 0){          var w=nc.createNotification('',r[i].title,'has been edited by ' + r[i].user)          w.show          w.onclick = function{w.cancel;window.focus;}          }        document.title = r[i].title+' has been edited by ' + r[i].user        onfocus = function{location.reload(true)}        }      t = r[0].timestamp;      setTimeout(checkWatchlistForUpdates, 15000)      }) } checkWatchlistForUpdates if(nc && nc.checkPermission == 1){ document.getElementById('firstHeading').appendChild(newNode('a',"Enable watchlist desktop notifications",{'style':'float:right; cursor:pointer; font-size: 13px;',click:function{nc.requestPermission(function{location.reload}); this.innerHTML = 'Waiting for permission to use desktop notifications...'}})) } }

wgPageName == "Special:Watchlist" && jQuery(document).ready(watchlistNotifier)