User:Akrivus/PingScript

// Pinglist by Akrivus, to use, copy and paste this into your personal common.js page. // Credit goes mostly to Akrivus and a little bit of Monchoman for pings and !mods script which this is (loosely) based on.

// Using a double backslash '\\' is a substitute for a barrier: word\\ would trigger on forword but not on wordgame, etc. // The amount of pings is unlimited, you can even get pinged by everything by just putting "", only thing is you'd have to make it so it doesn't highlight everything (unless you like it looking all mish-mosh like that.) var PING_LIST = [ "ping1", "ping2", "ping3", "ping4" ];

// 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>"); // Terminate the sound. setTimeout(function {							if ($('#ping').length) $('#ping').remove;						}, 1000); return }				}           }        });    } });