User:Himario7/chat.js

//

// Pinglist. // Using '\\b' is a barrier: word\b would trigger on forword but not on wordgame, etc. Other regex flags work on this. // Don't forget to double-slash, since single slashes in JS break things. var PING_LIST = [ "Mario", "HiMario7" ]; // Ping sound. // Needs to be a valid URL to an .ogg file. var PING_SOUND = 'http://vignette2.wikia.nocookie.net/botcentral/images/9/9d/Papyrus_Earrape_%28_%CD%A1%C2%B0_%CD%9C%CA%96_%CD%A1%C2%B0%29.ogg/revision/latest?cb=20160514013730'; // Ping color. // Needs to be a valid HTML color code. var PING_COLOR = "blue"; // 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 mee = $(".User .username").html; var mid = e.target.id; var usr = e.target.getAttribute('data-user'); if (usr == mee) return; if (msg !== void 0) { for (var i = 0; i < PING_LIST.length; i++) { if (new RegExp(PING_LIST[i], "mi").test(msg.innerHTML) === true) { // Play the sound. $(' ', {							id: 'ping',							src: PING_SOUND,							autoplay: true						}).appendTo('body'); // Display desktop notifications. if (Notification.permission === 'granted') { var notification = new Notification(usr + " mentioned you!", {body: msg.innerHTML.replace(/(<(img src[^>]*|(?:\/|)a[^>]*|(?:\/|)span[^>]*)>)/g, ""), icon: $("#" + mid + " .avatar").attr('src')}); }						// Change the look of the triggered message. $("#" + mid + " .message").html("" + msg.innerHTML + "<\/span>"); break; }				}				// Terminate the sound. setTimeout(function {					if ($('#ping').length) $('#ping').remove;				}, 1000); }       });    } }); //