User:Hypirae/wikia.js

/** * Wikia.js - Community Central specific scripts */

/** * WABoardNotify - Creates notifications to new board replies for CC * * WARNING: This is a plugin for AjaxRC and requires this to be installed first. * * Note: I tried this with DOM querying but the WikiActivity doesn't have * incremental item numbering and I cannot be ***ed to sit here and implement * it myself so now I have choses a more robust method that uses API calls. * * Written by Hypirae */ if (mw.config.get('wgCanonicalSpecialPageName') === 'WikiActivity') { window.addEventListener('unload', function {        localStorage.removeItem('WABoardNotify');    });

function WABoardNotify { if (document.hasFocus) { return; }

function grab { return localStorage.getItem('WABoardNotify'); }

function stash (id) { localStorage.setItem('WABoardNotify', id); }

Notification.requestPermission.then(function (permission) {           // if we don't have permission then this will do **** all won't it            if (permission !== 'granted') {                return;            }

var last = grab;

if (last === null) { stash(new Date.toISOString); last = grab; }

new mw.Api.get({               action: 'query',                list: 'recentchanges',                rcnamespace: 2001,                rcprop: 'title|ids|timestamp',                rcend: last            }).then(function (res) {                var last = grab;                var threads = res.query.recentchanges;

if (threads.length === 0) { return; }

var end = threads[0].timestamp;

if (last === null) { last = end; stash(end); }

threads.forEach(function (thread) {                   if (new Date(thread.timestamp) > new Date(last)) {                        var notif = new Notification('Thread update!');                        notif.onclick = function  {                            window.focus;                        }                    }                });

stash(end); });       });    }

window.ajaxCallAgain = window.ajaxCallAgain || []; ajaxCallAgain.push(WABoardNotify); }

window.ajaxSpecialPages = ["RecentChanges", "WikiActivity"];

importArticles({   type: 'script',    articles: [        'u:dev:MediaWiki:AjaxRC/code.js',    ] });