User:Shining-Armor/notifications.js

/** * Chat notifications * * This program uses new window notifications to provide alerts when pinged * * Copyright(c) 2015 Shining-Armor http://c.wikia.com/wiki/User:Shining-Armor */

var sfNotifications = {};

sfNotifications.notify = function(user, text, img) { new Notification(user, {body: text, icon: img}); };

sfNotifications.parse = function(node) { var node = $(node); if (node.length === 7) { if ($(node[6]).text.indexOf(mw.config.get('wgUserName')) > -1 && $(node[4]).text !== mw.config.get('wgUserName')) { sfNotifications.notify($(node[4]).text, $(node[6]).text, $(node[0]).attr('src')); }   } };

sfNotifications.init = function { if (Notification.permission === "granted") { if (typeof window.mainRoom !== 'undefined') { mainRoom.model.chats.bind("afteradd", function(c) {               sfNotifications.parse($("#Chat_" + roomId + " .message:last").parent.html);            }); }   } else { Notification.requestPermission; sfNotifications.init; } };

$(document).ready(function { sfNotifications.init });