mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-06-28 15:27:43 +00:00
Added support for BetterTTV's chat handling.
This commit is contained in:
parent
faece54a91
commit
ef8052c246
2 changed files with 120 additions and 18 deletions
103
script.js
103
script.js
|
@ -55,6 +55,7 @@ var ffz = function() {
|
||||||
ffz.prototype.last_set = 0;
|
ffz.prototype.last_set = 0;
|
||||||
ffz.prototype.last_emote = 0;
|
ffz.prototype.last_emote = 0;
|
||||||
ffz.prototype.manger = null;
|
ffz.prototype.manger = null;
|
||||||
|
ffz.prototype.has_bttv = false;
|
||||||
|
|
||||||
ffz.commands = {};
|
ffz.commands = {};
|
||||||
|
|
||||||
|
@ -162,6 +163,9 @@ ffz.prototype.setup = function() {
|
||||||
document.addEventListener("DOMContentLoaded", this.listen_dom, false);
|
document.addEventListener("DOMContentLoaded", this.listen_dom, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Detect BetterTTV
|
||||||
|
this.find_bttv(10);
|
||||||
|
|
||||||
this.log("Initialization complete.");
|
this.log("Initialization complete.");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -198,7 +202,10 @@ ffz.prototype.listen_dom = function() {
|
||||||
// Commands
|
// Commands
|
||||||
// -----------------
|
// -----------------
|
||||||
|
|
||||||
var msg = function(room, out) {
|
ffz.prototype._msg = function(room, out) {
|
||||||
|
if ( this.has_bttv )
|
||||||
|
return BetterTTV.chat.helpers.serverMessage(out.replace(/\n/g, "<br>"));
|
||||||
|
|
||||||
out = out.split("\n");
|
out = out.split("\n");
|
||||||
for(var i=0; i < out.length; i++)
|
for(var i=0; i < out.length; i++)
|
||||||
room.addMessage({style: 'ffz admin', from: 'FFZ', message: out[i]});
|
room.addMessage({style: 'ffz admin', from: 'FFZ', message: out[i]});
|
||||||
|
@ -216,7 +223,7 @@ ffz.prototype.run_command = function(room, m) {
|
||||||
else
|
else
|
||||||
out = "No such sub-command.";
|
out = "No such sub-command.";
|
||||||
|
|
||||||
if ( out ) msg(room, out);
|
if ( out ) this._msg(room, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
ffz.commands['help'] = function(room, args) {
|
ffz.commands['help'] = function(room, args) {
|
||||||
|
@ -335,11 +342,13 @@ ffz.commands['log'] = function(room, args) {
|
||||||
ffz.commands['log'].help = "Usage: /ffz log\nOpen a window with FFZ's debugging output.";
|
ffz.commands['log'].help = "Usage: /ffz log\nOpen a window with FFZ's debugging output.";
|
||||||
|
|
||||||
ffz.commands['list'] = function(room, args) {
|
ffz.commands['list'] = function(room, args) {
|
||||||
var output = '', filter;
|
var output = '', filter, html = this.has_bttv;
|
||||||
|
|
||||||
if ( args && args.length > 0 )
|
if ( args && args.length > 0 )
|
||||||
filter = args.join(" ").toLowerCase();
|
filter = args.join(" ").toLowerCase();
|
||||||
|
|
||||||
|
if ( html ) output += "<table style=\"width:100%\">";
|
||||||
|
|
||||||
for(var name in this.collections) {
|
for(var name in this.collections) {
|
||||||
if ( ! this.collections.hasOwnProperty(name) )
|
if ( ! this.collections.hasOwnProperty(name) )
|
||||||
return;
|
return;
|
||||||
|
@ -353,19 +362,30 @@ ffz.commands['list'] = function(room, args) {
|
||||||
if ( !include )
|
if ( !include )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var em = this.collections[name];
|
if ( html )
|
||||||
|
output += "<thead><th colspan=\"2\">" + name + "</th></thead><tbody>";
|
||||||
|
else
|
||||||
output += name + "\n";
|
output += name + "\n";
|
||||||
|
|
||||||
|
var em = this.collections[name];
|
||||||
for(var e in em) {
|
for(var e in em) {
|
||||||
if ( em.hasOwnProperty(e) ) {
|
if ( em.hasOwnProperty(e) ) {
|
||||||
var emote = em[e], t = emote.text;
|
var emote = em[e], t = emote.text;
|
||||||
|
if ( html )
|
||||||
|
output += "<tr style=\"line-height:" + emote.image.height + "px\"><td>" + t + "</td><td>" + emote.image.html + "</td></tr>";
|
||||||
|
else {
|
||||||
t = t[0] + "\u200B" + t.substr(1);
|
t = t[0] + "\u200B" + t.substr(1);
|
||||||
output += " " + t + " = " + emote.text + "\n";
|
output += " " + t + " = " + emote.text + "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ( html ) output += "</tbody>";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( html ) output += "</table>";
|
||||||
|
|
||||||
// Make sure we actually have output.
|
// Make sure we actually have output.
|
||||||
if ( output.indexOf('\u200B') === -1 )
|
if ( output.indexOf(html ? '<td>' : '\u200B') === -1 )
|
||||||
return "There are no available FFZ channel emoticons. If this is in error, please try the /ffz reload command.";
|
return "There are no available FFZ channel emoticons. If this is in error, please try the /ffz reload command.";
|
||||||
else
|
else
|
||||||
return "The following emotes are available:\n" + output;
|
return "The following emotes are available:\n" + output;
|
||||||
|
@ -393,7 +413,7 @@ ffz.commands['inject'] = function(room, args) {
|
||||||
return "/ffz inject requires exactly 1 argument.";
|
return "/ffz inject requires exactly 1 argument.";
|
||||||
|
|
||||||
var album = args[0].split('/').pop().split('?').shift().split('#').shift();
|
var album = args[0].split('/').pop().split('?').shift().split('#').shift();
|
||||||
room.addMessage({style: 'ffz admin', message: "Attempting to load test emoticons from imgur album \"" + album + "\"..."});
|
this._msg(room, "Attempting to load test emoticons from imgur album \"" + album + "\"...");
|
||||||
|
|
||||||
// Make sure there's no cache hits.
|
// Make sure there's no cache hits.
|
||||||
var res = "https://api.imgur.com/3/album/" + album;
|
var res = "https://api.imgur.com/3/album/" + album;
|
||||||
|
@ -404,13 +424,13 @@ ffz.commands['inject'] = function(room, args) {
|
||||||
{'Accept': 'application/json', 'Authorization': 'Client-ID ' + IMGUR_KEY},
|
{'Accept': 'application/json', 'Authorization': 'Client-ID ' + IMGUR_KEY},
|
||||||
5);
|
5);
|
||||||
}
|
}
|
||||||
ffz.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";
|
ffz.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";
|
||||||
|
|
||||||
ffz.prototype.do_imgur = function(room, album, data) {
|
ffz.prototype.do_imgur = function(room, album, data) {
|
||||||
if ( data === undefined )
|
if ( data === undefined )
|
||||||
return msg(room, "An error occurred communicating with Imgur.");
|
return this._msg(room, "An error occurred communicating with Imgur.");
|
||||||
else if ( !data )
|
else if ( !data )
|
||||||
return msg(room, "The named album does not exist or is private.");
|
return this._msg(room, "The named album does not exist or is private.");
|
||||||
|
|
||||||
// Get our data structure.
|
// Get our data structure.
|
||||||
data = JSON.parse(data).data;
|
data = JSON.parse(data).data;
|
||||||
|
@ -438,8 +458,56 @@ ffz.prototype.do_imgur = function(room, album, data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var count = this.process_css('imgur-' + album, 'FFZ Global Emotes - Imgur Album: ' + album, css);
|
var count = this.process_css('imgur-' + album, 'FFZ Global Emotes - Imgur Album: ' + album, css);
|
||||||
msg(room, "Loaded " + count + " emoticons from Imgur.");
|
this._msg(room, "Loaded " + count + " emoticons from Imgur.");
|
||||||
msg(room, ffz.commands['list'].bind(this)(room, [album]));
|
this._msg(room, ffz.commands['list'].bind(this)(room, [album]));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// -----------------
|
||||||
|
// BetterTTV Hooks
|
||||||
|
// -----------------
|
||||||
|
|
||||||
|
ffz.prototype.find_bttv = function(increment, delay) {
|
||||||
|
if ( !this.alive ) return;
|
||||||
|
|
||||||
|
if ( window.BTTVLOADED )
|
||||||
|
return this.setup_bttv();
|
||||||
|
|
||||||
|
else if ( delay === undefined )
|
||||||
|
this.log("BetterTTV not yet loaded. Waiting...");
|
||||||
|
|
||||||
|
if ( delay >= 60000 )
|
||||||
|
this.log("BetterTTV not detected in \"" + location.toString() + "\". Giving up.");
|
||||||
|
else
|
||||||
|
setTimeout(this.find_bttv.bind(this, increment, (delay||0) + increment),
|
||||||
|
increment);
|
||||||
|
}
|
||||||
|
|
||||||
|
var donor_badge = {type: 'ffz-donor', name: '', description: 'FFZ Donor'};
|
||||||
|
|
||||||
|
ffz.prototype.setup_bttv = function() {
|
||||||
|
this.log("BetterTTV was detected. Installing hook.");
|
||||||
|
this.has_bttv = true;
|
||||||
|
|
||||||
|
// Add badge handling to BetterTTV chat.
|
||||||
|
var privmsg = BetterTTV.chat.templates.privmsg, f = this;
|
||||||
|
BetterTTV.chat.templates.privmsg = function(highlight, action, server, isMod, data) {
|
||||||
|
if ( f.check_donor(data.sender) ) {
|
||||||
|
var inserted = false;
|
||||||
|
for(var i=0; i < data.badges.length; i++) {
|
||||||
|
var t = data.badges[i].type;
|
||||||
|
if ( t != 'turbo' && t != 'subscriber' )
|
||||||
|
continue;
|
||||||
|
data.badges.insertAt(i, donor_badge);
|
||||||
|
inserted = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ( ! inserted )
|
||||||
|
data.badges.push(donor_badge);
|
||||||
|
}
|
||||||
|
|
||||||
|
return privmsg(highlight, action, server, isMod, data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -600,8 +668,9 @@ ffz.prototype.add_channel = function(id, room) {
|
||||||
|
|
||||||
// Do we have log messages?
|
// Do we have log messages?
|
||||||
if ( this._log2.length > 0 ) {
|
if ( this._log2.length > 0 ) {
|
||||||
|
var func = this.has_bttv ? BetterTTV.chat.helpers.serverMessage : room.addTmiMessage;
|
||||||
while ( this._log2.length )
|
while ( this._log2.length )
|
||||||
room.addTmiMessage(this._log2.shift());
|
func(this._log2.shift());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the emotes for this channel.
|
// Load the emotes for this channel.
|
||||||
|
@ -730,8 +799,9 @@ ffz.prototype.process_css = function(group, channel, data) {
|
||||||
this.log("Loaded " + count + " emotes from collection: " + group);
|
this.log("Loaded " + count + " emotes from collection: " + group);
|
||||||
|
|
||||||
// Notify the manager that we've added emotes.
|
// Notify the manager that we've added emotes.
|
||||||
if ( this.manager )
|
// Don't notify the manager for now because of BTTV.
|
||||||
this.manager.notifyPropertyChange('emoticons');
|
//if ( this.manager && ! this.has_bttv )
|
||||||
|
// this.manager.notifyPropertyChange('emoticons');
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
@ -791,8 +861,9 @@ ffz.prototype.unload_emotes = function(group) {
|
||||||
this.emoticons = this.emoticons.filter(filt);
|
this.emoticons = this.emoticons.filter(filt);
|
||||||
|
|
||||||
// Update the emoticons with the manager.
|
// Update the emoticons with the manager.
|
||||||
if ( this.manager )
|
// Don't notify the manager for now for BTTV.
|
||||||
this.manager.notifyPropertyChange('emoticons');
|
//if ( this.manager && ! this.has_bttv )
|
||||||
|
// this.manager.notifyPropertyChange('emoticons');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
31
script.min.js
vendored
Normal file
31
script.min.js
vendored
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
(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,"<br>"));c=c.split("\n");for(var a=0;a<c.length;a++)b.addMessage({style:"ffz admin",from:"FFZ",message:c[a]})};d.prototype.run_command=function(b,c){var a=(c.substr(5)||"list").split(" "),h=a.shift().toLowerCase();this.log("Got FFZ Command: "+h+" "+JSON.stringify(a));(a=(h=d.commands[h])?h.bind(this)(b,a):"No such sub-command.")&&this._msg(b,a)};d.commands.help=function(b,c){if(c&&0<c.length){var a=
|
||||||
|
d.commands[c[0].toLowerCase()];return a?a&&void 0==a.help?"No help available for: "+c[0]:a.help:"No such sub-command: "+c[0]}var h=[];for(a in d.commands)d.commands.hasOwnProperty(a)?h.push(a):!1;return"Available sub-commands are: "+h.join(", ")};d.commands.help.help="Usage: /ffz help [command]\nList available commands, or show help for a specific command.";d.commands.log=function(b,c){var a="FrankerFaceZ Session Log\n\n"+this._log.join("\n"),a=a+"\n\n--------------------------------------------------------------------------------\nInternal State\n\nChannels:\n",
|
||||||
|
h;for(h in this.channels)if(this.channels.hasOwnProperty(h)){var d=this.channels[h];if(d){a+=" "+h+":\n";a+=" set_id: "+d.set_id+"\n";if(d.set){for(var a=a+" set:\n",f=0;f<d.set.length;f++)var e=d.set[f],a=a+(" isEmoticon: "+e.isEmoticon+", cls: "+JSON.stringify(e.cls)+", regex: "+e.regex.toString()+"\n");a+="\n"}else a+=" set (Unloaded)\n";if(d.style){e=d.style.innerHTML.split("\n");a+=" style:\n";for(f=0;f<e.length;f++)a+=" "+e[f]+"\n";a+="\n"}else a+=" style (Unloaded)"}else a+=
|
||||||
|
" "+h+" (Unloaded)\n"}a+="\nGlobal Sets:\n";for(h in this.globals)if(this.globals.hasOwnProperty(h))if(f=this.globals[h]){a+=" "+h+":\n";a+=" set_id: "+f+"\n";if(d=this.emotesets[f]){a+=" set:\n";for(f=0;f<d.length;f++)e=d[f],a+=" isEmoticon: "+e.isEmoticon+", cls: "+JSON.stringify(e.cls)+", regex: "+e.regex.toString()+"\n";a+="\n"}else a+=" set (Unloaded)\n";if(f=this.styles[h]){e=f.innerHTML.split("\n");a+=" style:\n";for(f=0;f<e.length;f++)a+=" "+e[f]+"\n";a+="\n"}else a+=
|
||||||
|
" style (Unloaded)\n"}else a+=" "+h+" (Unloaded)\n";a+="\nEmotes:\n";for(f=0;f<this.emoticons.length;f++)e=this.emoticons[f],a+=" "+e.text+" ("+e.image.id+")\n",a+=" ffzset: "+e.ffzset+" ("+e.image.emoticon_set+")\n",a+=" channel: "+e.channel+"\n",a+=" regex: "+e.regex.toString()+"\n",a+=" height: "+e.image.height+", width: "+e.image.width+"\n",a+=" url: "+e.image.url+"\n",a+=" html: "+e.image.html+"\n\n";l.open("data:text/plain,"+encodeURIComponent(a),"_blank")};
|
||||||
|
d.commands.log.help="Usage: /ffz log\nOpen a window with FFZ's debugging output.";d.commands.list=function(b,c){var a="",d,g=this.has_bttv;c&&0<c.length&&(d=c.join(" ").toLowerCase());g&&(a+='<table style="width:100%">');for(var f in this.collections){if(!this.collections.hasOwnProperty(f))return;if(d?-1!==f.toLowerCase().indexOf(d):"FFZ Global Emotes"!==f){var a=g?a+('<thead><th colspan="2">'+f+"</th></thead><tbody>"):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+='<tr style="line-height:'+k.image.height+'px"><td>'+m+"</td><td>"+k.image.html+"</td></tr>":(m=m[0]+"\u200b"+m.substr(1),a+=" "+m+" = "+k.text+"\n")}g&&(a+="</tbody>")}}g&&(a+="</table>");return-1===a.indexOf(g?"<td>":"\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<a.length;g++){var f=a[g],e=f.title?f.title:c+(g+1),n=18<f.height?(f.height-18)/-2:0,k=f.description?f.description.trim().split(/(?:\W*\n\W*)+/):void 0,m="";if(k)for(var l=0;l<k.length;l++)if("css: "===k[l].substr(0,5).toLowerCase()){m=k[l].substr(5);break}h+=
|
||||||
|
".imgur-"+c+"-"+(g+1)+' {content: "'+e+'"; background-image: url("'+f.link+'"); height: '+f.height+"px; width: "+f.width+"px; margin: "+n+"px 0px; "+m+"}\n"}a=this.process_css("imgur-"+c,"FFZ Global Emotes - Imgur Album: "+c,h);this._msg(b,"Loaded "+a+" emoticons from Imgur.");this._msg(b,d.commands.list.bind(this)(b,[c]))};d.prototype.find_bttv=function(b,c){if(this.alive){if(l.BTTVLOADED)return this.setup_bttv();void 0===c&&this.log("BetterTTV not yet loaded. Waiting...");6E4<=c?this.log('BetterTTV not detected in "'+
|
||||||
|
location.toString()+'". Giving up.'):setTimeout(this.find_bttv.bind(this,b,(c||0)+b),b)}};var s={type:"ffz-donor",name:"",description:"FFZ Donor"};d.prototype.setup_bttv=function(){this.log("BetterTTV was detected. Installing hook.");this.has_bttv=!0;var b=BetterTTV.chat.templates.privmsg,c=this;BetterTTV.chat.templates.privmsg=function(a,d,g,f,e){if(c.check_donor(e.sender)){for(var l=!1,k=0;k<e.badges.length;k++){var m=e.badges[k].type;if("turbo"==m||"subscriber"==m){e.badges.insertAt(k,s);l=!0;
|
||||||
|
break}}l||e.badges.push(s)}return b(a,d,g,f,e)}};d.prototype.add_badge=function(b,c){if(this.check_donor(b)){var a=document.createElement("span");a.className="badge-container tooltip";a.setAttribute("title","FFZ Donor");var d=document.createElement("div");d.className="badge ffz-donor";a.appendChild(d);a.appendChild(document.createTextNode(" "));d=c.find(".badge-container").filter(function(a){a=this.title.toLowerCase();return"subscriber"==a||"turbo"==a}).first();d.length?d.before(a):c.append(a)}};
|
||||||
|
d.prototype.modify_lines=function(){var b=this;App.LineView.reopen({didInsertElement:function(){this._super();b.add_badge(this.get("context.model.from"),this.$(".badges"))}})};d.prototype._modify_room=function(b){var c=this;b.reopen({init:function(){this._super();c.alive&&c.add_channel(this.id,this)},willDestroy:function(){this._super();c.alive&&c.remove_channel(this.id)},send:function(a){if(!c.alive||"/ffz "!=a.substr(0,5)&&"/ffz"!=a)return this._super(a);this.set("messageToSend","");c.run_command(this,
|
||||||
|
a)}})};d.prototype.modify_room=function(){this._modify_room(App.Room);var b=App.Room.instances,c;for(c in b)if(b.hasOwnProperty(c)){var a=b[c];this.alive&&this.add_channel(a.id,a);a.tmiRoom&&this.alive?this.alter_tmi(a.id,a.tmiRoom):a.viewers&&this._modify_viewers(a.viewers);this._modify_room(a)}};d.prototype._modify_viewers=function(b){var c=this;b.reopen({tmiRoom:Ember.computed(function(a,b){1<arguments.length&&(this.tmiRoom=b,c.alive&&c.alter_tmi(this.id,b))})})};d.prototype.modify_viewers=function(){this._modify_viewers(App.Room.Viewers)};
|
||||||
|
d.prototype._modify_emotes=function(b){var c=this;b.reopen({_emoticons:[],init:function(){this._super();c.alive&&c.get_manager(this)},emoticons:Ember.computed(function(a,b){1<arguments.length&&(this._emoticons=b,c.log("Twitch standard emoticons loaded."));return c.alive?_.union(this._emoticons,c.emoticons):this._emoticons})})};d.prototype.modify_emotes=function(){this._modify_emotes(App.EmoticonsController);var b=App.__container__.lookup("controller:emoticons");b&&(this._modify_emotes(b),this.get_manager(b))};
|
||||||
|
d.prototype.get_manager=function(b){this.manager=b;for(var c in this.emotesets)this.emotesets.hasOwnProperty(c)&&(b.emoticonSets[c]=this.emotesets[c])};d.prototype.add_channel=function(b,c){if(this.alive){this.log("Registered channel: "+b);this.channels[b]={id:b,room:c,tmi:null,style:null};if(0<this._log2.length)for(var a=this.has_bttv?BetterTTV.chat.helpers.serverMessage:c.addTmiMessage;this._log2.length;)a(this._log2.shift());this.load_emotes(b)}};d.prototype.remove_channel=function(b){var c=this.channels[b];
|
||||||
|
c&&(this.log("Removing channel: "+b),this.unload_emotes(b),c.tmi&&delete c.tmi.getEmotes,this.channels[b]=!1)};d.prototype.alter_tmi=function(b,c){var a=this.channels[b],d=this;if(a&&this.alive&&!a.tmi){a.tmi=c;var g=c.__proto__.getEmotes.bind(c);c.getEmotes=function(b){return _.union([a.set_id],d.global_sets,g(b)||[])}}};d.prototype.load_emotes=function(b,c){this.get("//commondatastorage.googleapis.com/frankerfacez/"+b+".css",this.process_css.bind(this,b,void 0),c?1:108E5)};d.prototype.process_css=
|
||||||
|
function(b,c,a){if(!this.alive||void 0===a)return 0;this.unload_emotes(b);if(null==a)return 0;var d=this.channels[b];if(!1!==d){var g=--this.last_set,f=[],e=document.createElement("style");d?(d.set_id=g,d.set=f,d.style=e,c="FFZ Channel Emotes: "+b):(this.globals[b]=g,this.global_sets.push(g),this.styles[b]=e,c||(c="FFZ Global Emotes"+("global"!=b?": "+b:"")));this.emotesets[g]=f;this.manager&&(this.manager.emoticonSets[g]=f);e.type="text/css";e.innerHTML=a;document.body?document.body.appendChild(e):
|
||||||
|
this.pending_styles.push(e);var l=0,k=this,m=this.collections[c]=[];a.replace(u,function(a,d,e,h,p,q){p=parseInt(p);q=parseInt(q);h={emoticon_set:g,height:p,width:q,url:h,html:'<span class="'+d+' emoticon" title="'+e+'"></span>',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;a<b.length;a++)this.donors[b[a]]=!0;c+=
|
||||||
|
b.length}this.log("Loaded "+c+" donors.")}};d.prototype.get=function(b,c,a,d,g){if(this.alive)if(this.getting[b])this.log("Already getting resource: "+b);else{this.getting[b]=!0;g=g||10;var f=0,e=(new Date).getTime();if(l.localStorage){var n=localStorage.getItem("ffz_"+b);if(null!=n){this.log("Found resource in localStorage: "+b);try{c(JSON.parse(n))}catch(k){this.log("Error in callback: "+k)}f=parseInt(localStorage.getItem("ffz_age_"+b)||0)}}r||!f||void 0!==a&&null!==a&&e-f>a?(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);
|
Loading…
Add table
Add a link
Reference in a new issue