User:MysticDarkz9/chat.js

// Swiggle.js - Notification system for Wikia chats. By Incongruence. // An attempt at getting balloon notifications to work with the chat. // Ongoing! May be Chrome-only. I will test compatibility when further completed. // May well be broken at any given time, user beware. // Icon to use. This functionality may be replaced with user avatars. const ICON_URL = "http://a.pomf.se/xnaglt.png"; // Time between checks. const CHECK_TIME = 500; // Time to keep the notifications open for. const KEEP_TIME = 2734; function Message(element) { this.element = element; this.user = function { return this.element.dataset.user; } this.message = function { return this.element.getElementsByClassName("message")[0].innerHTML; } this.display = function { if(Notification.permission == "granted") { var msg = new Notification(this.user, {icon: ICON_URL, body: this.message}); setTimeout(function {       msg.close;      }, KEEP_TIME); } } } function Chat{ this.getMessages = function { var chelement = document.getElementsByClassName("Chat")[0]; return chelement.firstChild.getElementsByTagName("li"); } this.size = function { return this.getMessages.length; } } function Notifier { this.chat = new Chat; this.count = 0; this.poll = function { var size = this.chat.size; if(this.count != size) { new Message(this.chat.getMessages[size - 1]).display; }   this.count = size; } } // Get permission and start polling. var notifier = new Notifier; Notification.requestPermission(function(status) { if(status == "granted") {    setInterval(function{ notifier.poll; }, CHECK_TIME);  } });