-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOptions.js
389 lines (377 loc) · 15.4 KB
/
Options.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
/**
* Wikia ChatPlugins
* 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
* minor modifications by Dragonfree97
*/
if (typeof(chatPluginsCustom)!="undefined") {
if (typeof(chatPluginsCustom.staffIcon)=="undefined") {
chatPluginsCustom.staffIcon = "http://img1.wikia.nocookie.net/__cb20140626173406/gamedezyner/images/6/60/StaffIcon.png";
}
if (typeof(chatPluginsCustom.modIcon)=="undefined") {
chatPluginsCustom.modIcon= "http://img1.wikia.nocookie.net/__cb20140626173343/gamedezyner/images/8/89/ModIcon.png";
}
if (typeof(chatPluginsCustom.pingSound)=="undefined") {
chatPluginsCustom.pingSound = "http://images.wikia.com/gamedezyner/images/7/7e/PingSound.ogg";
}
if (typeof(chatPluginsCustom.loadedFrom)=="undefined") {
chatPluginsCustom.loadedFrom = "chat.js";
}
}
else {
chatPluginsCustom = {
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",
loadedFrom: "MediaWiki:Chat.js"
}
}
var chatPlugins = {
release: {
version: 0.7
},
custom: {
staffIcon: chatPluginsCustom.staffIcon,
modIcon: chatPluginsCustom.modIcon,
pingSound: chatPluginsCustom.pingSound
// horsedModules: chatPluginsCustom.horsedModules,
// horsedSettings: chatPluginsCustom.horsedSettings,
// disabledModules: chatPluginsCustom.disabledModules
},
module: function(name, loadScript, loadWiki) {
this.enabled = function() {
return chatPlugins.cookie.arrays.modules[this.id];
}
this.id = Object.keys(chatPlugins.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(chatPlugins.pages.list)) {
api.functions.editPage("User:" + wgUserName + "/ChatPlugins/" + chatPlugins.pages.list[Object.keys(chatPlugins.pages.list)[i]].name,chatPlugins.pages.list[Object.keys(chatPlugins.pages.list)[i]].value);
}
},
load: function() { // Save all registered cookie arrays to respective cookies
for (i in Object.keys(chatPlugins.pages.list)) {
if (typeof(api.functions.getPageContents("User:" + wgUserName + "/ChatPlugins/" + chatPlugins.pages.list[Object.keys(chatPlugins.pages.list)[i]].name))!="string") {
var content = "";
}
else {
content = api.functions.getPageContents("User:" + wgUserName + "/ChatPlugins/" + chatPlugins.pages.list[Object.keys(chatPlugins.pages.list)[i]].name);
}
chatPlugins.pages.list[Object.keys(chatPlugins.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(chatPlugins.cookie.arrays)) {
chatPlugins.cookie.arrays[Object.keys(chatPlugins.cookie.arrays)[i]] = chatPlugins.cookie.get("chatPlugins"+Object.keys(chatPlugins.cookie.arrays)[i].charAt(0).toUpperCase() + Object.keys(chatPlugins.cookie.arrays)[i].slice(1)).split(",");
}
},
save: function() { // Save all registered cookie arrays to respective cookies
for (i in Object.keys(chatPlugins.cookie.arrays)) {
chatPlugins.cookie.set("chatPlugins"+Object.keys(chatPlugins.cookie.arrays)[i].charAt(0).toUpperCase() + Object.keys(chatPlugins.cookie.arrays)[i].slice(1),chatPlugins.cookie.arrays[Object.keys(chatPlugins.cookie.arrays)[i]].toString());
}
},
reset: function () { //Reset cookie data to default
modules = Object.keys(chatPlugins.modules);
for ( i in Object.keys(chatPlugins.modules) ) {
module = chatPlugins.modules[modules[i]];
chatPlugins.cookie.arrays.modules[module.id] = 0;
}
chatPlugins.cookie.arrays.version[0] = chatPlugins.release.version;
chatPlugins.cookie.save();
}
},
menu: {
loaded: false,
load: function() {
$(".chattopic").append('<ul id="chatPluginsMenu" class="chatPluginsMenu" style="position:absolute;right:150px;top:20px;z-index:99;padding:5px;border: solid 2px ' + $('body').css("background-color") + ';font-size:12px;color:' + $('#WikiaPage').css("color") + ';background-color:' + $('#WikiaPage').css("background-color") + ';display:none;"></ul>');
$(".chatPluginsMenu").mouseover(function() {$('#chatPluginsMenu').css('display','block')});
$(".chatPluginsMenu").mouseout(function() {$('#chatPluginsMenu').css('display','none')});
chatPlugins.menu.loaded = true;
},
add: function(id, title) {
if (!chatPlugins.menu.loaded) {
chatPlugins.menu.load();
}
$('#chatPluginsMenu').append('<li><a id="' + id + '" href="#">' + title + '</a></li>');
$('#'+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", '<form method="" name="" class="WikiaForm "><fieldset>' +
'<div id="chatPluginsHeader">Please select the features you would like to enable:</div>' +
'<table id="chatPluginsTable"></table>' +
'<div>Note: Clicking Save will refresh the chat.</div></fieldset></form>', {
id: "optionsWindow",
width: 600,
buttons: [
{
id: "cancel",
message: "Cancel",
handler: chatPlugins.menu.cancel
},
{
id: "save",
defaultButton: true,
message: "Save",
handler: chatPlugins.menu.save
}
]
});
$(".close").click(chatPlugins.menu.cancel);
$(".blackout").click(chatPlugins.menu.cancel);
$(".blackout").addClass("chatPlugins");
chatPluginsTable = "";
modules = Object.keys(chatPlugins.modules);
for (i=0;i<modules.length;i++) {
module = chatPlugins.modules[modules[i]];
if (i%2) {
chatPluginsTable += '<td style="padding:2px;"><label><input class="chatOption" type="checkbox" name="' + module.name + '" value="' + module.name + '"/>Enable ' + module.name + '</label>';
if (typeof(module.settingsID)!="undefined"){
chatPluginsTable += ' <a href="#" style="font-size:8pt;font-style:italic" id="' + module.settingsID + '">(Settings)</a>';
}
chatPluginsTable += '</td></tr>';
}
else {
chatPluginsTable += '<tr><td style="padding:2px;"><label><input class="chatOption" type="checkbox" name="' + module.name + '" value="' + module.name + '"/>Enable ' + module.name + '</label>';
if (typeof(module.settingsID)!="undefined"){
chatPluginsTable += ' <a href="#" style="font-size:8pt;font-style:italic" id="' + module.settingsID + '">(Settings)</a>';
}
chatPluginsTable += '</td>';
}
if ((modules.length % 2)!=1) {
chatPluginsTable += '</tr>';
}
$('#chatPluginsTable').html(chatPluginsTable);
}
for (i=0;i<modules.length;i++) {
module = chatPlugins.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(chatPlugins.menu.cancel);
}
},
save: function() {
modules = Object.keys(chatPlugins.modules);
checked = $(".chatOption:checked");
unchecked = $(".chatOption:not(:checked)");
cookieString = "";
for ( i in Object.keys(chatPlugins.modules) ) {
module = chatPlugins.modules[modules[i]];
if ($('input[name="' + module.name + '"]:checked').length > 0) {
chatPlugins.cookie.arrays.modules[module.id] = 1;
}
else {
chatPlugins.cookie.arrays.modules[module.id] = 0;
}
}
chatPlugins.cookie.save();
chatPlugins.menu.cancel();
if (chatPluginsCustom.loadedFrom == "w:c:Special:MyPage/global.js") {
chatPlugins.reload();
}
else {
window.location.reload();
}
},
cancel: function() {
$('#optionsWindow').remove();
$('.blackout.chatPlugins').remove();
}
},
load: function() {
if (typeof(chatPlugins.cookie.get("chatPluginsVersion"))=="undefined") { // Is ChatPlugins version saved in cookie? If not, initialize cookies for first time and continue loading.
chatPlugins.cookie.reset();
console.log('[OPTIONS] Cookies initialized for first run');
chatPlugins.loading = true;
}
else {
if (isNaN(parseFloat(chatPlugins.cookie.get("chatPluginsVersion")))) { // Is ChatPlugins version cookie invalid? If so, reset cookies to default values and continue loading.
chatPlugins.cookie.reset();
console.log('[OPTIONS] Error: Cookies invalid. Resetting cookies');
chatPlugins.loading = true;
}
else {
if (parseFloat(chatPlugins.cookie.get("chatPluginsVersion"))==chatPlugins.release.version) { // Is ChatPlugins version the same as last load? If so, log and continue loading.
console.log('[OPTIONS] Cookies valid. Loading options');
chatPlugins.loading = true;
}
if (parseFloat(chatPlugins.cookie.get("chatPluginsVersion"))<chatPlugins.release.version) { // Is ChatPlugins version newer than last load? If so, alert the user to the upgrade and continue loading.
chatPlugins.cookie.set("chatPluginsVersion",chatPlugins.release.version.toString());
chatPlugins.loading = true;
}
}
}
if (chatPlugins.loading) {
chatPlugins.cookie.load();
modules = Object.keys(chatPlugins.modules);
for (i = 0; i < Object.keys(chatPlugins.modules).length; i++) {
module = chatPlugins.modules[modules[i]];
if (module.enabled() == true) {
module.load();
}
}
if( !$(".chatPluginsMenu.topiclink").length ) {
$("div.chattopic").append(' • <a href="#" id="chatPluginsButton" class="chatPluginsMenu topiclink"><img src="http://vignette1.wikia.nocookie.net/clubpenguin/images/8/8b/Options.png/revision/latest?cb=20160117105154" height="12px" class="optionsimage chattopic-icon" /> options</a>');
}
if (chatPluginsCustom.loadedFrom == "w:c:Special:MyPage/global.js" || chatPluginsCustom.loadedFrom == "bookmark") {
$("#ChatHeader .public.wordmark").append('<a href="#" id="chatRefreshButton"><img src="http://img4.wikia.nocookie.net/__cb20140818203356/gamedezyner/images/a/a9/ChatPluginsRefreshButton.png" height="32px"/></a>');
$("#chatRefreshButton").click(function() {
chatPlugins.reload();
});
function disableF5(e) {
if ((e.which || e.keyCode) == 116) {
e.preventDefault();
chatPlugins.reload();
}
};
$(document).on("keydown", disableF5);
}
$("#chatPluginsButton").click(chatPlugins.menu.open);
chatPlugins.loading = false;
chatPlugins.loaded = true;
var bgcolor = $("body").css("background-color");
bgcolor = bgcolor.substring(4, bgcolor.length-1).replace(/ /g, '').split(',');
var bgbrightness = Math.round(((parseInt(bgcolor[0]) * 299) + (parseInt(bgcolor[1]) * 587) + (parseInt(bgcolor[2]) * 114)) /1000);
if (bgbrightness < 125) {
$("#chatPluginsInfo").css("color","white");
$("#chatPluginsInfoLink").css("color","lightblue");
}
else {
$("#chatPluginsInfo").css("color","black");
$("#chatPluginsInfoLink").css("color","#006cb0");
}
console.log('[OPTIONS] Loading successful');
}
},
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 "><fieldset><div id="settingsHeader"></div>' + content + '</fieldset></form>', {
id: "settingsWindow",
width: width,
buttons: [
{
id: "cancel",
message: "Cancel",
handler: chatPlugins.settings.cancel
},
{
id: "save",
defaultButton: true,
message: "Save",
handler: save
}
]
});
$(".close").click(chatPlugins.settings.cancel);
$(".blackout:not(.chatPlugins)").addClass("chatSettings")
},
cancel: function() {
$('#settingsWindow').remove();
$(".blackout.chatSettings").remove()
}
},
reload: function() {
window.chatwindow = window.open('/wiki/Special:Chat?useskin=wikia', wgDBname + 'chat' + Math.round(Math.random()*100));
window.chatwindow.onload = function () {
window.chatwindow.importScriptPage('User:' + wgUserName + '/global.js', 'c');
window.chatwindow.importScriptPage('User:' + wgUserName + '/wikia.js');
if (api.functions.getPageContents("MediaWiki:Chat.js").indexOf("Stable/ChatPlugins/code.js")==-1) {
window.chatwindow.chatPluginsCustom = {
loadedFrom: chatPluginsCustom.loadedFrom
}
window.chatwindow.importScriptPage('Testing/ChatPlugins/code.js', 'gamedezyner');
}
}
window.chatwindow.closeopener = true;
}
};
// Append Chat Options Button to header
// Register our Modules
// Pings
chatPlugins.modules.pings = new chatPlugins.module("pings", "Mediawiki:chat.js/pings.js", "clubpenguin");
// Multi PM
chatPlugins.modules.multiPM = new chatPlugins.module("multi PM", "Mediawiki:chat.js/multiPM.js", "clubpenguin");
// Multi Kick
chatPlugins.modules.multiKick = new chatPlugins.module("multi kick", "Mediawiki:chat.js/multiKick.js", "clubpenguin");
chatPlugins.modules.multiKick.modOnly = true;
// Chat Style
chatPlugins.modules.style = new chatPlugins.module("Style", "Mediawiki:chat.js/style.js", "clubpenguin");
// Tab Complete
chatPlugins.modules.tabComplete = new chatPlugins.module("Tab Complete", "Mediawiki:chat.js/tabComplete.js", "clubpenguin");
// Slash Commands
chatPlugins.modules.slashCommands = new chatPlugins.module("Slash Commands", "Mediawiki:chat.js/slashCommands.js", "clubpenguin");
// Search Bar
chatPlugins.modules.slashCommands = new chatPlugins.module("Search Bar", "Mediawiki:chat.js/searchBar.js", "clubpenguin");
// Chat Hacks
chatPlugins.modules.slashCommands = new chatPlugins.module("Chat Hacks", "Mediawiki:chat.js/chatHacks.js", "clubpenguin");
// Load API plugin
if (typeof(api)=="undefined") {
importScriptPage('Stable/API/code.js', 'd97');
}
// If this is a reloaded window, kill old window
if (window.opener!=null) {
if(typeof(window.closeopener)!="undefined") {
window.opener.close();
}
}
// Initialize the script
chatPlugins.load();