1
0
Fork 0
mirror of https://github.com/FrankerFaceZ/FrankerFaceZ.git synced 2025-07-05 18:48:31 +00:00
FrankerFaceZ/script.min.js

3 lines
78 KiB
JavaScript
Raw Normal View History

2015-04-15 21:00:52 -04:00
!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 m=!1,s=0;s<e.badges.length;s++){var _=e.badges[s];if(_.type==c.replaces){_.type="ffz-badge-replacement "+_.type,_.description+=", "+(r.title||c.title)+'" style="background-image: url(&quot;'+(r.image||c.image)+"&quot;)",m=!0;break}}if(m)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
}var i=[];for(var a in n.ffz_commands)n.ffz_commands.hasOwnProperty(a)&&i.push(a);return"The available commands are: "+i.join(", ")},n.ffz_commands.help.help="Usage: /ffz help [command]\nList available commands, or show help for a specific command.",n.prototype.add_room=function(e,t){return this.rooms[e]?this.log("Tried to add existing room: "+e):(this.log("Adding Room: "+e),this.rooms[e]={id:e,room:t,menu_sets:[],sets:[],css:null},this.ws_send("sub",e),void this._legacy_add_room(e))},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 m=o[u],_=i[m];if(_&&_.length)for(e.push({category:m}),e.push({chatter:""}),_.sort();_.length;){var h=_.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(/ +/);retu
return a=a.split(",").removeObject("0"),e.settings.global_emotes_in_menu&&(a.push("0"),r=_.union(r,e.global_sets)),[a,r]};n.settings_info.global_emotes_in_menu={type:"boolean",value:!1,name:"Display Global Emotes in My Emotes",help:"Display the global Twitch emotes in the My Emoticons menu."},n.prototype.setup_my_emotes=function(){if(this._twitch_emote_sets={},this._twitch_set_to_channel={},localStorage.ffzTwitchSets)try{this._twitch_set_to_channel=JSON.parse(localStorage.ffzTwitchSets)}catch(e){}this._twitch_set_to_channel[0]="twitch_global"},n.menu_pages.my_emotes={name:"My Emoticons",icon:o.EMOTE,visible:function(){var e=r(this);return e[0].length>0||e[1].length>0},render:function(e,t){var o=r(this),l=this;new RSVP.Promise(function(e){for(var t=[],i=0;i<o[0].length;i++){var r=o[0][i];l._twitch_emote_sets[r]||t.push(r)}RSVP.all([new RSVP.Promise(function(e){return t.length?void Twitch.api.get("chat/emoticon_images",{emotesets:t.join(",")},{version:3}).done(function(t){if(t.emoticon_sets)for(var n in t.emoticon_sets)if(t.emoticon_sets.hasOwnProperty(n)){var o=l._twitch_emote_sets[n]=l._twitch_emote_sets[n]||{},i=t.emoticon_sets[n];i.sort(function(e,t){var e=(s[e.code]?"000"+s[e.code]:e.code).toLowerCase(),t=(s[t.code]?"000"+s[t.code]:t.code).toLowerCase();return"000grayface"==e&&(e="grayface"),"000grayface"==t&&(t="grayface"),t>e?-1:e>t?1:0}),o.emotes=i,o.source="Twitch"}e()}).fail(function(){e()}):e()}),new RSVP.Promise(function(e){if(!t.length)return e();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),2e3)}.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()},2e3)):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})}_="global"===d.id?"Global Emoticons":d.title||d.id,m=d.icon||"http://cdn.frankerfacez.com/channel/global/devicon.png"}else p=d.emotes,_=n.get_capitalization(d.channel),m=d.bad