1
0
Fork 0
mirror of https://github.com/FrankerFaceZ/FrankerFaceZ.git synced 2025-07-06 11:08:30 +00:00
FrankerFaceZ/script.min.js

3 lines
77 KiB
JavaScript
Raw Normal View History

!function(e){!function t(e,n,o){function i(s,r){if(!n[s]){if(!e[s]){var l="function"==typeof require&&require;if(!r&&l)return l(s,!0);if(a)return a(s,!0);throw new Error("Cannot find module '"+s+"'")}var c=n[s]={exports:{}};e[s][0].call(c.exports,function(t){var n=e[s][1][t];return i(n?n:t)},c,c.exports,t,e,n,o)}return n[s].exports}for(var a="function"==typeof require&&require,s=0;s<o.length;s++)i(o[s]);return i}({1:[function(t){var n=e.FrankerFaceZ,o=t("./constants"),i=t("./utils");n.settings_info.bot_badges={type:"boolean",value:!0,category:"Chat",name:"Bot Badges",help:"Give special badges to known bots."},n.prototype.setup_badges=function(){this.log("Preparing badge system."),this.badges={},this.log("Creating badge style element.");var e=this._badge_style=document.createElement("style");e.id="ffz-badge-css",document.head.appendChild(e),this.log("Adding legacy donor badges."),this._legacy_add_donors()},n.ws_commands.reload_badges=function(){this._legacy_load_bots(),this._legacy_load_donors()},n.ws_commands.set_badge=function(e){var t=e[0],n=e[1],o=e[2],i=this.users[t]=this.users[t]||{},a=i.badges=i.badges||{};void 0===o?delete a[n]:a[n]=o};var a=function(e){return".badges .ffz-badge-"+e.id+" { background-color: "+e.color+'; background-image: url("'+e.image+'"); '+(e.extra_css||"")+"}"};n.prototype.bttv_badges=function(e){var t=e.sender,n=this.users[t],o=[],i=-1,a=BetterTTV.settings.get("alphaTags");if(n&&n.badges){for(var s=0;s<e.badges.length;s++){var r=e.badges[s];if("subscriber"==r.type||"turbo"==r.type){i=s;break}}for(var l in n.badges)if(n.badges.hasOwnProperty(l)){var r=n.badges[l],c=this.badges[r.id]||{},u=r.title||c.title,d="";if(void 0!==c.visible){var h=c.visible;if("function"==typeof h&&(h=h.bind(this)(null,t)),!h)continue}if(c.replaces){for(var _=!1,s=0;s<e.badges.length;s++){var m=e.badges[s];if(m.type==c.replaces){m.type="ffz-badge-replacement "+m.type,m.description+=", "+(r.title||c.title)+'" style="background-image: url(&quot;'+(r.image||c.image)+"&quot;)",_=!0;break}}if(_)continue}r.image&&(d+="background-image: url(&quot;"+r.image+"&quot;); "),r.color&&!a&&(d+="background-color: "+r.color+"; "),r.extra_css&&(d+=r.extra_css),d&&(u+='" style="'+d),o.push([(-1==i?1:-1)*l,{type:"ffz-badge-"+r.id+(a?" alpha":""),name:"",description:u}])}if(o.sort(function(e,t){return e[0]-t[0]}),-1==i)for(;o.length;)e.badges.push(o.shift()[1]);else for(;o.length;)e.badges.insertAt(i,o.shift()[1])}},n.prototype.render_badge=function(e){var t=e.get("context.model.from"),n=e.get("context.parentController.content.id"),o=e.$(".badges"),i=this.users[t];if(i&&i.badges){var a=o.find(".badge").filter(function(){var e=this.title.toLowerCase();return"subscriber"==e||"turbo"==e}).first(),s=[],r=!!a.length;for(var l in i.badges)if(i.badges.hasOwnProperty(l)){var c=i.badges[l],u=this.badges[c.id]||{};if(void 0!==u.visible){var d=u.visible;if("function"==typeof d&&(d=d.bind(this)(n,t)),!d)continue}if(u.replaces){var h=o[0].querySelector(".badge."+u.replaces);if(h){h.style.backgroundImage='url("'+(c.image||u.image)+'")',h.classList.add("ffz-badge-replacement"),h.title+=", "+(c.title||u.title);continue}}var h=document.createElement("div");h.className="badge float-left tooltip ffz-badge-"+c.id,h.setAttribute("title",c.title||u.title),c.image&&(h.style.backgroundImage='url("'+c.image+'")'),c.color&&(h.style.backgroundColor=c.color),c.extra_css&&(h.style.cssText+=c.extra_css),s.push([(r?1:-1)*l,h])}if(s.sort(function(e,t){return e[0]-t[0]}),r)for(;s.length;)a.before(s.shift()[1]);else for(;s.length;)o.append(s.shift()[1])}},n.bttv_known_bots=["nightbot","moobot","sourbot","xanbot","manabot","mtgbot","ackbot","baconrobot","tardisbot","deejbot","valuebot","stahpbot"],n.prototype._legacy_add_donors=function(){this.badges[0]={id:0,title:"FFZ Developer",color:"#FAAF19",image:"//cdn.frankerfacez.com/channel/global/devicon.png"},i.update_css(this._badge_style,0,a(this.badges[0])),this.badges[1]={id:1,title:"FFZ Donor",color:"#755000",image:"//cdn.frankerfacez.com/channel/global/donoricon.png"},i.update_css(this._badge_style,1,a(this.badges[1])),th
},n.prototype.remove_room=function(e){var t=this.rooms[e];if(t){this.log("Removing Room: "+e),(t.css||t.moderator_badge)&&r.update_css(this._room_style,e,null),this.ws_send("unsub",e),delete this.rooms[e];for(var n=0;n<t.sets.length;n++){var o=t.sets[n],i=this.emote_sets[o];i&&(i.users.removeObject(e),i.global||i.users.length||this.unload_set(o))}}},n.prototype.load_room=function(e,t){return this._legacy_load_room(e,t)},n.prototype._load_room_json=function(e,t,n){this.rooms[e]&&(n.room=this.rooms[e].room),this.rooms[e]=n,(n.css||n.moderator_badge)&&r.update_css(this._room_style,e,l(n)+(n.css||""));for(var o=0;o<n.sets.length;o++){var i=n.sets[o];this.emote_sets.hasOwnProperty(i)||this.load_set(i)}this.update_ui_link(),t&&t(!0,n)},n.prototype._modify_room=function(e){var t=this;e.reopen({init:function(){this._super();try{t.add_room(this.id,this)}catch(e){t.error("add_room: "+e)}},willDestroy:function(){this._super();try{t.remove_room(this.id)}catch(e){t.error("remove_room: "+e)}},getSuggestions:function(){var e=this._super();try{t.settings.capitalize&&(e=_.map(e,n.get_capitalization))}catch(o){t.error("get_suggestions: "+o)}return e},send:function(e){try{var n=e.split(" ",1)[0].toLowerCase();if("/ffz"===n)return this.set("messageToSend",""),void t.run_ffz_command(e.substr(5),this.get("id"));if("/"===n.charAt(0)&&t.run_command(e,this.get("id")))return void this.set("messageToSend","")}catch(o){t.error("send: "+o)}return this._super(e)}})},n.prototype._legacy_add_room=function(e,t,n){jQuery.ajax(s.SERVER+"channel/"+e+".css",{cache:!1,context:this}).done(function(n){this._legacy_load_room_css(e,t,n)}).fail(function(o){return 404==o.status?this._legacy_load_room_css(e,t,null):(n=n||0,n++,10>n?this._legacy_add_room(e,t,n):void 0)})},n.prototype._legacy_load_room_css=function(e,t,n){var s=e,r=s.match(a);r&&r[1]&&(s=r[1]);var l={id:e,menu_sets:[s],sets:[s],moderator_badge:null,css:null};return n&&(n=n.replace(o,"").trim()),n&&(n=n.replace(i,function(e,t){return l.moderator_badge||"modicon.png"!==t.substr(-11)?e:(l.moderator_badge=t,"")})),l.css=n||null,this._load_room_json(e,t,l)}},{"../constants":3,"../utils":27}],9:[function(){var t=e.FrankerFaceZ;t.prototype.setup_viewers=function(){this.log("Hooking the Ember Viewers controller.");var e=App.__container__.resolve("controller:viewers");this._modify_viewers(e)},t.prototype._modify_viewers=function(e){var n=this;e.reopen({lines:function(){var e=this._super();try{var o=[],i={},a=null,s=App.__container__.lookup("controller:channel"),r=this.get("parentController.model.id"),l=s&&s.get("id");if(l){var c=s.get("display_name");c&&(t.capitalization[l]=[c,Date.now()])}r!=l&&(l=null);for(var u=0;u<e.length;u++){var d=e[u];if(d.category)a=d.category,o.push(a),i[a]=[];else{var h=d.chatter.toLowerCase();if(!h)continue;h==l?(o.unshift("Broadcaster"),i.Broadcaster=[h]):i.hasOwnProperty(a)&&i[a].push(h)}}e=[];for(var u=0;u<o.length;u++){var _=o[u],m=i[_];if(m&&m.length)for(e.push({category:_}),e.push({chatter:""}),m.sort();m.length;){var h=m.shift();h=t.get_capitalization(h),e.push({chatter:h})}}}catch(p){n.error("ViewersController lines: "+p)}return e}.property("content.chatters")})}},{}],10:[function(t){var n=e.FrankerFaceZ,o=/\.([\w\-_]+)\s*?\{content:\s*?"([^"]+)";\s*?background-image:\s*?url\("([^"]+)"\);\s*?height:\s*?(\d+)px;\s*?width:\s*?(\d+)px;\s*?margin:([^;}]+);?([^}]*)\}/gm,i=/[^\n}]*\.badges\s+\.moderator\s*{\s*background-image:\s*url\(\s*['"]([^'"]+)['"][^}]+(?:}|$)/,a=t("./constants"),s=t("./utils"),r=function(e,t,n){t&&(n.global=!0,this.global_sets.push(e))},l=function(e,t){var n=e.split(/ +/);return 2!=n.length?e:(n[0]=parseFloat(n[0]),n[1]=parseFloat(n[1]),n[0]==(t-18)/-2&&0==n[1]?null:e)},c=function(e){var t=e.margins;return t||(t=(e.height-18)/-2+"px 0"),".ffz-emote-"+e.id+' { background-image: url("'+e.url+'"); height: '+e.height+"px; width: "+e.width+"px; margin: "+t+(e.extra_css?"; "+e.extra_css:"")+"}\n"},u=function(e){return e.margins||e.extra_css?c(e)+'img[src="'+e.url+'"] { '+(e.margins?"margin: "+e.margins+";":"")+(e.extra_css||"")+" }\n":c(e)},d=u;n.prototype.setu
var o=[],i=t,s=function(e,t){var i=l._twitch_emote_sets[e]=l._twitch_emote_sets[e]||{};if(t&&!a[t]){if("twitch_global"==t)return n.capitalization["global emoticons"]=["Global Emoticons",Date.now()],i.channel="Global Emoticons",void(i.badge="//cdn.frankerfacez.com/channel/global/twitch_logo.png");if("turbo"==t)return i.channel="Twitch Turbo",void(i.badge="//cdn.frankerfacez.com/script/turbo_badge.png");o.push(new RSVP.Promise(function(e,t,n){Twitch.api.get("chat/"+t+"/badges",null,{version:3}).done(function(t){t.subscriber&&t.subscriber.image&&(e.badge=t.subscriber.image),n()}).fail(n)}.bind(this,i,t)));var s=t.toLowerCase(),r=n.capitalization[s];return r&&Date.now()-r[1]<36e5?void(i.channel=r[0]):void o.push(new RSVP.Promise(function(e,t,o,i){l.ws_send("get_display_name",t,function(a,s){var r=a?s:o;n.capitalization[t]=[r,Date.now()],e.channel=r,i()})||(e.channel=o,i()),setTimeout(function(e,t,n){e.channel||(e.channel=t),n()}.bind(this,e,o,i),5e3)}.bind(this,i,s,t)))}},r=function(){o.length?RSVP.all(o).then(e,e):e()};t=[];for(var c=0;c<i.length;c++){var u=i[c];l._twitch_set_to_channel[u]?s(u,l._twitch_set_to_channel[u]):t.push(u)}t.length>0?(l.ws_send("twitch_sets",t,function(e,n){if(t=[],e){for(var o in n)n.hasOwnProperty(o)&&(l._twitch_set_to_channel[o]=n[o],s(o,n[o]));localStorage.ffzTwitchSets=JSON.stringify(l._twitch_set_to_channel)}r()}),setTimeout(function(){t.length&&r()},5e3)):r()})]).then(function(){for(var t={},n=0;n<o[0].length;n++){var i=o[0][n];l._twitch_emote_sets[i]&&(t[i]=l._twitch_emote_sets[i])}e(t)},function(){e({})})}).then(function(a){try{if("my_emotes"!=t.getAttribute("data-page"))return;t.innerHTML="";var r=o[1],c=[];for(var u in a)if(a.hasOwnProperty(u)){var d=a[u];d.channel&&d.emotes&&d.emotes.length&&c.push([1,d.channel,d])}for(var h=0;h<r.length;h++){var u=r[h],d=l.emote_sets[u];l.feature_friday&&u==l.feature_friday.set||d.count>0&&c.push([2,d.id,d])}c.sort(function(e,t){if(e[0]<t[0])return-1;if(e[0]>t[0])return 1;var n=e[1].toLowerCase(),o=t[1].toLowerCase();return("twitch turbo"===n||"global emoticons"===n)&&(n="zzz"+n),("twitch turbo"===o||"global emoticons"===o)&&(o="zzz"+o),o>n?-1:n>o?1:0});for(var h=0;h<c.length;h++){var _,m,p,f=2===c[h][0],d=c[h][2],g=document.createElement("div"),v=document.createElement("div"),b=f?"FrankerFaceZ":d.source;if(f){p=[];for(var y in d.emotes){var w=d.emotes[y];w.hidden||p.push({code:w.name,url:w.url,width:w.width,height:w.height})}m="global"===d.id?"Global Emoticons":d.id,_=d.icon||"http://cdn.frankerfacez.com/channel/global/devicon.png"}else p=d.emotes,m=n.get_capitalization(d.channel),_=d.badge;if(p.length){g.className="heading",g.innerHTML='<span class="right">'+b+"</span>"+m,_&&(g.style.backgroundImage='url("'+_+'")'),v.className="emoticon-grid",v.appendChild(g);for(var k=0;k<p.length;k++){var w=p[k],F=s[w.code]||w.code,E=document.createElement("span");if(E.className="emoticon tooltip",E.style.backgroundImage='url("'+(w.url?w.url:i+w.id+"/1.0")+'")',w.height&&(E.style.height=w.height+"px"),w.width&&(E.style.width=w.width+"px"),!w.url){var z='image-set(url("'+i+w.id+'/1.0") 1x, url("'+i+w.id+'/2.0") 2x, url("'+i+w.id+'/3.0") 4x)';E.style.backgroundImage="-webkit-"+z,E.style.backgroundImage="-moz-"+z,E.style.backgroundImage="-ms-"+z,E.style.backgroundImage=z}E.title=F,E.addEventListener("click",l._add_emote.bind(l,e,F)),v.appendChild(E)}t.appendChild(v)}}if(!c.length){var v=document.createElement("div");v.className="chat-menu-content center",v.innerHTML="Error Loading Subscriptions",t.appendChild(v)}}catch(C){l.log("My Emotes Menu Error",C),t.innerHTML="";var v=document.createElement("div"),g=document.createElement("div"),x=document.createElement("p");g.className="heading",g.innerHTML="Error Loading Menu",v.appendChild(g),x.className="clearfix",x.textContent=C,v.appendChild(x),v.className="chat-menu-content",t.appendChild(v)}})}}},{"../constants":3}],23:[function(){var t=e.FrankerFaceZ;t.prototype.setup_notifications=function(){this.log("Adding event handler for window focus."),e.addEventListener("focus",this.clear_notifications.bind(this))},t.settings_i