diff --git a/script.js b/script.js index 433c67b7..37443da2 100644 --- a/script.js +++ b/script.js @@ -14,8 +14,9 @@ if ( injectNeeded ) { // Global Variables // ----------------- -var CSS = /\.([\w\-_]+) \{content:.*?"([^"]+)";.*?background-image: url\("([^"]+)"\);.*?height:.*?(\d+).+?width:.*?(\d+)[^}]*\}/mg, +var CSS = /\.([\w\-_]+)\s*?\{content:\s*?"([^"]+)";\s*?background-image:\s*?url\("([^"]+)"\);\s*?height:\s*?(\d+)px;\s*?width:\s*?(\d+)[^}]*\}/mg, IMGUR_KEY = 'e48d122e3437051', CACHE_LENGTH = 10800000, + SERVER = '//commondatastorage.googleapis.com/frankerfacez/', DEBUG = location.search.indexOf('frankerfacez') !== -1; @@ -96,12 +97,6 @@ ffz.prototype.init = function(increment, delay) { // hook into the Twitch Ember application. if ( !this.alive ) return; - // A secondary check for old chat. - if ( window.CurrentChat && window.CurrentChat.emoticons ) { - this.log("Detected old chat. Injecting old FFZ."); - return this.inject_old(); - } - var loaded = window.Ember != undefined && window.App != undefined && App.EmoticonsController != undefined && @@ -117,31 +112,9 @@ ffz.prototype.init = function(increment, delay) { return; } - // Inject the old FFZ script if we can't use new chat. - if ( App.hasOwnProperty('useNewChat') && !App.useNewChat ) { - this.log("Detected old chat. Injecting old FFZ."); - return this.inject_old(); - } - this.setup(); }; -ffz.prototype.inject_old = function() { - if ( this._dom ) - document.removeEventListener("DOMContentLoaded", this._dom, false); - - if ( !document.body ) { - this._dom = this.inject_old.bind(this); - document.addEventListener("DOMContentLoaded", this._dom, false); - return; - } - - var s = document.createElement('script'); - s.src = "//commondatastorage.googleapis.com/frankerfacez/script/old-frankerfacez.js"; - document.body.appendChild(s); - document.body.removeChild(s); -} - ffz.prototype.setup = function() { if ( !this.alive ) return; @@ -620,7 +593,7 @@ ffz.prototype.modify_viewers = function() { ffz.prototype._modify_emotes = function(ec) { var f = this; ec.reopen({ - _emoticons: [], + _emoticons: ec.emoticons || [], init: function() { this._super(); @@ -714,7 +687,12 @@ ffz.prototype.alter_tmi = function(id, tmi) { // ----------------- ffz.prototype.load_emotes = function(group, refresh) { - this.get("//commondatastorage.googleapis.com/frankerfacez/" + group + ".css", + // TEMPORARY GROUP CHAT + var m = /^_(.+)_\d+$/.exec(group), name = group; + if ( m != null ) + name = m[1]; + + this.get(SERVER + name + ".css", this.process_css.bind(this, group, undefined), refresh ? 1 : CACHE_LENGTH); } @@ -874,7 +852,7 @@ ffz.prototype.unload_emotes = function(group) { ffz.prototype.check_donor = function(username) { return this.donors[username] || false; } ffz.prototype.load_donors = function(refresh) { - this.get("//commondatastorage.googleapis.com/frankerfacez/donors.txt", + this.get(SERVER + "donors.txt", this.process_donors.bind(this), refresh ? 1 : CACHE_LENGTH); } diff --git a/script.min.js b/script.min.js index 3b0bfcb5..0b57607e 100644 --- a/script.min.js +++ b/script.min.js @@ -1,31 +1,30 @@ -(function wrapper(l,t){if(t){var p=document.createElement("script");p.textContent="("+wrapper+")(window, false)";document.body.appendChild(p);document.body.removeChild(p)}else{var u=/\.([\w\-_]+) \{content:.*?"([^"]+)";.*?background-image: url\("([^"]+)"\);.*?height:.*?(\d+).+?width:.*?(\d+)[^}]*\}/mg,r=-1!==location.search.indexOf("frankerfacez"),d=function(){this.alive=!0;this.donors={};this.getting={};this.emoticons=[];this.emotesets={};this.channels={};this.collections={};this.globals={};this.global_sets= -[];this.styles={};this.pending_styles=[];this._log=[];this._log2=[];this.init(10)};d.prototype.last_set=0;d.prototype.last_emote=0;d.prototype.manger=null;d.prototype.has_bttv=!1;d.commands={};d.prototype.log=function(b){this._log.push(b);b="FFZ"+(this.alive?": ":" (Dead): ")+b;console.log(b);if(r){var c,a;for(a in this.channels)if(this.channels[a]&&this.channels[a].room){c=this.channels[a];break}c?c.room.addTmiMessage(b):this._log2.push(b)}};d.prototype.init=function(b,c){if(this.alive){if(l.CurrentChat&& -l.CurrentChat.emoticons)return this.log("Detected old chat. Injecting old FFZ."),this.inject_old();if(void 0==l.Ember||void 0==l.App||void 0==App.EmoticonsController||void 0==App.Room)6E4<=c?this.log('Twitch API not detected in "'+location.toString()+'". Aborting.'):setTimeout(this.init.bind(this,b,(c||0)+b),b);else{if(App.hasOwnProperty("useNewChat")&&!App.useNewChat)return this.log("Detected old chat. Injecting old FFZ."),this.inject_old();this.setup()}}};d.prototype.inject_old=function(){this._dom&& -document.removeEventListener("DOMContentLoaded",this._dom,!1);if(document.body){var b=document.createElement("script");b.src="//commondatastorage.googleapis.com/frankerfacez/script/old-frankerfacez.js";document.body.appendChild(b);document.body.removeChild(b)}else this._dom=this.inject_old.bind(this),document.addEventListener("DOMContentLoaded",this._dom,!1)};d.prototype.setup=function(){this.alive&&(this.log("Hooking Ember application."),this.modify_room(),this.modify_viewers(),this.modify_emotes(), -this.modify_lines(),this.log("Loading data."),this.load_donors(),this.load_emotes("global"),document.body||(this.listen_dom=this.listen_dom.bind(this),document.addEventListener("DOMContentLoaded",this.listen_dom,!1)),this.find_bttv(10),this.log("Initialization complete."))};d.prototype.destroy=function(){this.alive&&(alive=!1,l.ffz===this&&(l.ffz=void 0),delete this._log,delete this._log2)};d.prototype.listen_dom=function(){for(document.removeEventListener("DOMContentLoaded",this.listen_dom,!1);this.pending_styles.length;)document.body.appendChild(this.pending_styles.pop())}; -d.prototype._msg=function(b,c){if(this.has_bttv)return BetterTTV.chat.helpers.serverMessage(c.replace(/\n/g,"
"));c=c.split("\n");for(var a=0;a'+f+""):a+(f+"\n"),e=this.collections[f],n;for(n in e)if(e.hasOwnProperty(n)){var k=e[n], -m=k.text;g?a+=''+m+""+k.image.html+"":(m=m[0]+"\u200b"+m.substr(1),a+=" "+m+" = "+k.text+"\n")}g&&(a+="")}}g&&(a+="");return-1===a.indexOf(g?"":"\u200b")?"There are no available FFZ channel emoticons. If this is in error, please try the /ffz reload command.":"The following emotes are available:\n"+a};d.commands.list.help="Usage: /ffz list [global]\nList available FFZ emoticons. Use the global parameter to list ALL FFZ emoticons, or filter for a specific set."; -d.commands.global=function(b,c){return d.commands.list.bind(this)(b,["global"])};d.commands.global.help="Usage: /ffz global\nShorthand for /ffz list global. List ALL FFZ emoticons, including FFZ global emoticons.";d.commands.reload=function(b,c){for(var a in this.channels)this.channels.hasOwnProperty(a)&&this.channels[a]&&this.load_emotes(a,!0);this.load_emotes("global");this.load_donors();return"Attempting to reload FFZ data from the server."};d.commands.reload.help="Usage: /ffz reload\nAttempt to reload FFZ emoticons and donors."; -d.commands.inject=function(b,c){if(!c||1!==c.length)return"/ffz inject requires exactly 1 argument.";var a=c[0].split("/").pop().split("?").shift().split("#").shift();this._msg(b,'Attempting to load test emoticons from imgur album "'+a+'"...');var d="https://api.imgur.com/3/album/"+a;l.localStorage&&localStorage.removeItem("ffz_"+d);this.get(d,this.do_imgur.bind(this,b,a),1,{Accept:"application/json",Authorization:"Client-ID e48d122e3437051"},5)};d.commands.inject.help="Usage: /ffz inject [album-id]\nLoads emoticons from an imgur album for testing. album-id can simply be the album URL. Ex: /ffz inject http://imgur.com/a/v4aZr"; -d.prototype.do_imgur=function(b,c,a){if(void 0===a)return this._msg(b,"An error occurred communicating with Imgur.");if(!a)return this._msg(b,"The named album does not exist or is private.");a=JSON.parse(a).data;a=a.images;for(var h="",g=0;g',id:--k.last_emote};a="!"===e[e.length-1]?RegExp("\\b"+e+"(?=\\W|$)","g"):RegExp("\\b"+e+"\\b","g");e={image:h,images:[h],text:e,channel:c,hidden:!1,regex:a,ffzset:b};m.push(e);k.emoticons.push(e);f.push({isEmoticon:!0,cls:d,regex:a});l++});this.log("Loaded "+l+" emotes from collection: "+ -b);return l}};d.prototype.unload_emotes=function(b){if(this.alive){var c=this.channels[b],a,d,g;if(!1!==c){c?(a=c.set_id,d=c.style,g="FFZ Channel Emotes: "+b,delete c.set,delete c.set_id,delete c.style):(a=this.globals[b],d=this.styles[b],g="FFZ Global Emotes"+("global"!=b?": "+b:""),delete this.globals[b],delete this.styles[b],c=this.global_sets.indexOf(a),-1!==c&&this.global_sets.splice(c,1));this.collections[g]&&delete this.collections[g];if(d)try{d.parentNode.removeChild(d)}catch(f){}delete this.emotesets[a]; -this.manager&&delete this.manager.emoticonSets[a];this.emoticons=this.emoticons.filter(function(a){return a.ffzgroup!==b})}}};d.prototype.check_donor=function(b){return this.donors[b]||!1};d.prototype.load_donors=function(b){this.get("//commondatastorage.googleapis.com/frankerfacez/donors.txt",this.process_donors.bind(this),b?1:108E5)};d.prototype.process_donors=function(b){if(this.alive){this.donors={};var c=0;if(null!=b){b=b.trim().split(/\W+/);for(var a=0;aa?(this.log("Resource expired. Fetching: "+ -b),this.do_get(b,c,0,d,g)):this.getting[b]=!1}};d.prototype.do_get=function(b,c,a,d,g){function f(){var e=(a||0)+1;if(!g||e<=g)return setTimeout(k.do_get.bind(k,b,c,e,d,g),1E3),!0}if(this.alive){var e=new XMLHttpRequest;e.open("GET",b);if(d)for(var n in d)d.hasOwnProperty(n)&&e.setRequestHeader(n,d[n]);var k=this;e.addEventListener("error",function(a){if(!f()){k.getting[b]=!1;try{c(void 0)}catch(d){k.log("Error in callback: "+d)}}},!1);e.addEventListener("load",function(a){if(200===e.status){if(a= -e.responseText,l.localStorage){var d=localStorage.getItem("ffz_last_"+b),g=e.getResponseHeader("Last-Modified");if(d&&d==g){k.log("Resource not modified: "+b);localStorage.setItem("ffz_age_"+b,(new Date).getTime());k.getting[b]=!1;return}localStorage.setItem("ffz_last_"+b,g)}}else{if(304===e.status){k.log("Resource not modified: "+b);l.localStorage&&localStorage.setItem("ffz_age_"+b,(new Date).getTime());k.getting[b]=!1;return}if(404===e.status)a=null;else{if(f())return;a=void 0}}l.localStorage&& -void 0!==a&&(localStorage.setItem("ffz_"+b,JSON.stringify(a)),localStorage.setItem("ffz_age_"+b,(new Date).getTime()));k.getting[b]=!1;try{c(a)}catch(h){k.log("Error in callback: "+h)}},!1);e.send()}else this.getting[b]=!1};l.ffz=new d}})(this.unsafeWindow||window,window.chrome?!0:!1); \ No newline at end of file +(function wrapper(m,t){if(t){var p=document.createElement("script");p.textContent="("+wrapper+")(window, false)";document.body.appendChild(p);document.body.removeChild(p)}else{var u=/\.([\w\-_]+)\s*?\{content:\s*?"([^"]+)";\s*?background-image:\s*?url\("([^"]+)"\);\s*?height:\s*?(\d+)px;\s*?width:\s*?(\d+)[^}]*\}/mg,r=-1!==location.search.indexOf("frankerfacez"),c=function(){this.alive=!0;this.donors={};this.getting={};this.emoticons=[];this.emotesets={};this.channels={};this.collections={};this.globals= +{};this.global_sets=[];this.styles={};this.pending_styles=[];this._log=[];this._log2=[];this.init(10)};c.prototype.last_set=0;c.prototype.last_emote=0;c.prototype.manger=null;c.prototype.has_bttv=!1;c.commands={};c.prototype.log=function(b){this._log.push(b);b="FFZ"+(this.alive?": ":" (Dead): ")+b;console.log(b);if(r){var d,a;for(a in this.channels)if(this.channels[a]&&this.channels[a].room){d=this.channels[a];break}d?d.room.addTmiMessage(b):this._log2.push(b)}};c.prototype.init=function(b,d){this.alive&& +(void 0==m.Ember||void 0==m.App||void 0==App.EmoticonsController||void 0==App.Room?6E4<=d?this.log('Twitch API not detected in "'+location.toString()+'". Aborting.'):setTimeout(this.init.bind(this,b,(d||0)+b),b):this.setup())};c.prototype.setup=function(){this.alive&&(this.log("Hooking Ember application."),this.modify_room(),this.modify_viewers(),this.modify_emotes(),this.modify_lines(),this.log("Loading data."),this.load_donors(),this.load_emotes("global"),document.body||(this.listen_dom=this.listen_dom.bind(this), +document.addEventListener("DOMContentLoaded",this.listen_dom,!1)),this.find_bttv(10),this.log("Initialization complete."))};c.prototype.destroy=function(){this.alive&&(alive=!1,m.ffz===this&&(m.ffz=void 0),delete this._log,delete this._log2)};c.prototype.listen_dom=function(){for(document.removeEventListener("DOMContentLoaded",this.listen_dom,!1);this.pending_styles.length;)document.body.appendChild(this.pending_styles.pop())};c.prototype._msg=function(b,d){if(this.has_bttv)return BetterTTV.chat.helpers.serverMessage(d.replace(/\n/g, +"
"));d=d.split("\n");for(var a=0;a'+f+""):a+(f+"\n"),e=this.collections[f],l;for(l in e)if(e.hasOwnProperty(l)){var k=e[l],n=k.text;c?a+=''+n+""+k.image.html+"":(n=n[0]+"\u200b"+ +n.substr(1),a+=" "+n+" = "+k.text+"\n")}c&&(a+="")}}c&&(a+="");return-1===a.indexOf(c?"":"\u200b")?"There are no available FFZ channel emoticons. If this is in error, please try the /ffz reload command.":"The following emotes are available:\n"+a};c.commands.list.help="Usage: /ffz list [global]\nList available FFZ emoticons. Use the global parameter to list ALL FFZ emoticons, or filter for a specific set.";c.commands.global=function(b,d){return c.commands.list.bind(this)(b,["global"])}; +c.commands.global.help="Usage: /ffz global\nShorthand for /ffz list global. List ALL FFZ emoticons, including FFZ global emoticons.";c.commands.reload=function(b,d){for(var a in this.channels)this.channels.hasOwnProperty(a)&&this.channels[a]&&this.load_emotes(a,!0);this.load_emotes("global");this.load_donors();return"Attempting to reload FFZ data from the server."};c.commands.reload.help="Usage: /ffz reload\nAttempt to reload FFZ emoticons and donors.";c.commands.inject=function(b,d){if(!d||1!==d.length)return"/ffz inject requires exactly 1 argument."; +var a=d[0].split("/").pop().split("?").shift().split("#").shift();this._msg(b,'Attempting to load test emoticons from imgur album "'+a+'"...');var c="https://api.imgur.com/3/album/"+a;m.localStorage&&localStorage.removeItem("ffz_"+c);this.get(c,this.do_imgur.bind(this,b,a),1,{Accept:"application/json",Authorization:"Client-ID e48d122e3437051"},5)};c.commands.inject.help="Usage: /ffz inject [album-id]\nLoads emoticons from an imgur album for testing. album-id can simply be the album URL. Ex: /ffz inject http://imgur.com/a/v4aZr"; +c.prototype.do_imgur=function(b,d,a){if(void 0===a)return this._msg(b,"An error occurred communicating with Imgur.");if(!a)return this._msg(b,"The named album does not exist or is private.");a=JSON.parse(a).data;a=a.images;for(var g="",h=0;h',id:--k.last_emote};a="!"===e[e.length-1]?RegExp("\\b"+e+"(?=\\W|$)","g"):RegExp("\\b"+e+"\\b","g");e={image:g,images:[g],text:e,channel:d,hidden:!1,regex:a,ffzset:b};n.push(e);k.emoticons.push(e); +f.push({isEmoticon:!0,cls:c,regex:a});l++});this.log("Loaded "+l+" emotes from collection: "+b);return l}};c.prototype.unload_emotes=function(b){if(this.alive){var d=this.channels[b],a,c,h;if(!1!==d){d?(a=d.set_id,c=d.style,h="FFZ Channel Emotes: "+b,delete d.set,delete d.set_id,delete d.style):(a=this.globals[b],c=this.styles[b],h="FFZ Global Emotes"+("global"!=b?": "+b:""),delete this.globals[b],delete this.styles[b],d=this.global_sets.indexOf(a),-1!==d&&this.global_sets.splice(d,1));this.collections[h]&& +delete this.collections[h];if(c)try{c.parentNode.removeChild(c)}catch(f){}delete this.emotesets[a];this.manager&&delete this.manager.emoticonSets[a];this.emoticons=this.emoticons.filter(function(a){return a.ffzgroup!==b})}}};c.prototype.check_donor=function(b){return this.donors[b]||!1};c.prototype.load_donors=function(b){this.get("//commondatastorage.googleapis.com/frankerfacez/donors.txt",this.process_donors.bind(this),b?1:108E5)};c.prototype.process_donors=function(b){if(this.alive){this.donors= +{};var d=0;if(null!=b){b=b.trim().split(/\W+/);for(var a=0;aa?(this.log("Resource expired. Fetching: "+b),this.do_get(b,d,0,c,h)):this.getting[b]=!1}};c.prototype.do_get=function(b,d,a,c,h){function f(){var e=(a||0)+1;if(!h||e<=h)return setTimeout(k.do_get.bind(k,b,d,e,c,h),1E3),!0}if(this.alive){var e=new XMLHttpRequest;e.open("GET",b);if(c)for(var l in c)c.hasOwnProperty(l)&&e.setRequestHeader(l,c[l]);var k=this;e.addEventListener("error",function(a){if(!f()){k.getting[b]=!1;try{d(void 0)}catch(c){k.log("Error in callback: "+ +c)}}},!1);e.addEventListener("load",function(a){if(200===e.status){if(a=e.responseText,m.localStorage){var c=localStorage.getItem("ffz_last_"+b),g=e.getResponseHeader("Last-Modified");if(c&&c==g){k.log("Resource not modified: "+b);localStorage.setItem("ffz_age_"+b,(new Date).getTime());k.getting[b]=!1;return}localStorage.setItem("ffz_last_"+b,g)}}else{if(304===e.status){k.log("Resource not modified: "+b);m.localStorage&&localStorage.setItem("ffz_age_"+b,(new Date).getTime());k.getting[b]=!1;return}if(404=== +e.status)a=null;else{if(f())return;a=void 0}}m.localStorage&&void 0!==a&&(localStorage.setItem("ffz_"+b,JSON.stringify(a)),localStorage.setItem("ffz_age_"+b,(new Date).getTime()));k.getting[b]=!1;try{d(a)}catch(h){k.log("Error in callback: "+h)}},!1);e.send()}else this.getting[b]=!1};m.ffz=new c}})(this.unsafeWindow||window,window.chrome?!0:!1); \ No newline at end of file