User:NeikoTheLucario/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"; 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") { new Notification(this.user, {icon: ICON_URL, body: this.message}); } } } function Chat{ this.getMessages = function { var chelement = document.getElementsByClassName("Chat")[0]; return chelement.firstChild.getElementsByTagName("li"); } this.size = function { return this.getMessages.length; } } // Get permission and start polling. var chat = new Chat; Notification.requestPermission(function(status) { if(status == "granted") {    new Message(chat.getMessages[0]).display;  } });