mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-06-27 21:05:53 +00:00
Added basic support for BetterTTV chat tag alpha transparency.
This commit is contained in:
parent
58efd651bf
commit
f9fdcb3ba6
2 changed files with 15 additions and 11 deletions
|
@ -466,17 +466,21 @@ ffz.prototype.setup_bttv = function() {
|
|||
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 badge = _.defaults({}, donor_badge);
|
||||
if ( BetterTTV.settings.get('alphaTags') )
|
||||
badge['type'] = badge['type'] + ' alpha';
|
||||
|
||||
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);
|
||||
data.badges.insertAt(i, badge);
|
||||
inserted = true;
|
||||
break;
|
||||
}
|
||||
if ( ! inserted )
|
||||
data.badges.push(donor_badge);
|
||||
data.badges.push(badge);
|
||||
}
|
||||
|
||||
return privmsg(highlight, action, server, isMod, data);
|
||||
|
|
18
script.min.js
vendored
18
script.min.js
vendored
|
@ -1,4 +1,4 @@
|
|||
(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=
|
||||
(function wrapper(m,s){if(s){var p=document.createElement("script");p.textContent="("+wrapper+")(window, false)";document.body.appendChild(p);document.body.removeChild(p)}else{var t=/\.([\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,
|
||||
|
@ -13,15 +13,15 @@ c.commands.global.help="Usage: /ffz global\nShorthand for /ffz list global. List
|
|||
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<a.length;h++){var f=a[h],e=f.title?f.title:d+(h+1),l=18<f.height?(f.height-18)/-2:0,k=f.description?f.description.trim().split(/(?:\W*\n\W*)+/):void 0,n="";if(k)for(var q=0;q<k.length;q++)if("css: "===k[q].substr(0,5).toLowerCase()){n=k[q].substr(5);break}g+=
|
||||
".imgur-"+d+"-"+(h+1)+' {content: "'+e+'"; background-image: url("'+f.link+'"); height: '+f.height+"px; width: "+f.width+"px; margin: "+l+"px 0px; "+n+"}\n"}a=this.process_css("imgur-"+d,"FFZ Global Emotes - Imgur Album: "+d,g);this._msg(b,"Loaded "+a+" emoticons from Imgur.");this._msg(b,c.commands.list.bind(this)(b,[d]))};c.prototype.find_bttv=function(b,d){if(this.alive){if(m.BTTVLOADED)return this.setup_bttv();void 0===d&&this.log("BetterTTV not yet loaded. Waiting...");6E4<=d?this.log('BetterTTV not detected in "'+
|
||||
location.toString()+'". Giving up.'):setTimeout(this.find_bttv.bind(this,b,(d||0)+b),b)}};var s={type:"ffz-donor",name:"",description:"FFZ Donor"};c.prototype.setup_bttv=function(){this.log("BetterTTV was detected. Installing hook.");this.has_bttv=!0;var b=BetterTTV.chat.templates.privmsg,d=this;BetterTTV.chat.templates.privmsg=function(a,c,h,f,e){if(d.check_donor(e.sender)){for(var l=!1,k=0;k<e.badges.length;k++){var n=e.badges[k].type;if("turbo"==n||"subscriber"==n){e.badges.insertAt(k,s);l=!0;
|
||||
break}}l||e.badges.push(s)}return b(a,c,h,f,e)}};c.prototype.add_badge=function(b,d){if(this.check_donor(b)){var a=document.createElement("span");a.className="badge-container tooltip";a.setAttribute("title","FFZ Donor");var c=document.createElement("div");c.className="badge ffz-donor";a.appendChild(c);a.appendChild(document.createTextNode(" "));c=d.find(".badge-container").filter(function(a){a=this.title.toLowerCase();return"subscriber"==a||"turbo"==a}).first();c.length?c.before(a):d.append(a)}};
|
||||
c.prototype.modify_lines=function(){var b=this;App.LineView.reopen({didInsertElement:function(){this._super();b.add_badge(this.get("context.model.from"),this.$(".badges"))}})};c.prototype._modify_room=function(b){var d=this;b.reopen({init:function(){this._super();d.alive&&d.add_channel(this.id,this)},willDestroy:function(){this._super();d.alive&&d.remove_channel(this.id)},send:function(a){if(!d.alive||"/ffz "!=a.substr(0,5)&&"/ffz"!=a)return this._super(a);this.set("messageToSend","");d.run_command(this,
|
||||
a)}})};c.prototype.modify_room=function(){this._modify_room(App.Room);var b=App.Room.instances,d;for(d in b)if(b.hasOwnProperty(d)){var a=b[d];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)}};c.prototype._modify_viewers=function(b){var d=this;b.reopen({tmiRoom:Ember.computed(function(a,b){1<arguments.length&&(this.tmiRoom=b,d.alive&&d.alter_tmi(this.id,b))})})};c.prototype.modify_viewers=function(){this._modify_viewers(App.Room.Viewers)};
|
||||
c.prototype._modify_emotes=function(b){var d=this;b.reopen({_emoticons:b.emoticons||[],init:function(){this._super();d.alive&&d.get_manager(this)},emoticons:Ember.computed(function(a,b){1<arguments.length&&(this._emoticons=b,d.log("Twitch standard emoticons loaded."));return d.alive?_.union(this._emoticons,d.emoticons):this._emoticons})})};c.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))};c.prototype.get_manager=function(b){this.manager=b;for(var d in this.emotesets)this.emotesets.hasOwnProperty(d)&&(b.emoticonSets[d]=this.emotesets[d])};c.prototype.add_channel=function(b,d){if(this.alive){this.log("Registered channel: "+b);this.channels[b]={id:b,room:d,tmi:null,style:null};if(0<this._log2.length)for(var a=this.has_bttv?BetterTTV.chat.helpers.serverMessage:d.addTmiMessage;this._log2.length;)a(this._log2.shift());this.load_emotes(b)}};c.prototype.remove_channel=
|
||||
function(b){var d=this.channels[b];d&&(this.log("Removing channel: "+b),this.unload_emotes(b),d.tmi&&delete d.tmi.getEmotes,this.channels[b]=!1)};c.prototype.alter_tmi=function(b,d){var a=this.channels[b],c=this;if(a&&this.alive&&!a.tmi){a.tmi=d;var h=d.__proto__.getEmotes.bind(d);d.getEmotes=function(b){return _.union([a.set_id],c.global_sets,h(b)||[])}}};c.prototype.load_emotes=function(b,d){var a=/^_(.+)_\d+$/.exec(b),c=b;null!=a&&(c=a[1]);this.get("//commondatastorage.googleapis.com/frankerfacez/"+
|
||||
location.toString()+'". Giving up.'):setTimeout(this.find_bttv.bind(this,b,(d||0)+b),b)}};var u={type:"ffz-donor",name:"",description:"FFZ Donor"};c.prototype.setup_bttv=function(){this.log("BetterTTV was detected. Installing hook.");this.has_bttv=!0;var b=BetterTTV.chat.templates.privmsg,d=this;BetterTTV.chat.templates.privmsg=function(a,c,h,f,e){if(d.check_donor(e.sender)){var l=_.defaults({},u);BetterTTV.settings.get("alphaTags")&&(l.type+=" alpha");for(var k=!1,n=0;n<e.badges.length;n++){var q=
|
||||
e.badges[n].type;if("turbo"==q||"subscriber"==q){e.badges.insertAt(n,l);k=!0;break}}k||e.badges.push(l)}return b(a,c,h,f,e)}};c.prototype.add_badge=function(b,d){if(this.check_donor(b)){var a=document.createElement("span");a.className="badge-container tooltip";a.setAttribute("title","FFZ Donor");var c=document.createElement("div");c.className="badge ffz-donor";a.appendChild(c);a.appendChild(document.createTextNode(" "));c=d.find(".badge-container").filter(function(a){a=this.title.toLowerCase();return"subscriber"==
|
||||
a||"turbo"==a}).first();c.length?c.before(a):d.append(a)}};c.prototype.modify_lines=function(){var b=this;App.LineView.reopen({didInsertElement:function(){this._super();b.add_badge(this.get("context.model.from"),this.$(".badges"))}})};c.prototype._modify_room=function(b){var d=this;b.reopen({init:function(){this._super();d.alive&&d.add_channel(this.id,this)},willDestroy:function(){this._super();d.alive&&d.remove_channel(this.id)},send:function(a){if(!d.alive||"/ffz "!=a.substr(0,5)&&"/ffz"!=a)return this._super(a);
|
||||
this.set("messageToSend","");d.run_command(this,a)}})};c.prototype.modify_room=function(){this._modify_room(App.Room);var b=App.Room.instances,d;for(d in b)if(b.hasOwnProperty(d)){var a=b[d];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)}};c.prototype._modify_viewers=function(b){var d=this;b.reopen({tmiRoom:Ember.computed(function(a,b){1<arguments.length&&(this.tmiRoom=b,d.alive&&d.alter_tmi(this.id,
|
||||
b))})})};c.prototype.modify_viewers=function(){this._modify_viewers(App.Room.Viewers)};c.prototype._modify_emotes=function(b){var d=this;b.reopen({_emoticons:b.emoticons||[],init:function(){this._super();d.alive&&d.get_manager(this)},emoticons:Ember.computed(function(a,b){1<arguments.length&&(this._emoticons=b,d.log("Twitch standard emoticons loaded."));return d.alive?_.union(this._emoticons,d.emoticons):this._emoticons})})};c.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))};c.prototype.get_manager=function(b){this.manager=b;for(var d in this.emotesets)this.emotesets.hasOwnProperty(d)&&(b.emoticonSets[d]=this.emotesets[d])};c.prototype.add_channel=function(b,d){if(this.alive){this.log("Registered channel: "+b);this.channels[b]={id:b,room:d,tmi:null,style:null};if(0<this._log2.length)for(var a=this.has_bttv?BetterTTV.chat.helpers.serverMessage:d.addTmiMessage;this._log2.length;)a(this._log2.shift());
|
||||
this.load_emotes(b)}};c.prototype.remove_channel=function(b){var d=this.channels[b];d&&(this.log("Removing channel: "+b),this.unload_emotes(b),d.tmi&&delete d.tmi.getEmotes,this.channels[b]=!1)};c.prototype.alter_tmi=function(b,d){var a=this.channels[b],c=this;if(a&&this.alive&&!a.tmi){a.tmi=d;var h=d.__proto__.getEmotes.bind(d);d.getEmotes=function(b){return _.union([a.set_id],c.global_sets,h(b)||[])}}};c.prototype.load_emotes=function(b,d){var a=/^_(.+)_\d+$/.exec(b),c=b;null!=a&&(c=a[1]);this.get("//commondatastorage.googleapis.com/frankerfacez/"+
|
||||
c+".css",this.process_css.bind(this,b,void 0),d?1:108E5)};c.prototype.process_css=function(b,d,a){if(!this.alive||void 0===a)return 0;this.unload_emotes(b);if(null==a)return 0;var c=this.channels[b];if(!1!==c){var h=--this.last_set,f=[],e=document.createElement("style");c?(c.set_id=h,c.set=f,c.style=e,d="FFZ Channel Emotes: "+b):(this.globals[b]=h,this.global_sets.push(h),this.styles[b]=e,d||(d="FFZ Global Emotes"+("global"!=b?": "+b:"")));this.emotesets[h]=f;this.manager&&(this.manager.emoticonSets[h]=
|
||||
f);e.type="text/css";e.innerHTML=a;document.body?document.body.appendChild(e):this.pending_styles.push(e);var l=0,k=this,n=this.collections[d]=[];a.replace(u,function(a,c,e,g,m,p){m=parseInt(m);p=parseInt(p);g={emoticon_set:h,height:m,width:p,url:g,html:'<span class="'+c+' 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:g,images:[g],text:e,channel:d,hidden:!1,regex:a,ffzset:b};n.push(e);k.emoticons.push(e);
|
||||
f);e.type="text/css";e.innerHTML=a;document.body?document.body.appendChild(e):this.pending_styles.push(e);var l=0,k=this,n=this.collections[d]=[];a.replace(t,function(a,c,e,g,m,p){m=parseInt(m);p=parseInt(p);g={emoticon_set:h,height:m,width:p,url:g,html:'<span class="'+c+' 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: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;a<b.length;a++)this.donors[b[a]]=!0;d+=b.length}this.log("Loaded "+d+" donors.")}};c.prototype.get=function(b,d,a,c,h){if(this.alive)if(this.getting[b])this.log("Already getting resource: "+b);else{this.getting[b]=!0;h=h||10;var f=0,e=(new Date).getTime();if(m.localStorage){var l=localStorage.getItem("ffz_"+b);if(null!=l){this.log("Found resource in localStorage: "+b);try{d(JSON.parse(l))}catch(k){this.log("Error in callback: "+k)}f=parseInt(localStorage.getItem("ffz_age_"+
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue