User:Ultimate Dark Carnage/chat.js

importArticles(/*{   type: 'script',    articles: [        "u:dev:MessageBlocker/code.js",        "u:c:User:Ultimate_Dark_Carnage/commands.js",        "u:c:User:Ultimate_Dark_Carnage/test.js",        "u:c:User:Ultimate_Dark_Carnage/sandbox2.js"    ] }, */{    'type': 'style',    articles: [        'u:c:User:Ultimate_Dark_Carnage/chat2.css'    ] });

$(document).ready(function{   var msg_no = 0;    localStorage.setItem('title', document.title);    $(window).on('blur', function{ $('.ChatWindow').on('DOMNodeInserted', '.Chat ul > li .message', function(event){           msg_no = msg_no + 1;            var original_title = localStorage.getItem('title');            document.title = '(' + msg_no + ') ' + original_title;        }); });   $(window).on('focus', function{ $('.ChatWindow').off('DOMNodeInserted'); msg_no = 0; var original_title = localStorage.getItem('title'); document.title = original_title; }); });

/*function ChatTemplate{ this.loaded = false; this.version = '1.0.1'; this.templates = { '': function{ var groups = mw.config.get('wgUserGroups', wgUserGroups); if (				groups.indexOf('chatmoderator') > -1 ||				groups.indexOf('sysop') > -1 ||				groups.indexOf('bureaucrat') > -1 ||				groups.indexOf('vstf') > -1 ||				groups.indexOf('helper') > -1 ||				groups.indexOf('staff') > -1				){ var audio = document.createElement('audio'); audio.innerHTML = ''; audio.autoplay = false; audio.className = 'ping ping-sound'; audio.onended = function(event){ if (event.target){ var parent = event.target.parentElement; parent.removeChild(event.target); }					};					if (document.body.className == 'ChatWindow') document.body.appendChild(audio); }		},		'': function(user){ if (user != 'self'){ mainRoom.kick({					userToKick: user				}); } else { mainRoom.kick({					userToKick: wgUserName				}); }		},		'': function(theme){ var DB = mw.config.get('wgDBName', wgDBName); DB = (DB == 'wikia') ? 'c' : DB; importStyleSheetPage('User:' + wgUserName + '/' + theme + '.css', DB); },		'': function(txt){ var messages = document.getElementsByClassName('message'); for (var i = 0; i < messages.length; i++){ if (messages[i].nodeName == 'SPAN' && i == (messages.length - 1)){ message[i].innerHTML = 'Spoiler ' + ' ' + txt + ' '; }			}			var spoilerButton = document.getElementsByClassName('spoiler'); for (var i = 0; i < spoilerButton.length; i++){ var btn = spoilerButton[i]; btn.onclick = function(event){ var txt = event.target.nextElementSibling || event.target.nextSibling, spState = 0; if (txt){ if (spState === 0 && getComputedStyle(txt)['display'] == 'none'){ txt.style['display'] = 'inline-block'; spState = 1; } else { txt.style['display'] = 'none'; spState = 0; }					}				};			}		},		'': wgUserName, '': function(user, mod, msg){ },		: ,		: 	}; }

ChatTemplate.prototype.addTemplate = function(obj){ var temp = Object.keys(this.templates), templates = this.templates; for (var t in obj){ if (temp.indexOf(t) === -1){ this.templates[t] = obj[t]; }	} };

ChatTemplate.prototype.removeTemplate = function(temp){ var keys = Object.keys(this.templates); if (keys.indexOf(temp) > -1){ delete this.templates[temp]; } };

ChatTemplate.prototype.parse = function(txt, obj){ var value = null; for (var temp in obj){ var t = new RegExp(temp, 'g'); if (txt.match(temp)){ if (temp.indexOf('(.*)') > -1){ if (typeof obj[temp] == 'function'){ var v = txt.replace(t, function(key, val1, val2, val3){						var val = null;						if (val2){							if (val3) val = [val1, val2, val3];							else val = [val1, val2];						} else val = val1;					}).split(','), v1 = Array.isArray(v) ? v[0] : v;					txt = mw.html.escape(txt); Function.prototype.apply.call(obj[temp], window, [v1, v[1], v[2]]); }				else value = txt.replace(t, obj[temp]); } else { if (typeof obj[temp] == 'function') Function.prototype.apply.call(obj[temp], window, []); else value = txt.replace(t, obj[temp]); }		}	}	if (value){ var messages = document.getElementsByClassName('message'); for (var i = 0; i < messages.length; i++){ if (messages[i].nodeName == 'SPAN' && i == (messages.length - 1)){ message[i].innerHTML = value; }		}	} };

ChatTemplate.prototype.load = function{ var c = this, c_temp = c.templates; mainRoom.model.chats.bind('afteradd', function(c){       if (c.attributes.text){            c.parse(c.attributes.text, c_temp);        }    }); };

var chat_templates = new ChatTemplate; chat_templates.load;