User:HambleBee/chat.js

// Import Chat features importArticles({   type    : "script",    articles: [        "u:dev:ChatOptions/code.js",        "u:dev:!mods/code.js"    ] });

var config = JSON.parse(localStorage.getItem('custom-chat-pings-config')) || {}, object, objectText, pingFinished, formHTML = '\  \ \		 Mode: \  \ Messages \ Alerts \ All \ \		 \		 Audio: \  \ \		 Color: \  \ \		 \		 For each field, seperate each entry with a comma. All entries are case insensitive. \		 \			 Messages \ List: \  \ Blacklist: \  \ Ignored Users: \  \ \			 Alerts \ List: \  \ Blacklist: \  \ To report bugs or suggestions, do so here. \	 \ ', self = { init: function { if (mw.config.get('wgCanonicalSpecialPageName') !== "Chat") return; //add audio object to page $('body').append(' '); //add button for loading GUI $('#Write').append(' Pings '); //set event listener to load the GUI $('#btn-custom-ping').click(function { 				self.loadGUI;			}); //start the chat event listener we'll be using //@param the child object being added mainRoom.model.chats.bind("afteradd", function (child) {				//select child object				object = $('#entry-' + child.cid);				//set ping boolean to false				pingFinished = false;				if (config.messageList || config.alertList) {					if (object.hasClass('inline-alert')) {						if (config.mode != 0) {							objectText = object.text.toLowerCase.trim;							$.each(config.alertList.split(','), function(i,v) { $.each(config.alertBlacklist.split(','), function(i2,v2) {									if (objectText.indexOf(v.toLowerCase) !== -1 && (objectText.indexOf(v2.toLowerCase) === -1 || !v2)) {										self.processPing;										if (pingFinished) return;									}								}); if (pingFinished) return; });						}					}					else if ($('div.User > span:nth-child(2)').text !== object.attr('data-user')) {						if (config.mode != 1) {							objectText = object.children('.message').text.toLowerCase.trim;							$.each(config.messageList.split(','), function(i,v) { $.each(config.messageBlacklist.split(','), function(i2,v2) {									$.each(config.ignore.split(','), function(i3,v3) { if (objectText.indexOf(v.toLowerCase) !== -1 && (objectText.indexOf(v2.toLowerCase) === -1 || !v2) && (object.attr('data-user').toLowerCase.indexOf(v3.toLowerCase) === -1 || !v3)) { self.processPing; if (pingFinished) return; }									});									if (pingFinished) return;								}); if (pingFinished) return; });						}					}				}			});			//add inline alert to confirm loading of script mainRoom.model.chats.add(new models.InlineAlert({text:'Custom Chat Pings loaded. To report bugs or suggestions, do so here.'})); },		loadGUI: function { $.showCustomModal('Custom Chat Pings', formHTML, {				id: 'form-custom-ping',				width: '30%',				buttons: [{ 				    message: 'Cancel',				    handler: function {						$('#form-custom-ping').closeModal;				    }				},  {				    message: 'Reset',				    defaultButton: true,				    handler: function {						$.showCustomModal('Confirmation', 'Are you sure you want to reset the values?', { id: 'form-custom-ping-clear', width: '20%', buttons: [{ message: 'Yes', defaultButton: true, handler: function { $('#select-pings-mode').val(0); $('#text-pings-audio,#text-pings-color,#text-pings-messages-list,#text-pings-messages-blacklist,#text-pings-messages-ignore,#text-pings-alerts-list,#text-pings-alerts-blacklist').val(''); $('#form-custom-ping-clear').closeModal; }							}, {								message: 'No', defaultButton: true, handler: function { $('#form-custom-ping-clear').closeModal; }							}]						});				   }				},  {				    message: 'Update',				    defaultButton: true,				    handler: function {						config.mode = $('#select-pings-mode').val;						config.audio = $('#text-pings-audio').val || $('#text-pings-audio').attr('placeholder');						config.color = $('#text-pings-color').val || $('#text-pings-color').attr('placeholder');						config.messageList = $('#text-pings-messages-list').val;						config.messageBlacklist = $('#text-pings-messages-blacklist').val;						config.ignore = $('#text-pings-messages-ignore').val;											config.alertList = $('#text-pings-alerts-list').val;						config.alertBlacklist = $('#text-pings-alerts-blacklist').val;						localStorage.setItem('custom-chat-pings-config', JSON.stringify(config));						$('#form-custom-ping').closeModal;				    }				}]			}); //load stored values after GUI loads if (config.mode) $('#select-pings-mode').val(config.mode); if (config.audio) $('#text-pings-audio').val(config.audio); if (config.color) $('#text-pings-color').val(config.color); if (config.messageList) $('#text-pings-messages-list').val(config.messageList); if (config.messageBlacklist) $('#text-pings-messages-blacklist').val(config.messageBlacklist); if (config.ignore) $('#text-pings-messages-ignore').val(config.ignore); if (config.alertList) $('#text-pings-alerts-list').val(config.alertList); if (config.alertBlacklist) $('#text-pings-alerts-blacklist').val(config.alertBlacklist); },		processPing: function { //change text color object.css('color', config.color); //play sound $('#custom-ping-sound').html(' '); //stop all loops pingFinished = true; } }; self.init; }) (this.jQuery, this.mediaWiki); //
 * (function($, mw) {