2015-02-24 00:33:29 -05:00
var FFZ = window . FrankerFaceZ ,
constants = require ( "../constants" ) ,
2015-06-05 03:59:28 -04:00
utils = require ( "../utils" ) ,
2015-02-24 00:33:29 -05:00
2017-06-11 13:30:37 -04:00
BANNED _SETS = { "00000turbo" : true } ,
EXTRA _INVENTORY = [ '33563' ] ;
2015-02-24 00:33:29 -05:00
// -------------------
// Initialization
// -------------------
2015-08-04 01:43:08 -04:00
FFZ . basic _settings . replace _twitch _menu = {
type : "boolean" ,
category : "Chat" ,
name : "Unified Emoticons Menu" ,
help : "Completely replace the default Twitch emoticon menu and display global emoticons in the My Emoticons menu." ,
get : function ( ) {
return this . settings . replace _twitch _menu && this . settings . global _emotes _in _menu && this . settings . emoji _in _menu ;
} ,
set : function ( val ) {
this . settings . set ( 'replace_twitch_menu' , val ) ;
this . settings . set ( 'global_emotes_in_menu' , val ) ;
this . settings . set ( 'emoji_in_menu' , val ) ;
}
} ;
2015-07-13 21:52:44 -04:00
FFZ . settings _info . replace _twitch _menu = {
type : "boolean" ,
value : false ,
category : "Chat Input" ,
name : "Replace Twitch Emoticon Menu" ,
help : "Completely replace the default Twitch emoticon menu." ,
on _update : function ( val ) {
document . body . classList . toggle ( "ffz-menu-replace" , val ) ;
}
} ;
2015-02-26 00:42:11 -05:00
FFZ . settings _info . global _emotes _in _menu = {
type : "boolean" ,
value : false ,
2015-07-13 21:52:44 -04:00
category : "Chat Input" ,
2015-02-26 00:42:11 -05:00
name : "Display Global Emotes in My Emotes" ,
help : "Display the global Twitch emotes in the My Emoticons menu."
} ;
2015-07-06 00:09:21 -04:00
FFZ . settings _info . emoji _in _menu = {
type : "boolean" ,
2016-03-23 19:28:22 -04:00
value : true ,
2015-07-06 00:09:21 -04:00
2015-07-13 21:52:44 -04:00
category : "Chat Input" ,
2015-07-06 00:09:21 -04:00
name : "Display Emoji in My Emotes" ,
help : "Display the supported emoji images in the My Emoticons menu."
} ;
2015-07-13 21:52:44 -04:00
FFZ . settings _info . emote _menu _collapsed = {
2016-07-13 02:31:26 -04:00
storage _key : "ffz_setting_my_emoticons_collapsed_sections" ,
2015-07-13 21:52:44 -04:00
value : [ ] ,
visible : false
}
2016-03-23 19:28:22 -04:00
FFZ . settings _info . favorite _emotes = {
2016-07-13 02:31:26 -04:00
value : { } ,
visible : false
2016-03-23 19:28:22 -04:00
}
2015-02-24 00:33:29 -05:00
FFZ . prototype . setup _my _emotes = function ( ) {
2017-09-15 14:41:00 -04:00
var UserEmotes = utils . ember _lookup ( 'service:user-emotes' ) ;
if ( UserEmotes ) {
this . modify _user _emotes ( UserEmotes ) ;
UserEmotes . ffzUpdateData ( ) ;
}
2015-06-05 03:59:28 -04:00
this . _twitch _badges = { } ;
2017-04-05 19:12:11 -04:00
this . _twitch _badges [ "--inventory--" ] = "//cdn.frankerfacez.com/script/inventory_icon.svg" ;
2015-07-31 21:40:51 -04:00
this . _twitch _badges [ "--global--" ] = "//cdn.frankerfacez.com/script/twitch_logo.png" ;
this . _twitch _badges [ "--turbo-faces--" ] = this . _twitch _badges [ "turbo" ] = "//cdn.frankerfacez.com/script/turbo_badge.png" ;
2016-10-05 23:07:10 -04:00
this . _twitch _badges [ "--prime-faces--" ] = this . _twitch _badges [ "--prime--" ] = "//cdn.frankerfacez.com/badges/twitch/premium/1/1.png" ;
this . _twitch _badges [ "--curse--" ] = "//cdn.frankerfacez.com/script/curse_logo.png" ;
2015-02-24 00:33:29 -05:00
}
2017-09-15 14:41:00 -04:00
FFZ . prototype . modify _user _emotes = function ( service ) {
var f = this ;
service . reopen ( {
ffzUpdateData : function ( ) {
var emotes = ( this . get ( 'allEmotes' ) || { } ) [ 'emoticon_sets' ] || { } ;
for ( var set _id in emotes ) {
f . get _twitch _set ( set _id ) ;
var es = emotes [ set _id ] || [ ] ,
2017-09-17 14:21:49 -04:00
esl = es . length ,
sid = typeof set _id === "number" ? set _id : parseInt ( set _id ) ;
2017-09-15 14:41:00 -04:00
for ( var i = 0 ; i < esl ; i ++ )
2017-09-17 14:21:49 -04:00
f . _twitch _emote _to _set [ es [ i ] . id ] = sid ;
2017-09-15 14:41:00 -04:00
}
if ( f . _inputv )
Ember . propertyDidChange ( f . _inputv , 'ffz_emoticons' ) ;
} . observes ( 'allEmotes' )
} ) ;
}
2015-02-24 00:33:29 -05:00
// -------------------
// Menu Page
// -------------------
2015-07-31 21:40:51 -04:00
FFZ . menu _pages . myemotes = {
2015-02-24 00:33:29 -05:00
name : "My Emoticons" ,
icon : constants . EMOTE ,
2016-03-31 19:47:17 -04:00
has _sets : function ( view ) {
2015-06-10 18:46:04 -04:00
var user = this . get _user ( ) ,
2016-10-12 20:54:09 -04:00
controller = utils . ember _lookup ( 'controller:chat' ) ,
2017-08-16 13:24:55 -04:00
user _emotes = utils . ember _lookup ( 'service:user-emotes' ) ,
2017-09-15 14:41:00 -04:00
twitch _sets = ( user _emotes && user _emotes . allEmotes || { } ) [ 'emoticon_sets' ] || { } ,
2015-06-10 18:46:04 -04:00
ffz _sets = user && this . users [ user . login ] && this . users [ user . login ] . sets || [ ] ,
2015-08-28 22:54:12 -04:00
sk = twitch _sets && Object . keys ( twitch _sets ) ;
2015-06-10 18:46:04 -04:00
2015-08-28 22:54:12 -04:00
if ( sk && ! this . settings . global _emotes _in _menu && sk . indexOf ( '0' ) !== - 1 )
sk . removeObject ( '0' ) ;
2016-03-31 19:47:17 -04:00
return ffz _sets . length || ( sk && sk . length ) ;
} ,
visible : function ( view ) {
2016-04-11 18:57:25 -04:00
return this . settings . emoji _in _menu || FFZ . menu _pages . myemotes . has _sets . call ( this , view ) ;
2015-02-24 00:33:29 -05:00
} ,
2016-07-13 02:31:26 -04:00
default _page : function ( ) {
for ( var key in this . settings . favorite _emotes )
if ( this . settings . favorite _emotes [ key ] && this . settings . favorite _emotes [ key ] . length )
return 'favorites' ;
2016-03-23 19:28:22 -04:00
2017-03-27 18:03:10 -04:00
var has _emotes = FFZ . menu _pages . myemotes . has _sets . call ( this ) ;
if ( has _emotes )
return 'all' ;
if ( this . settings . emoji _in _menu )
return 'emoji' ;
return 'favorites' ;
2016-07-13 02:31:26 -04:00
} ,
2016-03-23 19:28:22 -04:00
2016-07-13 02:31:26 -04:00
pages : {
favorites : {
name : "Favorites" ,
sort _order : 1 ,
2016-03-23 19:28:22 -04:00
2016-07-13 02:31:26 -04:00
render : function ( view , container ) {
FFZ . menu _pages . myemotes . render _lists . call ( this , view , container , true ) ;
2016-03-23 19:28:22 -04:00
2016-07-13 02:31:26 -04:00
var el = document . createElement ( "div" ) ;
el . className = "emoticon-grid ffz-no-emotes center" ;
2017-04-05 19:12:11 -04:00
el . innerHTML = "You have no favorite emoticons.<br> <img src=\"//cdn.frankerfacez.com/emoticon/26608/2\"><br>To make an emote a favorite, find it and <nobr>" + ( constants . IS _OSX ? '⌘' : 'Ctrl' ) + "-Click</nobr> it." ;
2016-07-13 02:31:26 -04:00
container . appendChild ( el ) ;
}
} ,
2016-03-23 19:28:22 -04:00
2016-07-13 02:31:26 -04:00
all : {
name : "All Emoticons" ,
sort _order : 2 ,
2016-03-23 19:28:22 -04:00
2016-03-31 19:47:17 -04:00
visible : function ( view ) {
2016-04-11 18:57:25 -04:00
return FFZ . menu _pages . myemotes . has _sets . call ( this , view ) ;
2016-03-31 19:47:17 -04:00
} ,
2016-07-13 02:31:26 -04:00
render : function ( view , container ) {
2017-06-11 13:30:37 -04:00
/ * v a r s e a r c h _ c o n t = u t i l s . c r e a t e E l e m e n t ( ' d i v ' , ' f f z - f i l t e r - c o n t a i n e r ' ) ,
search _input = utils . createElement ( 'input' , 'emoticon-selector__filter-input form__input js-filter-input text text--full-width' ) ,
filtered _cont = utils . createElement ( 'div' , 'ffz-filter-children ffz-ui-sub-menu-page' ) ,
was _filtered = false ;
search _input . placeholder = 'Search for Emotes' ;
search _input . type = 'text' ;
filtered _cont . style . maxHeight = ( parseInt ( container . style . maxHeight ) - 53 ) + 'px' ;
search _cont . appendChild ( search _input ) ;
container . appendChild ( filtered _cont ) ;
container . appendChild ( search _cont ) ;
search _input . addEventListener ( 'input' , function ( e ) {
var filter = ( search _input . value || '' ) . toLowerCase ( ) ,
groups = filtered _cont . querySelectorAll ( '.emoticon-grid' ) ;
for ( var i = 0 ; i < groups . length ; i ++ ) {
var el = groups [ i ] ,
emotes = el . querySelectorAll ( '.emoticon' ) ,
hidden = true ;
for ( var j = 0 ; j < emotes . length ; j ++ ) {
var em = emotes [ j ] ,
ehidden = filter . length && em . getAttribute ( 'data-filter' ) . indexOf ( filter ) === - 1 ;
em . classList . toggle ( 'hidden' , ehidden ) ;
hidden = hidden && ehidden ;
}
el . classList . toggle ( 'hidden' , hidden ) ;
el . classList . toggle ( 'collapsable' , ! filter . length ) ;
}
} ) ;
container = filtered _cont ; * /
2016-07-13 02:31:26 -04:00
FFZ . menu _pages . myemotes . render _lists . call ( this , view , container , false ) ;
}
} ,
emoji : {
name : "Emoji" ,
sort _order : 3 ,
visible : function ( ) { return this . settings . emoji _in _menu } ,
render : function ( view , container ) {
var sets = [ ] ;
for ( var cat in constants . EMOJI _CATEGORIES ) {
var menu = FFZ . menu _pages . myemotes . draw _emoji . call ( this , view , cat , false ) ;
if ( menu )
sets . push ( [ cat , menu ] ) ;
}
sets . sort ( function ( a , b ) {
var an = a [ 0 ] , bn = b [ 0 ] ;
if ( an < bn ) return - 1 ;
if ( an > bn ) return 1 ;
return 0 ;
} ) ;
2016-07-14 23:01:15 -04:00
if ( sets . length )
sets [ 0 ] [ 1 ] . classList . add ( 'top-set' ) ;
2016-07-13 02:31:26 -04:00
for ( var i = 0 ; i < sets . length ; i ++ )
container . appendChild ( sets [ i ] [ 1 ] ) ;
}
}
} ,
render _lists : function ( view , container , favorites _only ) {
2016-10-12 20:54:09 -04:00
var controller = utils . ember _lookup ( 'controller:chat' ) ,
2017-08-16 13:24:55 -04:00
user _emotes = utils . ember _lookup ( 'service:user-emotes' ) ,
2017-09-15 14:41:00 -04:00
twitch _sets = ( user _emotes && user _emotes . allEmotes || { } ) [ 'emoticon_sets' ] || { } ,
2015-08-02 02:41:03 -04:00
2016-07-13 02:31:26 -04:00
user = this . get _user ( ) ,
ffz _sets = this . getEmotes ( user && user . login , null ) ,
2017-04-05 19:12:11 -04:00
sets = [ ] ,
gathered _emotes = [ ] ;
2016-07-13 02:31:26 -04:00
// Start with Twitch Sets
2017-06-11 13:30:37 -04:00
var gathered _favorites = this . settings . favorite _emotes [ 'twitch-inventory' ] || [ ] ,
gathered _channels = { } ,
other _channels = [ ] ;
2017-04-05 19:12:11 -04:00
2016-07-13 02:31:26 -04:00
for ( var set _id in twitch _sets ) {
2017-04-05 19:12:11 -04:00
if ( ! twitch _sets . hasOwnProperty ( set _id ) || ( ! favorites _only && ! this . settings . global _emotes _in _menu && set _id === '0' ) )
2016-07-13 02:31:26 -04:00
continue ;
2016-10-05 23:07:10 -04:00
// Skip the Twitch Turbo set if we have Twitch Prime. They're identical.
if ( set _id == 793 && twitch _sets . hasOwnProperty ( 19194 ) )
continue ;
2016-07-13 02:31:26 -04:00
var set = twitch _sets [ set _id ] ;
if ( ! set . length )
continue ;
2017-06-11 13:30:37 -04:00
if ( this . _twitch _inventory _sets . indexOf ( set _id ) !== - 1 || EXTRA _INVENTORY . indexOf ( set _id ) !== - 1 ) {
2017-04-22 22:34:22 -04:00
for ( var i = 0 ; i < set . length ; i ++ )
if ( ! favorites _only || gathered _favorites . indexOf ( set [ i ] . id ) !== - 1 )
gathered _emotes . push ( set [ i ] ) ;
2017-04-05 19:12:11 -04:00
continue ;
}
2017-09-15 14:41:00 -04:00
var raw _data = this . get _twitch _set ( set _id ) ,
raw _id = raw _data && raw _data . c _name ,
2017-04-22 22:34:22 -04:00
menu _id = raw _id ? raw _id . toLowerCase ( ) : 'unknown' ,
favorites _list = this . settings . favorite _emotes [ "twitch-" + set _id ] ;
2017-04-05 19:12:11 -04:00
if ( favorites _only && ( ! favorites _list || ! favorites _list . length ) )
continue ;
2017-06-11 13:30:37 -04:00
if ( menu _id !== 'unknown' ) {
var gathered = gathered _channels [ menu _id ] = gathered _channels [ menu _id ] || [ ] ;
gathered . push ( set _id ) ;
continue ;
}
2017-04-05 19:12:11 -04:00
var sort _key = 0 ,
2016-11-20 13:43:12 -05:00
menu = FFZ . menu _pages . myemotes . draw _twitch _set . call ( this , view , set _id , set , favorites _only ) ;
if ( menu _id . indexOf ( 'global' ) !== - 1 )
sort _key = 100 ;
else if ( menu _id . substr ( 0 , 2 ) === '--' || menu _id === 'turbo' )
sort _key = 75 ;
2016-07-13 02:31:26 -04:00
if ( menu )
2016-11-20 13:43:12 -05:00
sets . push ( [ [ sort _key , menu _id ] , menu ] ) ;
2016-07-13 02:31:26 -04:00
}
2017-06-11 13:30:37 -04:00
for ( var menu _id in gathered _channels ) {
var gathered = [ ] ,
stuff = gathered _channels [ menu _id ] ;
if ( ! stuff . length )
continue ;
for ( var i = 0 ; i < stuff . length ; i ++ ) {
var set _id = stuff [ i ] ,
set = twitch _sets [ set _id ] ;
for ( var j = 0 ; j < set . length ; j ++ )
gathered . push ( [ set _id , set [ j ] ] ) ;
}
var sort _key = 0 ,
menu = FFZ . menu _pages . myemotes . draw _twitch _set . call ( this , view , stuff [ 0 ] , gathered , favorites _only ) ;
if ( menu _id . indexOf ( 'global' ) !== - 1 )
sort _key = 100 ;
else if ( menu _id . substr ( 0 , 2 ) === '--' || menu _id === 'turbo' )
sort _key = 75 ;
if ( menu )
sets . push ( [ [ sort _key , menu _id ] , menu ] ) ;
}
2017-04-05 19:12:11 -04:00
// Handle the gathered single emotes.
if ( gathered _emotes . length ) {
var menu = FFZ . menu _pages . myemotes . draw _twitch _set . call ( this , view , 'inventory' , gathered _emotes , favorites _only ) ;
sets . push ( [ [ 50 , 'twitch-inventory' ] , menu ] ) ;
}
2016-07-13 02:31:26 -04:00
// Emoji~!
if ( favorites _only && this . settings . emoji _in _menu ) {
var favorites _list = this . settings . favorite _emotes [ "emoji" ] ;
if ( favorites _list && favorites _list . length ) {
var menu = FFZ . menu _pages . myemotes . draw _emoji . call ( this , view , null , favorites _only ) ;
if ( menu )
2016-11-20 13:43:12 -05:00
sets . push ( [ [ 200 , "emoji" ] , menu ] ) ;
2016-07-13 02:31:26 -04:00
}
}
// Now, FFZ!
2017-04-05 19:12:11 -04:00
if ( favorites _only ) {
// But first, inject all the sets from this specific room.
var ffz _room = controller && this . rooms && this . rooms [ controller . get ( 'currentRoom.id' ) ] ;
if ( ffz _room ) {
if ( ffz _room . set && ffz _sets . indexOf ( ffz _room . set ) === - 1 )
ffz _sets . push ( ffz _room . set ) ;
if ( ffz _room . sets && ffz _room . sets . length )
ffz _sets = _ . uniq ( ffz _sets . concat ( ffz _room . sets ) ) ;
if ( ffz _room . extra _sets && ffz _room . extra _sets . length )
ffz _sets = _ . uniq ( ffz _sets . concat ( ffz _room . extra _sets ) ) ;
}
}
2016-07-13 02:31:26 -04:00
for ( var i = 0 ; i < ffz _sets . length ; i ++ ) {
var set _id = ffz _sets [ i ] ,
2016-12-15 18:39:23 -05:00
set = this . emote _sets [ set _id ] ;
2017-04-05 19:12:11 -04:00
if ( ! set || ! set . count || set . hidden || ( ! favorites _only && ! this . settings . global _emotes _in _menu && this . default _sets . indexOf ( set _id ) !== - 1 ) )
2016-12-15 18:39:23 -05:00
continue ;
2016-07-13 02:31:26 -04:00
2016-12-15 18:39:23 -05:00
var menu _id = set . hasOwnProperty ( 'source_ext' ) ? 'ffz-ext-' + set . source _ext + '-' + set . source _id : 'ffz-' + set . id ,
2016-07-13 02:31:26 -04:00
favorites _list = this . settings . favorite _emotes [ menu _id ] ;
if ( favorites _only && ( ! favorites _list || ! favorites _list . length ) )
continue ;
2016-11-20 13:43:12 -05:00
var menu _id = set . title . toLowerCase ( ) ,
sort _key = set . sort ,
menu = FFZ . menu _pages . myemotes . draw _ffz _set . call ( this , view , set , favorites _only ) ;
if ( sort _key === undefined || sort _key === null ) {
if ( menu _id . indexOf ( 'global' ) !== - 1 )
sort _key = 100 ;
else
sort _key = 0 ;
}
2016-07-13 02:31:26 -04:00
if ( menu )
2016-11-20 13:43:12 -05:00
sets . push ( [ [ sort _key , menu _id ] , menu ] ) ;
2016-07-13 02:31:26 -04:00
}
if ( ! sets . length )
return false ;
// Finally, sort and add them all.
sets . sort ( function ( a , b ) {
2016-11-20 13:43:12 -05:00
var ask = a [ 0 ] [ 0 ] ,
an = a [ 0 ] [ 1 ] ,
bsk = b [ 0 ] [ 0 ] ,
bn = b [ 0 ] [ 1 ] ;
if ( ask < bsk ) return - 1 ;
if ( ask > bsk ) return 1 ;
2016-07-13 02:31:26 -04:00
if ( an < bn ) return - 1 ;
if ( an > bn ) return 1 ;
return 0 ;
} ) ;
if ( favorites _only ) {
var grid = document . createElement ( 'div' ) ;
grid . className = 'emoticon-grid favorites-grid' ;
for ( var i = 0 ; i < sets . length ; i ++ )
grid . appendChild ( sets [ i ] [ 1 ] ) ;
container . appendChild ( grid ) ;
2016-07-14 23:01:15 -04:00
} else if ( sets . length ) {
sets [ 0 ] [ 1 ] . classList . add ( 'top-set' ) ;
2016-07-13 02:31:26 -04:00
for ( var i = 0 ; i < sets . length ; i ++ )
container . appendChild ( sets [ i ] [ 1 ] ) ;
2016-07-14 23:01:15 -04:00
}
2016-07-13 02:31:26 -04:00
return true ;
2015-06-05 03:59:28 -04:00
} ,
2015-02-24 00:33:29 -05:00
2017-06-11 13:30:37 -04:00
toggle _section : function ( heading , container , set _state ) {
2015-07-13 21:52:44 -04:00
var menu = heading . parentElement ,
set _id = menu . getAttribute ( 'data-set' ) ,
collapsed _list = this . settings . emote _menu _collapsed ,
2017-06-11 13:30:37 -04:00
has _state = set _state !== undefined ,
is _collapsed = has _state ? set _state : collapsed _list . indexOf ( set _id ) === - 1 ;
2015-07-13 21:52:44 -04:00
2017-06-11 13:30:37 -04:00
if ( ! has _state ) {
if ( ! is _collapsed )
collapsed _list . removeObject ( set _id ) ;
else
collapsed _list . push ( set _id ) ;
this . settings . set ( 'emote_menu_collapsed' , collapsed _list , true ) ;
}
2015-07-13 21:52:44 -04:00
menu . classList . toggle ( 'collapsed' , ! is _collapsed ) ;
2016-03-23 19:28:22 -04:00
2016-07-13 02:31:26 -04:00
if ( is _collapsed )
menu . appendChild ( container ) ;
else
menu . removeChild ( container ) ;
2015-07-13 21:52:44 -04:00
} ,
2016-03-23 19:28:22 -04:00
draw _emoji : function ( view , cat , favorites _only ) {
2015-07-06 00:09:21 -04:00
var heading = document . createElement ( 'div' ) ,
2015-07-13 21:52:44 -04:00
menu = document . createElement ( 'div' ) ,
2016-07-13 02:31:26 -04:00
menu _id = 'emoji' + ( cat ? '-' + cat : '' ) ,
emotes = favorites _only ? document . createDocumentFragment ( ) : document . createElement ( 'div' ) ,
collapsed = ! favorites _only && this . settings . emote _menu _collapsed . indexOf ( menu _id ) === - 1 ,
2015-08-28 22:54:12 -04:00
f = this ,
2016-03-23 19:28:22 -04:00
settings = this . settings . parse _emoji || 1 ,
2015-08-28 22:54:12 -04:00
2016-07-13 02:31:26 -04:00
favorites = this . settings . favorite _emotes [ "emoji" ] || [ ] ,
c = 0 ;
2015-07-06 00:09:21 -04:00
2016-07-13 02:31:26 -04:00
menu . className = 'emoticon-grid' ;
menu . setAttribute ( 'data-set' , menu _id ) ;
2015-07-06 00:09:21 -04:00
2016-07-13 02:31:26 -04:00
if ( ! favorites _only ) {
heading . className = 'heading' ;
heading . innerHTML = '<span class="right">Unicode</span>' + ( cat ? utils . sanitize ( constants . EMOJI _CATEGORIES [ cat ] ) : 'Emoji' ) ;
heading . style . backgroundImage = 'url("' + constants . SERVER + 'emoji/' + ( settings === 3 ? 'one/' : ( settings === 2 ? 'noto-' : 'tw/' ) ) + ( constants . EMOJI _LOGOS [ cat ] || '1f4af' ) + '.svg")' ;
heading . style . backgroundSize = "18px" ;
2015-08-02 02:41:03 -04:00
2016-07-13 02:31:26 -04:00
menu . classList . add ( 'collapsable' ) ;
menu . appendChild ( heading ) ;
menu . classList . toggle ( 'collapsed' , collapsed ) ;
2017-06-11 13:30:37 -04:00
heading . addEventListener ( 'click' , function ( ) { FFZ . menu _pages . myemotes . toggle _section . bind ( f ) ( this , emotes ) ; } ) ;
2016-07-13 02:31:26 -04:00
}
2015-08-02 02:41:03 -04:00
2015-07-06 00:09:21 -04:00
var set = [ ] ;
2015-08-28 22:54:12 -04:00
2015-07-06 00:09:21 -04:00
for ( var eid in this . emoji _data )
set . push ( this . emoji _data [ eid ] ) ;
2015-08-02 02:41:03 -04:00
2015-07-06 00:09:21 -04:00
set . sort ( function ( a , b ) {
2015-08-28 22:54:12 -04:00
var an = ( a . name || "" ) . toLowerCase ( ) ,
bn = ( b . name || "" ) . toLowerCase ( ) ;
2015-07-06 00:09:21 -04:00
if ( an < bn ) return - 1 ;
else if ( an > bn ) return 1 ;
if ( a . raw < b . raw ) return - 1 ;
if ( a . raw > b . raw ) return 1 ;
return 0 ;
} ) ;
2015-08-02 02:41:03 -04:00
2015-07-06 00:09:21 -04:00
for ( var i = 0 ; i < set . length ; i ++ ) {
var emoji = set [ i ] ,
2015-08-28 22:54:12 -04:00
em = document . createElement ( 'span' ) ;
2016-03-23 19:28:22 -04:00
if ( ( cat && cat !== emoji . cat ) || ( settings === 1 && ! emoji . tw ) || ( settings === 2 && ! emoji . noto ) || ( settings === 3 && ! emoji . one ) )
2015-08-28 22:54:12 -04:00
continue ;
2015-07-06 00:09:21 -04:00
2016-03-23 19:28:22 -04:00
var is _favorite = favorites . indexOf ( emoji . raw ) !== - 1 ,
2016-07-13 02:31:26 -04:00
src = settings === 3 ? emoji . one _src : ( settings === 2 ? emoji . noto _src : emoji . tw _src ) ,
2015-11-14 23:52:49 -05:00
image = this . settings . emote _image _hover ? '<img class="emoticon ffz-image-hover" src="' + src + '">' : '' ;
2016-07-13 02:31:26 -04:00
if ( favorites _only && ! is _favorite )
continue ;
2016-03-23 19:28:22 -04:00
em . className = 'emoticon emoji ffz-tooltip ffz-can-favorite' ;
2016-07-13 02:31:26 -04:00
em . classList . toggle ( 'ffz-favorite' , is _favorite ) ;
em . classList . toggle ( 'ffz-is-favorite' , favorites _only ) ;
2016-03-23 19:28:22 -04:00
2016-07-13 02:31:26 -04:00
em . setAttribute ( 'data-ffz-emoji' , emoji . code ) ;
2017-06-11 13:30:37 -04:00
em . setAttribute ( 'data-filter' , emoji . name . toLowerCase ( ) + ' :' + emoji . short _name . toLowerCase ( ) + ':' ) ;
2016-07-13 02:31:26 -04:00
em . alt = emoji . raw ;
2016-03-23 19:28:22 -04:00
em . addEventListener ( 'click' , this . _add _emote . bind ( this , view , emoji . raw , "emoji" , emoji . raw ) ) ;
2015-08-02 02:41:03 -04:00
2015-11-14 23:52:49 -05:00
em . style . backgroundImage = 'url("' + src + '")' ;
2015-08-28 22:54:12 -04:00
em . style . backgroundSize = "18px" ;
2015-08-02 02:41:03 -04:00
2016-07-13 02:31:26 -04:00
c ++ ;
2016-03-23 19:28:22 -04:00
emotes . appendChild ( em ) ;
2015-07-06 00:09:21 -04:00
}
2016-07-13 02:31:26 -04:00
if ( ! c )
return ;
2016-03-23 19:28:22 -04:00
2016-07-13 02:31:26 -04:00
if ( favorites _only )
return emotes ;
2016-03-23 19:28:22 -04:00
2016-07-13 02:31:26 -04:00
if ( ! collapsed )
menu . appendChild ( emotes ) ;
2016-03-23 19:28:22 -04:00
2015-07-06 00:09:21 -04:00
return menu ;
} ,
2016-03-23 19:28:22 -04:00
draw _twitch _set : function ( view , set _id , set , favorites _only ) {
2015-06-05 03:59:28 -04:00
var heading = document . createElement ( 'div' ) ,
menu = document . createElement ( 'div' ) ,
2016-07-13 02:31:26 -04:00
emotes = favorites _only ? document . createDocumentFragment ( ) : document . createElement ( 'div' ) ,
collapsed = ! favorites _only && this . settings . emote _menu _collapsed . indexOf ( 'twitch-' + set _id ) === - 1 ,
2015-07-13 21:52:44 -04:00
f = this ,
2015-02-24 00:33:29 -05:00
2017-09-15 14:41:00 -04:00
set _data = this . get _twitch _set ( set _id ) ,
channel _id = set _id === 'inventory' ? '--inventory--' : ( set _data && set _data . c _name || 'twitch_unknown' ) , title ,
2016-07-13 02:31:26 -04:00
favorites = this . settings . favorite _emotes [ "twitch-" + set _id ] || [ ] ,
c = 0 ;
2015-07-31 21:40:51 -04:00
2016-07-13 02:31:26 -04:00
menu . className = 'emoticon-grid' ;
2015-07-13 21:52:44 -04:00
menu . setAttribute ( 'data-set' , 'twitch-' + set _id ) ;
2016-03-23 19:28:22 -04:00
2016-07-13 02:31:26 -04:00
if ( ! favorites _only ) {
2017-04-05 19:12:11 -04:00
if ( channel _id === '--inventory--' )
title = "Inventory" ;
else if ( channel _id === "twitch_unknown" )
2016-07-13 02:31:26 -04:00
title = "Unknown Channel" ;
else if ( channel _id === "--global--" )
title = "Global Emoticons" ;
else if ( channel _id === "turbo" || channel _id === "--turbo-faces--" )
title = "Twitch Turbo" ;
2016-10-05 23:07:10 -04:00
else if ( channel _id === "--prime--" || channel _id === "--prime-faces--" )
2016-10-01 13:43:08 -04:00
title = "Twitch Prime" ;
2016-10-05 23:07:10 -04:00
else if ( channel _id === "--curse--" )
title = "Curse Emoticons" ;
2016-07-13 02:31:26 -04:00
else
title = FFZ . get _capitalization ( channel _id , function ( name ) {
heading . innerHTML = '<span class="right">Twitch</span>' + utils . sanitize ( name ) ;
} ) ;
heading . className = 'heading' ;
heading . innerHTML = '<span class="right">Twitch</span>' + utils . sanitize ( title ) ;
2017-04-05 19:12:11 -04:00
var icon = this . _twitch _badges [ channel _id ] ;
if ( icon ) {
heading . style . backgroundImage = 'url("' + icon + '")' ;
if ( icon . indexOf ( '.svg' ) !== - 1 )
heading . style . backgroundSize = "18px" ;
2017-09-15 14:41:00 -04:00
} else if ( set _data ) {
2016-07-13 02:31:26 -04:00
var f = this ;
2017-09-15 14:41:00 -04:00
fetch ( "https://badges.twitch.tv/v1/badges/channels/" + set _data . c _id + "/display?language=" + ( Twitch . receivedLanguage || "en" ) , {
headers : {
'Client-ID' : constants . CLIENT _ID
}
} ) . then ( utils . json ) . then ( function ( data ) {
try {
var badge = f . _twitch _badges [ channel _id ] = data . badge _sets . subscriber . versions [ 0 ] . image _url _1x ;
heading . style . backgroundImage = 'url("' + badge + '")' ;
} catch ( err ) { /* Lament JS's lack of null coalescing operators */ }
} ) ;
2016-07-13 02:31:26 -04:00
}
menu . classList . add ( 'collapsable' ) ;
menu . appendChild ( heading ) ;
menu . classList . toggle ( 'collapsed' , collapsed ) ;
heading . addEventListener ( 'click' , function ( ) { FFZ . menu _pages . myemotes . toggle _section . bind ( f ) ( this , emotes ) ; } ) ;
}
2015-02-26 17:27:39 -05:00
2015-07-06 00:09:21 -04:00
set . sort ( function ( a , b ) {
2017-06-11 13:30:37 -04:00
if ( Array . isArray ( a ) )
a = a [ 1 ] ;
if ( Array . isArray ( b ) )
b = b [ 1 ] ;
2015-07-06 00:09:21 -04:00
var an = a . code . toLowerCase ( ) ,
bn = b . code . toLowerCase ( ) ;
if ( an < bn ) return - 1 ;
else if ( an > bn ) return 1 ;
if ( a . id < b . id ) return - 1 ;
if ( a . id > b . id ) return 1 ;
return 0 ;
} ) ;
2015-06-05 03:59:28 -04:00
for ( var i = 0 ; i < set . length ; i ++ ) {
var emote = set [ i ] ,
2017-06-11 13:30:37 -04:00
esid = set _id ,
favs = favorites ;
if ( Array . isArray ( emote ) ) {
esid = emote [ 0 ] ;
emote = emote [ 1 ] ;
favs = this . settings . favorite _emotes [ "twitch-" + esid ] || [ ] ;
}
var code = constants . KNOWN _CODES [ emote . code ] || emote . code ,
is _favorite = favs . indexOf ( emote . id ) !== - 1 ;
2016-03-23 19:28:22 -04:00
2016-07-13 02:31:26 -04:00
if ( favorites _only && ! is _favorite )
continue ;
2016-03-23 19:28:22 -04:00
2016-07-13 02:31:26 -04:00
var em = document . createElement ( 'span' ) ,
2016-03-23 19:28:22 -04:00
img _set = 'image-set(url("' + constants . TWITCH _BASE + emote . id + '/1.0") 1x, url("' + constants . TWITCH _BASE + emote . id + '/2.0") 2x)' ;
2015-02-24 00:33:29 -05:00
2016-03-23 19:28:22 -04:00
em . className = 'emoticon ffz-tooltip ffz-can-favorite' ;
2016-07-13 02:31:26 -04:00
em . setAttribute ( 'data-emote' , emote . id ) ;
2017-06-11 13:30:37 -04:00
em . setAttribute ( 'data-filter' , code . toLowerCase ( ) ) ;
2016-07-13 02:31:26 -04:00
em . alt = code ;
2015-02-24 00:33:29 -05:00
2016-07-13 02:31:26 -04:00
em . classList . toggle ( 'ffz-favorite' , is _favorite ) ;
em . classList . toggle ( 'ffz-is-favorite' , favorites _only ) ;
em . classList . toggle ( 'ffz-tooltip-no-credit' , ! favorites _only ) ;
2015-07-06 00:09:21 -04:00
if ( this . settings . replace _bad _emotes && constants . EMOTE _REPLACEMENTS [ emote . id ] ) {
em . style . backgroundImage = 'url("' + constants . EMOTE _REPLACEMENT _BASE + constants . EMOTE _REPLACEMENTS [ emote . id ] + '")' ;
} else {
2015-11-14 23:52:49 -05:00
em . style . backgroundImage = 'url("' + constants . TWITCH _BASE + emote . id + '/1.0")' ;
2015-07-06 00:09:21 -04:00
em . style . backgroundImage = '-webkit-' + img _set ;
em . style . backgroundImage = '-moz-' + img _set ;
em . style . backgroundImage = '-ms-' + img _set ;
2016-03-23 19:28:22 -04:00
em . style . backgroundImage = img _set ;
2015-07-06 00:09:21 -04:00
}
2015-02-24 00:33:29 -05:00
2017-06-11 13:30:37 -04:00
em . addEventListener ( "click" , function ( id , c , q , e ) {
2015-08-02 02:41:03 -04:00
e . preventDefault ( ) ;
if ( ( e . shiftKey || e . shiftLeft ) && f . settings . clickable _emoticons )
window . open ( "https://twitchemotes.com/emote/" + id ) ;
else
2017-06-11 13:30:37 -04:00
this . _add _emote ( view , c , "twitch-" + q , id , e ) ;
} . bind ( this , emote . id , code , esid ) ) ;
2016-03-23 19:28:22 -04:00
2016-07-13 02:31:26 -04:00
c ++ ;
2016-03-23 19:28:22 -04:00
emotes . appendChild ( em ) ;
2015-06-05 03:59:28 -04:00
}
2015-02-24 00:33:29 -05:00
2016-07-13 02:31:26 -04:00
if ( ! c )
return ;
2016-03-23 19:28:22 -04:00
2016-07-13 02:31:26 -04:00
if ( favorites _only )
return emotes ;
2016-03-23 19:28:22 -04:00
2016-07-13 02:31:26 -04:00
if ( ! collapsed )
menu . appendChild ( emotes ) ;
2016-03-23 19:28:22 -04:00
2015-06-05 03:59:28 -04:00
return menu ;
} ,
2015-02-24 00:33:29 -05:00
2016-03-23 19:28:22 -04:00
draw _ffz _set : function ( view , set , favorites _only ) {
2015-06-05 03:59:28 -04:00
var heading = document . createElement ( 'div' ) ,
menu = document . createElement ( 'div' ) ,
2016-07-13 02:31:26 -04:00
emote _container = favorites _only ? document . createDocumentFragment ( ) : document . createElement ( 'div' ) ,
2015-07-13 21:52:44 -04:00
f = this ,
2015-10-24 22:44:00 -04:00
emotes = [ ] ,
menu _id = set . hasOwnProperty ( 'source_ext' ) ? 'ffz-ext-' + set . source _ext + '-' + set . source _id : 'ffz-' + set . id ,
2016-07-13 02:31:26 -04:00
favorites = this . settings . favorite _emotes [ menu _id ] || [ ] ,
c = 0 ,
2016-09-09 17:34:20 -04:00
icon = set . icon || ( set . hasOwnProperty ( 'source_ext' ) && this . _apis [ set . source _ext ] && this . _apis [ set . source _ext ] . icon ) || '//cdn.frankerfacez.com/script/devicon.png' ,
2016-07-13 02:31:26 -04:00
collapsed = ! favorites _only && this . settings . emote _menu _collapsed . indexOf ( menu _id ) === - 1 ;
2016-03-23 19:28:22 -04:00
menu . className = 'emoticon-grid' ;
2016-07-13 02:31:26 -04:00
menu . setAttribute ( 'data-set' , menu _id ) ;
2015-02-26 17:27:39 -05:00
2016-07-13 02:31:26 -04:00
if ( ! favorites _only ) {
menu . classList . add ( 'collapsable' ) ;
2015-10-24 22:44:00 -04:00
2016-07-13 02:31:26 -04:00
heading . className = 'heading' ;
heading . innerHTML = '<span class="right">' + ( utils . sanitize ( set . source ) || 'FrankerFaceZ' ) + '</span>' + set . title ;
2015-02-26 17:27:39 -05:00
2016-07-13 02:31:26 -04:00
heading . style . backgroundImage = 'url("' + icon + '")' ;
if ( icon . indexOf ( '.svg' ) !== - 1 )
heading . style . backgroundSize = "18px" ;
2015-08-02 02:41:03 -04:00
2016-07-13 02:31:26 -04:00
menu . appendChild ( heading ) ;
menu . classList . toggle ( 'collapsed' , collapsed ) ;
heading . addEventListener ( 'click' , function ( ) { FFZ . menu _pages . myemotes . toggle _section . bind ( f ) ( this , emote _container ) ; } ) ;
}
2015-02-26 17:27:39 -05:00
2015-06-05 03:59:28 -04:00
for ( var emote _id in set . emoticons )
set . emoticons . hasOwnProperty ( emote _id ) && ! set . emoticons [ emote _id ] . hidden && emotes . push ( set . emoticons [ emote _id ] ) ;
2015-02-26 17:27:39 -05:00
2015-06-05 03:59:28 -04:00
emotes . sort ( function ( a , b ) {
var an = a . name . toLowerCase ( ) ,
bn = b . name . toLowerCase ( ) ;
2015-02-26 17:27:39 -05:00
2015-06-05 03:59:28 -04:00
if ( an < bn ) return - 1 ;
else if ( an > bn ) return 1 ;
if ( a . id < b . id ) return - 1 ;
if ( a . id > b . id ) return 1 ;
return 0 ;
} ) ;
2015-02-26 17:27:39 -05:00
2015-06-05 03:59:28 -04:00
for ( var i = 0 ; i < emotes . length ; i ++ ) {
var emote = emotes [ i ] ,
2016-07-13 02:31:26 -04:00
is _favorite = favorites . indexOf ( emote . id ) !== - 1 ;
2015-06-05 03:59:28 -04:00
2016-07-13 02:31:26 -04:00
if ( favorites _only && ! is _favorite )
continue ;
2016-03-23 19:28:22 -04:00
2016-07-13 02:31:26 -04:00
var em = document . createElement ( 'span' ) ,
2015-06-05 03:59:28 -04:00
img _set = 'image-set(url("' + emote . urls [ 1 ] + '") 1x' ;
if ( emote . urls [ 2 ] )
img _set += ', url("' + emote . urls [ 2 ] + '") 2x' ;
2015-02-26 17:27:39 -05:00
2015-06-05 03:59:28 -04:00
if ( emote . urls [ 4 ] )
img _set += ', url("' + emote . urls [ 4 ] + '") 4x' ;
2015-02-24 00:33:29 -05:00
2015-06-05 03:59:28 -04:00
img _set += ')' ;
2015-02-24 00:33:29 -05:00
2016-03-23 19:28:22 -04:00
em . className = 'emoticon ffz-tooltip ffz-can-favorite' ;
2016-07-13 02:31:26 -04:00
em . classList . toggle ( 'ffz-favorite' , is _favorite ) ;
em . classList . toggle ( 'ffz-is-favorite' , favorites _only ) ;
2016-03-23 19:28:22 -04:00
2016-07-13 02:31:26 -04:00
em . setAttribute ( 'data-ffz-emote' , emote . id ) ;
em . setAttribute ( 'data-ffz-set' , set . id ) ;
2017-06-11 13:30:37 -04:00
em . setAttribute ( 'data-filter' , emote . name . toLowerCase ( ) ) ;
2016-03-23 19:28:22 -04:00
2015-06-05 03:59:28 -04:00
em . style . backgroundImage = 'url("' + emote . urls [ 1 ] + '")' ;
em . style . backgroundImage = '-webkit-' + img _set ;
em . style . backgroundImage = '-moz-' + img _set ;
em . style . backgroundImage = '-ms-' + img _set ;
2016-03-23 19:28:22 -04:00
em . style . backgroundImage = img _set ;
2015-02-24 00:33:29 -05:00
2015-06-05 03:59:28 -04:00
if ( emote . height )
2016-03-23 19:28:22 -04:00
em . style . height = ( 10 + emote . height ) + "px" ;
2015-06-05 03:59:28 -04:00
if ( emote . width )
2016-03-23 19:28:22 -04:00
em . style . width = ( 10 + emote . width ) + "px" ;
2015-02-24 00:33:29 -05:00
2015-08-02 02:41:03 -04:00
em . addEventListener ( "click" , function ( id , code , e ) {
e . preventDefault ( ) ;
2015-10-27 14:25:13 -04:00
if ( ( e . shiftKey || e . shiftLeft ) && f . settings . clickable _emoticons ) {
var url ;
if ( set . hasOwnProperty ( 'source_ext' ) ) {
var api = f . _apis [ set . source _ext ] ;
if ( api && api . emote _url _generator )
url = api . emote _url _generator ( set . source _id , id ) ;
} else
url = "https://www.frankerfacez.com/emoticons/" + id ;
if ( url )
window . open ( url ) ;
} else
2016-03-23 19:28:22 -04:00
this . _add _emote ( view , code , menu _id , id , e ) ;
2015-08-02 02:41:03 -04:00
} . bind ( this , emote . id , emote . name ) ) ;
2015-02-26 17:27:39 -05:00
2016-07-13 02:31:26 -04:00
c ++ ;
2016-03-23 19:28:22 -04:00
emote _container . appendChild ( em ) ;
}
2015-02-24 00:33:29 -05:00
2016-07-13 02:31:26 -04:00
if ( ! c )
return ;
2015-02-24 00:33:29 -05:00
2016-07-13 02:31:26 -04:00
if ( favorites _only )
return emote _container ;
2015-02-24 00:33:29 -05:00
2016-07-13 02:31:26 -04:00
if ( ! collapsed )
menu . appendChild ( emote _container ) ;
2015-02-24 00:33:29 -05:00
2016-03-23 19:28:22 -04:00
return menu ;
2015-06-05 03:59:28 -04:00
}
} ;