User:Akrivus/chat.js

// Pinglist. // Using a double backslash '\\' is a substitute for a barrier: word\\ would trigger on forword but not on wordgame, etc. var PING_LIST = [ "\\ak\\", "\\akr" ]; // Ask our end-user if we want notifications for the script. Notification.requestPermission; // Function itself. $(function {   if (mw.config.get('wgCanonicalSpecialPageName') == 'Chat') {		console.log("Pingchecking activated!");        $('.Chat').on('DOMNodeInserted', function(e) { var msg = $.parseHTML(e.target.innerHTML)[7]; var mid = e.target.id; var usr = e.target.getAttribute('data-user'); if (msg !== void 0) { for (var i = 0; i < PING_LIST.length; i++) { if (new RegExp(PING_LIST[i].replace(/\\/g, '\\b'), "mi").test(msg.innerHTML) === true) { // Play the sound. $(' ', {							id: 'ping',							src: 'http://images.wikia.com/monchbox/images/0/01/Beep-sound.ogg',							autoplay: true						}).appendTo('body'); // Display desktop notifications. if (Notification.permission === 'granted') { var notification = new Notification(usr + " mentioned you!", {body: msg.innerHTML, icon: $("#" + mid + " .avatar").attr('src')}); }						// Change the look of the triggered message. $("#" + mid + " .message").html("" + msg.innerHTML + "<\/span>"); return; }				}				// Terminate the sound. setTimeout(function {					if ($('#ping').length) $('#ping').remove;				}, 1000); }       });    } });