User:Dragonfree97/chat.js/options2.js

/** * Wikia ChatOptions * Change some options on Special:Chat to make it easier * to use and more useful in general. * * WARNING * Make sure you are not loading MediaWiki:Chat.js/load.js * with MediaWiki:Chat-edit-count. * Load it with MediaWiki:Chat-welcome-message, or this * will malfunction badly. * * Created from ChatOptions * by Callofduty4, Madnessfan34537, and Sactage */

if (typeof(chatOptionsCustom)!="undefined") { if (typeof(chatOptionsCustom.staffIcon)=="undefined") { chatOptionsCustom.staffIcon = "http://img1.wikia.nocookie.net/__cb20140626173406/gamedezyner/images/6/60/StaffIcon.png"; }	if (typeof(chatOptionsCustom.modIcon)=="undefined") { chatOptionsCustom.modIcon= "http://img1.wikia.nocookie.net/__cb20140626173343/gamedezyner/images/8/89/ModIcon.png"; } 	if (typeof(chatOptionsCustom.pingSound)=="undefined") { chatOptionsCustom.pingSound = "http://images.wikia.com/gamedezyner/images/7/7e/PingSound.ogg"; } //	if (typeof(chatOptionsCustom.forcedModules)=="undefined") { //		chatOptionsCustom.forcedModules = []; //	} //	if (typeof(chatOptionsCustom.forcedSettings)=="undefined") { //		chatOptionsCustom.forcedSettings = {}; //	} //	if (typeof(chatOptionsCustom.disabledModules)=="undefined") { //		chatOptionsCustom.disabledModules = []; //	} } else { chatOptionsCustom = { staffIcon: "http://img1.wikia.nocookie.net/__cb20140626173406/gamedezyner/images/6/60/StaffIcon.png", modIcon: "http://img1.wikia.nocookie.net/__cb20140626173343/gamedezyner/images/8/89/ModIcon.png", pingSound: "http://images.wikia.com/gamedezyner/images/7/7e/PingSound.ogg", //		forcedModules: [], //		forcedSettings: {}, //		disabledModules: [], //		modules: [] } }

var chatOptions = { release: { version: 0.4, branch: "Stable" },	custom: { staffIcon: chatOptionsCustom.staffIcon, modIcon: chatOptionsCustom.modIcon, pingSound: chatOptionsCustom.pingSound //		forcedModules: chatOptionsCustom.forcedModules, //		forcedSettings: chatOptionsCustom.forcedSettings, //		disabledModules: chatOptionsCustom.disabledModules },	module: function(name, loadScript, loadWiki) { this.enabled = function { return chatOptions.cookie.arrays.modules[this.id]; }		this.id = Object.keys(chatOptions.modules).length; this.loaded = false; this.modOnly = false; this.adminOnly = false; this.loadScript = loadScript; this.loadWiki = loadWiki; this.name = name; this.load = function { if (this.loadWiki!="") { importScriptPage(this.loadScript,this.loadWiki); }			else { importScriptPage(this.loadScript); }			this.loaded = true; }	},	modules: {}, pages: { list: {}, save: function { // Save all registered cookie arrays to respective cookies for (i in Object.keys(chatOptions.pages.list)) { chatOptions.api.functions.editPage("User:" + wgUserName + "/ChatOptions/" + chatOptions.pages.list[Object.keys(chatOptions.pages.list)[i]].name,chatOptions.pages.list[Object.keys(chatOptions.pages.list)[i]].value); }		},		load: function { // Save all registered cookie arrays to respective cookies for (i in Object.keys(chatOptions.pages.list)) { if (typeof(chatOptions.api.functions.getPage("User:" + wgUserName + "/ChatOptions/" + chatOptions.pages.list[Object.keys(chatOptions.pages.list)[i]].name).content)!="string") { var content = ""; }				else { content = chatOptions.api.functions.getPage("User:" + wgUserName + "/ChatOptions/" + chatOptions.pages.list[Object.keys(chatOptions.pages.list)[i]].name).content; }				chatOptions.pages.list[Object.keys(chatOptions.pages.list)[i]].value = content; }		}	},	cookie: { arrays: { version: [], modules: [] },		get: function(cookie_name,pos) { var x, y, cookie_array = document.cookie.split(";"); for (var i=0; i < cookie_array.length; i++) { x = cookie_array[i].substr(0,cookie_array[i].indexOf("=")); y = cookie_array[i].substr(cookie_array[i].indexOf("=")+1); x = x.replace(/^\s+|\s+$/g,""); if (x == cookie_name) { return y;				} }		},		set: function (cookie_name,data) { var domain = wgServer.split("//")[1]; document.cookie = cookie_name + "=" + data + "; max-age=" + 60*60*24*150 + "; path=/; domain=" + domain; },		load: function { // Load all registered cookie arrays from respective cookies for (i in Object.keys(chatOptions.cookie.arrays)) { chatOptions.cookie.arrays[Object.keys(chatOptions.cookie.arrays)[i]] = chatOptions.cookie.get("chatOptions"+Object.keys(chatOptions.cookie.arrays)[i].charAt(0).toUpperCase + Object.keys(chatOptions.cookie.arrays)[i].slice(1)).split(","); }		 		},		save: function { // Save all registered cookie arrays to respective cookies for (i in Object.keys(chatOptions.cookie.arrays)) { chatOptions.cookie.set("chatOptions"+Object.keys(chatOptions.cookie.arrays)[i].charAt(0).toUpperCase + Object.keys(chatOptions.cookie.arrays)[i].slice(1),chatOptions.cookie.arrays[Object.keys(chatOptions.cookie.arrays)[i]].toString); }		},		reset: function { //Reset cookie data to default modules = Object.keys(chatOptions.modules); for ( i in Object.keys(chatOptions.modules) ) { module = chatOptions.modules[modules[i]]; chatOptions.cookie.arrays.modules[module.id] = 0; }			chatOptions.cookie.arrays.version[0] = chatOptions.release.version; chatOptions.cookie.save; }	},	menu: { loaded: false, load: function { $("#ChatHeader .public.wordmark").append(''); $(".chatOptionsMenu").mouseover(function {$('#chatOptionsMenu').css('display','block')}); $(".chatOptionsMenu").mouseout(function {$('#chatOptionsMenu').css('display','none')}); chatOptions.menu.loaded = true; },		add: function(id, title) { if (!chatOptions.menu.loaded) { chatOptions.menu.load; }			$('#chatOptionsMenu').append('' + title + ''); $('#'+id).hover(function { $(this).css("background-color","#cce1ef") },function { $(this).css("background-color",$('#WikiaPage').css("background-color")) }); //Need to load background color from style },		open: function { var $optionsWindowHTML = $.showCustomModal( "Options", ' ' + 				' Please select the features you would like to enable: ' + 				' ' + 				' Note: Clicking Save will refresh the chat. ', {				id: "optionsWindow",					width: 400,					buttons: [						{							id: "cancel",							message: "Cancel",							handler: chatOptions.menu.cancel						},						{							id: "save",							defaultButton: true,							message: "Save",							handler: chatOptions.menu.save						}					]			}); $(".close").click(chatOptions.menu.cancel); $(".blackout").click(chatOptions.menu.cancel); $(".blackout").addClass("chatOptions"); chatOptionsTable = ""; modules = Object.keys(chatOptions.modules); for (i=0;i Enable ' + module.name + ' '; if (typeof(module.settingsID)!="undefined"){ chatOptionsTable += ' (Settings)'; }						chatOptionsTable += ' '; }					else { chatOptionsTable += '  Enable ' + module.name + ' '; if (typeof(module.settingsID)!="undefined"){ chatOptionsTable += ' (Settings)'; }						chatOptionsTable += ' '; }					if ((modules.length % 2)!=1) { chatOptionsTable += ' '; }					$('#chatOptionsTable').html(chatOptionsTable); }				for (i=0;i<modules.length;i++) { module = chatOptions.modules[modules[i]]; if (module.enabled==1) { $('input[name="' + module.name + '"]').attr("checked",true); }					if (module.modOnly && wgUserGroups.indexOf("chatmoderator") == -1 && wgUserGroups.indexOf("sysop") == -1) { $('input[name="' + module.name + '"]').attr("checked",false); $('input[name="' + module.name + '"]').attr("disabled",true); }					$("#"+module.settingsID).click(module.settingsFunction); $("#"+module.settingsID).click(chatOptions.menu.cancel); }		},		save: function { modules = Object.keys(chatOptions.modules); checked = $(".chatOption:checked"); unchecked = $(".chatOption:not(:checked)"); cookieString = ""; for ( i in Object.keys(chatOptions.modules) ) { module = chatOptions.modules[modules[i]]; if ($('input[name="' + module.name + '"]:checked').length > 0) { chatOptions.cookie.arrays.modules[module.id] = 1; }				else { chatOptions.cookie.arrays.modules[module.id] = 0; }			}			chatOptions.cookie.save; chatOptions.menu.cancel; window.location.reload; },		cancel: function { $('#optionsWindow').remove; $('.blackout.chatOptions').remove; }	},	load: function { if (typeof(chatOptions.cookie.get("chatOptionsVersion"))=="undefined") { // Is ChatOptions version saved in cookie? If not, initialize cookies for first time and continue loading. chatOptions.cookie.reset; chatOptions.alert("Welcome to ChatOptions! Updated to version "+chatOptions.release.version+" "+chatOptions.release.branch+"!"); chatOptions.alert("Please be sure to set your settings the way you want!"); console.log({Info: "Cookie",Data: "Cookies Initialized for first run"}); chatOptions.loading = true; }		else { if (isNaN(parseFloat(chatOptions.cookie.get("chatOptionsVersion")))) { // Is ChatOptions version cookie invalid? If so, reset cookies to default values and continue loading. chatOptions.cookie.reset; chatOptions.alert("Something went wrong, but we caught it! Your chat settings had to be reset though :(");				chatOptions.alert("Please change your settings to your liking.");				console.log({Error: "Cookie",Data: "Invalid cookies. Cookies were reset."});				chatOptions.loading = true;			}			else {				if (parseFloat(chatOptions.cookie.get("chatOptionsVersion"))>chatOptions.release.version) { // Is ChatOptions version older than last load? If so, alert user and stop loading.					chatOptions.alert("Error! You have used a newer version of ChatOptions before! Please use the newest version!");					console.log({Error: "Unknown",Result: "Aborting"});					chatOptions.loading = false;				}				if (parseFloat(chatOptions.cookie.get("chatOptionsVersion"))==chatOptions.release.version) { // Is ChatOptions version the same as last load? If so, welcome user and continue loading.					chatOptions.alert("Welcome to ChatOptions! This is version "+chatOptions.release.version+" "+chatOptions.release.branch+".");					chatOptions.alert('Please report any bugs or issues to Gamedezyner</a>');					console.log({Info:"Cookie",Data:"Version match. Continuing load."});					chatOptions.loading = true;				}				if (parseFloat(chatOptions.cookie.get("chatOptionsVersion"))<chatOptions.release.version) { // Is ChatOptions version newer than last load? If so, alert the user to the upgrade and continue loading.					chatOptions.cookie.set("chatOptionsVersion",chatOptions.release.version.toString);					chatOptions.alert("Welcome to ChatOptions! You just upgraded to version "+chatOptions.release.version+" "+chatOptions.release.branch+"!");					chatOptions.alert("Please be sure to check that your settings are set the way you want!");					chatOptions.alert("This version includes the return of the AFK Button! Once enabled, you will find it in the dropdown when you hover your mouse over the settings button.");					chatOptions.loading = true;				}			}		}		if (chatOptions.loading) {			chatOptions.cookie.load;			modules = Object.keys(chatOptions.modules);			for (i = 0; i < Object.keys(chatOptions.modules).length; i++) {				module = chatOptions.modules[modules[i]];				if (module.enabled == true) {					module.load;				}			}			$("#ChatHeader .public.wordmark").append('<a href="#" id="chatOptionsButton" class="chatOptionsMenu" style="position:absolute;right:150px;"><img src="http://img4.wikia.nocookie.net/__cb20140623220607/gamedezyner/images/0/04/ChatOptionsButton.png" height="32px" style="float:right;padding-right:3px;"/></a>');			$('head').append('<style type="text/css">#WikiChatList {overflow:auto;padding-bottom:10px;height:30%;resize:vertical;} #Rail {overflow:hidden;} #Rail h1.private {display:block !important;} #Rail .WikiChatList li {display:block !important}.User {resize: none;}.User.chat-mod .username:after { background-image: url(' + chatOptions.custom.modIcon + ');background-position: 0px;background-size: 16px;}.User.staff .username:after { background-image: url(' + chatOptions.custom.staffIcon + ');background-position: 0px;background-size:16px;} ') $("#chatOptionsButton").click(chatOptions.menu.open); chatOptions.loading = false; chatOptions.loaded = true; console.log({Info:"ChatOptions",Data:"Successfully Loaded!"}); }	},	alert: function(text) { newInlineAlert = new models.InlineAlert; newInlineAlert.attributes.text = text; mainRoom.model.chats.add(newInlineAlert); },	settings: { open: function(title,content,width,save) { $.showCustomModal( title, '<form method="" name="" class="WikiaForm "> ' + content + ' ', {				id: "settingsWindow",					width: width,					buttons: [						{							id: "cancel",							message: "Cancel",							handler: chatOptions.settings.cancel						},						{							id: "save",							defaultButton: true,							message: "Save",							handler: save						}					]			}); $(".close").click(chatOptions.settings.cancel); $(".blackout:not(.chatOptions)").addClass("chatSettings") },		cancel: function { $('#settingsWindow').remove; $(".blackout.chatSettings").remove }	},	api: { edit: function (cookie_name,data) { this.token = mw.user.tokens.get("editToken"); this.action = "edit"; this.bot = "true"; this.format = "json"; },		query: function { this.action = "query"; this.format = "json"; },		post: function(params) { $.ajax({				url:     "http://" + chatOptions.api.target + ".wikia.com/api.php",				type:     "POST",				async: false,				cache: false,				timeout: 30000,				dataType: "JSON",				data: params			}).done(function(data) { 				params.result = "Success";				params.response = data;			}).fail(function {				params.result = "Fail";			}); },		settings: { throttle: 1000, pagelimit: 100 },		result: {}, target: wgDBname, functions: { getPage: function(targetpage) { thisQuery = new chatOptions.api.query; thisQuery.prop = "revisions"; thisQuery.rvprop = "content"; thisQuery.titles = targetpage; chatOptions.api.post(thisQuery); thisQuery.pages = thisQuery.response.query.pages; key = Object.keys(thisQuery.pages)[0]; if (key!="-1") { thisQuery.content = thisQuery.pages[key]["revisions"][0]["*"]; return thisQuery; }				else { return { Error: "Failed to get page contents" }; }			},			editPage: function(target, text, summary) { thisEdit = new chatOptions.api.edit; thisEdit.title = target; thisEdit.text = text; thisEdit.summary = summary; chatOptions.api.post(thisEdit); return thisEdit; }		}	} }; // Append Chat Options Button to header

// Register our Modules // Pings chatOptions.modules.pings = new chatOptions.module("Pings", chatOptions.release.branch + "/ChatOptions/Modules/pings.js", "gamedezyner"); // Multi PM chatOptions.modules.multiPM = new chatOptions.module("Multi PM", chatOptions.release.branch + "/ChatOptions/Modules/multiPM.js", "gamedezyner"); // Multi Kick chatOptions.modules.multiKick = new chatOptions.module("Multi Kick", chatOptions.release.branch + "/ChatOptions/Modules/multiKick.js", "gamedezyner"); chatOptions.modules.multiKick.modOnly = true; // Chat Style chatOptions.modules.style = new chatOptions.module("Style", chatOptions.release.branch + "/ChatOptions/Modules/style.js", "gamedezyner"); // Tab Complete chatOptions.modules.tabComplete = new chatOptions.module("Tab Complete", chatOptions.release.branch + "/ChatOptions/Modules/tabComplete.js", "gamedezyner"); // Custom Post Color chatOptions.modules.postColor = new chatOptions.module("Custom Post Color", chatOptions.release.branch + "/ChatOptions/Modules/postColor.js", "gamedezyner"); // AFK Button chatOptions.modules.afkButton = new chatOptions.module("AFK Button", chatOptions.release.branch + "/ChatOptions/Modules/afkButton.js", "gamedezyner");

// Initialize the script chatOptions.load;