2015-02-10 01:34:23 -05:00
var FFZ = window . FrankerFaceZ ,
utils = require ( "../utils" ) ,
2015-07-13 21:52:44 -04:00
constants = require ( "../constants" ) ,
2015-07-04 17:06:36 -04:00
helpers ,
2015-02-10 01:34:23 -05:00
keycodes = {
ESC : 27 ,
P : 80 ,
B : 66 ,
2015-05-17 19:02:57 -04:00
T : 84 ,
U : 85
2015-02-10 01:34:23 -05:00
} ,
2015-02-10 02:42:11 -05:00
MESSAGE = '<svg class="svg-messages" height="16px" version="1.1" viewBox="0 0 18 18" width="16px" x="0px" y="0px"><path clip-rule="evenodd" d="M1,15V3h16v12H1z M15.354,5.354l-0.707-0.707L9,10.293L3.354,4.646L2.646,5.354L6.293,9l-3.646,3.646l0.707,0.707L7,9.707l1.646,1.646h0.707L11,9.707l3.646,3.646l0.707-0.707L11.707,9L15.354,5.354z" fill-rule="evenodd"></path></svg>' ,
2015-10-17 18:05:44 -04:00
CHECK = '<svg class="svg-unban" height="16px" version="1.1" viewBox="0 0 16 16" width="16px" x="0px" y="0px"><path fill-rule="evenodd" clip-rule="evenodd" fill="#888888" d="M6.5,12.75L2,8.25l2-2l2.5,2.5l5.5-5.5l2,2L6.5,12.75z"/></svg>' ;
2015-07-04 17:06:36 -04:00
try {
helpers = window . require && window . require ( "ember-twitch-chat/helpers/chat-line-helpers" ) ;
} catch ( err ) { }
2015-02-10 01:34:23 -05:00
// ----------------
// Settings
// ----------------
2015-08-04 01:43:08 -04:00
FFZ . basic _settings . enhanced _moderation _cards = {
type : "boolean" ,
no _bttv : true ,
category : "Chat" ,
name : "Enhanced Moderation Cards" ,
help : "Improve moderation cards with hotkeys, additional buttons, chat history, and other information to make moderating easier." ,
get : function ( ) {
return this . settings . mod _card _hotkeys &&
this . settings . mod _card _info &&
this . settings . mod _card _history ;
} ,
set : function ( val ) {
this . settings . set ( 'mod_card_hotkeys' , val ) ;
this . settings . set ( 'mod_card_info' , val ) ;
this . settings . set ( 'mod_card_history' , val ) ;
}
} ;
FFZ . basic _settings . chat _hover _pause = {
type : "boolean" ,
no _bttv : true ,
category : "Chat" ,
name : "Pause Chat Scrolling on Mouse Hover" ,
help : "Automatically prevent the chat from scrolling when moving the mouse over it to prevent moderation mistakes and link misclicks." ,
get : 'chat_hover_pause' ,
set : 'chat_hover_pause'
} ;
2015-07-04 17:06:36 -04:00
FFZ . settings _info . chat _hover _pause = {
2015-02-10 01:34:23 -05:00
type : "boolean" ,
value : false ,
2015-05-17 19:02:57 -04:00
no _bttv : true ,
2015-02-10 01:34:23 -05:00
2015-07-04 17:06:36 -04:00
category : "Chat Moderation" ,
name : "Pause Chat Scrolling on Mouse Hover" ,
2015-08-04 01:43:08 -04:00
help : "Automatically prevent the chat from scrolling when moving the mouse over it to prevent moderation mistakes and link misclicks." ,
2015-07-04 17:06:36 -04:00
on _update : function ( val ) {
if ( ! this . _roomv )
return ;
if ( val )
this . _roomv . ffzEnableFreeze ( ) ;
else
this . _roomv . ffzDisableFreeze ( ) ;
}
} ;
FFZ . settings _info . short _commands = {
type : "boolean" ,
value : true ,
no _bttv : true ,
category : "Chat Moderation" ,
name : "Short Moderation Commands" ,
help : "Use /t, /b, and /u in chat in place of /timeout, /ban, /unban for quicker moderation, and use /p for 1 second timeouts."
} ;
FFZ . settings _info . mod _card _hotkeys = {
type : "boolean" ,
value : false ,
no _bttv : true ,
category : "Chat Moderation" ,
name : "Moderation Card Hotkeys" ,
help : "With a moderation card selected, press B to ban the user, T to time them out for 10 minutes, P to time them out for 1 second, or U to unban them. ESC closes the card."
} ;
2015-07-13 21:52:44 -04:00
FFZ . settings _info . mod _card _info = {
type : "boolean" ,
2015-07-18 21:10:27 -04:00
value : true ,
2015-07-13 21:52:44 -04:00
no _bttv : true ,
category : "Chat Moderation" ,
name : "Moderation Card Additional Information" ,
help : "Display a channel's follower count, view count, and account age on moderation cards."
} ;
2015-07-04 17:06:36 -04:00
FFZ . settings _info . mod _card _history = {
type : "boolean" ,
value : false ,
no _bttv : true ,
category : "Chat Moderation" ,
name : "Moderation Card History" ,
help : "Display a few of the user's previously sent messages on moderation cards." ,
on _update : function ( val ) {
if ( val || ! this . rooms )
return ;
// Delete all history~!
for ( var room _id in this . rooms ) {
var room = this . rooms [ room _id ] ;
if ( room )
room . user _history = undefined ;
}
}
} ;
2015-10-17 18:05:44 -04:00
FFZ . settings _info . mod _buttons = {
type : "button" ,
// Special Values
// false = Ban/Unban
// integer = Timeout (that amount of time)
value : [ [ '' , false , false ] , [ '' , 600 , false ] ] , //, ['', 1, false]],
category : "Chat Moderation" ,
no _bttv : true ,
name : "Custom In-Line Moderation Icons" ,
help : "Change out the different in-line moderation icons to use any command quickly." ,
method : function ( ) {
2016-03-23 19:28:22 -04:00
var f = this ,
old _val = "" ;
2015-10-17 18:05:44 -04:00
for ( var i = 0 ; i < this . settings . mod _buttons . length ; i ++ ) {
var pair = this . settings . mod _buttons [ i ] ,
prefix = pair [ 0 ] , cmd = pair [ 1 ] , had _prefix = pair [ 2 ] ;
if ( cmd === false )
cmd = "<BAN>" ;
else if ( typeof cmd !== "string" )
cmd = '' + cmd ;
if ( ! had _prefix )
prefix = '' ;
else
prefix += '=' ;
if ( cmd . substr ( cmd . length - 7 ) === ' {user}' )
cmd = cmd . substr ( 0 , cmd . length - 7 ) ;
if ( cmd . indexOf ( ' ' ) !== - 1 )
old _val += ' ' + prefix + '"' + cmd + '"' ;
else
old _val += ' ' + prefix + cmd ;
}
2016-03-23 19:28:22 -04:00
utils . prompt (
"Custom In-Line Moderation Icons" ,
"Please enter a list of commands to be made available as mod icons within chat lines. Commands are separated by spaces. " +
"To include spaces in a command, surround the command with double quotes (\"). Use <code>{user}</code> to insert the user's name " +
"into the command, otherwise it will be appended to the end.</p><p><b>Example:</b> <code>!permit \"!reg add {user}\"</code></p><p>To " +
"send multiple commands, separate them with <code><LINE></code>.</p><p>Numeric values will become timeout buttons for " +
"that number of seconds. The text <code><BAN></code> is a special value that will act like the normal Ban button in chat.</p><p>" +
"To assign a specific letter for use as the icon, specify it at the start of the command followed by an equals sign.</p><p>" +
"<b>Example:</b> <code>A=\"!reg add\"</code></p><p><b>Default:</b> <code><BAN> 600</code>" ,
old _val . substr ( 1 ) ,
function ( new _val ) {
if ( new _val === null || new _val === undefined )
return ;
var vals = [ ] , prefix = '' ;
new _val = new _val . trim ( ) ;
while ( new _val ) {
if ( new _val . charAt ( 1 ) === '=' ) {
prefix = new _val . charAt ( 0 ) ;
new _val = new _val . substr ( 2 ) ;
continue ;
}
if ( new _val . charAt ( 0 ) === '"' ) {
var end = new _val . indexOf ( '"' , 1 ) ;
if ( end === - 1 )
end = new _val . length ;
var segment = new _val . substr ( 1 , end - 1 ) ;
if ( segment ) {
vals . push ( [ prefix , segment ] ) ;
prefix = '' ;
}
new _val = new _val . substr ( end + 1 ) ;
} else {
var ind = new _val . indexOf ( ' ' ) ;
if ( ind === - 1 ) {
if ( new _val ) {
vals . push ( [ prefix , new _val ] ) ;
prefix = '' ;
}
new _val = '' ;
} else {
var segment = new _val . substr ( 0 , ind ) ;
if ( segment ) {
vals . push ( [ prefix , segment ] ) ;
prefix = '' ;
}
new _val = new _val . substr ( ind + 1 ) ;
}
}
}
var final = [ ] ;
for ( var i = 0 ; i < vals . length ; i ++ ) {
var had _prefix = false , prefix = vals [ i ] [ 0 ] , val = vals [ i ] [ 1 ] ;
if ( val === "<BAN>" )
val = false ;
var num = parseInt ( val ) ;
if ( num > 0 && ! Number . isNaN ( num ) )
val = num ;
if ( ! prefix ) {
var tmp ;
if ( typeof val === "string" )
tmp = /\w/ . exec ( val ) ;
else
tmp = utils . duration _string ( val ) ;
prefix = tmp && tmp . length ? tmp [ 0 ] . toUpperCase ( ) : "C" ;
} else
had _prefix = true ;
if ( typeof val === "string" ) {
// Split it up for this step.
var lines = val . split ( / *<LINE> */ ) ;
for ( var x = 0 ; x < lines . length ; x ++ ) {
if ( lines [ x ] . indexOf ( '{user}' ) === - 1 )
lines [ x ] += ' {user}' ;
}
val = lines . join ( "<LINE>" ) ;
}
final . push ( [ prefix , val , had _prefix ] ) ;
}
f . settings . set ( 'mod_buttons' , final ) ;
} , 600 ) ;
2015-10-17 18:05:44 -04:00
}
} ;
2015-07-13 21:52:44 -04:00
FFZ . settings _info . mod _card _buttons = {
type : "button" ,
value : [ ] ,
category : "Chat Moderation" ,
no _bttv : true ,
name : "Moderation Card Additional Buttons" ,
help : "Add additional buttons to moderation cards for running chat commands on those users." ,
method : function ( ) {
2016-03-23 19:28:22 -04:00
var f = this ,
old _val = "" ;
2015-07-13 21:52:44 -04:00
for ( var i = 0 ; i < this . settings . mod _card _buttons . length ; i ++ ) {
var cmd = this . settings . mod _card _buttons [ i ] ;
if ( cmd . indexOf ( ' ' ) !== - 1 )
old _val += ' "' + cmd + '"' ;
else
old _val += ' ' + cmd ;
}
2015-08-04 01:43:08 -04:00
2016-03-23 19:28:22 -04:00
utils . prompt (
"Moderation Card Additional Buttons" ,
"Please enter a list of additional commands to display buttons for on moderation cards. Commands are separated by spaces. " +
"To include spaces in a command, surround the command with double quotes (\"). Use <code>{user}</code> to insert the " +
"user's name into the command, otherwise it will be appended to the end.</p><p><b>Example:</b> !permit \"!reg add {user}\"" ,
old _val . substr ( 1 ) ,
function ( new _val ) {
if ( new _val === null || new _val === undefined )
return ;
var vals = [ ] ;
new _val = new _val . trim ( ) ;
while ( new _val ) {
if ( new _val . charAt ( 0 ) === '"' ) {
var end = new _val . indexOf ( '"' , 1 ) ;
if ( end === - 1 )
end = new _val . length ;
var segment = new _val . substr ( 1 , end - 1 ) ;
if ( segment )
vals . push ( segment ) ;
new _val = new _val . substr ( end + 1 ) ;
} else {
var ind = new _val . indexOf ( ' ' ) ;
if ( ind === - 1 ) {
if ( new _val )
vals . push ( new _val ) ;
new _val = '' ;
} else {
var segment = new _val . substr ( 0 , ind ) ;
if ( segment )
vals . push ( segment ) ;
new _val = new _val . substr ( ind + 1 ) ;
}
}
}
f . settings . set ( "mod_card_buttons" , vals ) ;
} , 600 ) ;
2015-07-13 21:52:44 -04:00
}
} ;
2015-07-04 17:06:36 -04:00
FFZ . settings _info . mod _card _durations = {
type : "button" ,
value : [ 300 , 600 , 3600 , 43200 , 86400 , 604800 ] ,
category : "Chat Moderation" ,
no _bttv : true ,
name : "Moderation Card Timeout Buttons" ,
help : "Add additional timeout buttons to moderation cards with specific durations." ,
method : function ( ) {
2016-03-23 19:28:22 -04:00
var f = this ,
old _val = this . settings . mod _card _durations . join ( ", " ) ;
utils . prompt (
"Moderation Card Timeout Buttons" ,
"Please enter a comma-separated list of durations that you would like to have timeout buttons for. " +
"Durations must be expressed in seconds.</p><p><b>Default:</b> 300, 600, 3600, 43200, 86400, 604800" ,
old _val ,
function ( new _val ) {
if ( new _val === null || new _val === undefined )
return ;
if ( new _val === "reset" )
new _val = FFZ . settings _info . mod _card _durations . value . join ( ", " ) ;
// Split them up.
new _val = new _val . trim ( ) . split ( /[ ,]+/ ) ;
var vals = [ ] ;
for ( var i = 0 ; i < new _val . length ; i ++ ) {
var val = parseInt ( new _val [ i ] ) ;
if ( val === 0 )
val = 1 ;
if ( ! Number . isNaN ( val ) && val > 0 )
vals . push ( val ) ;
}
f . settings . set ( "mod_card_durations" , vals ) ;
} , 600 ) ;
2015-07-04 17:06:36 -04:00
}
2015-02-10 01:34:23 -05:00
} ;
// ----------------
// Initialization
// ----------------
FFZ . prototype . setup _mod _card = function ( ) {
2015-07-04 17:06:36 -04:00
this . log ( "Modifying Mousetrap stopCallback so we can catch ESC." ) ;
var orig _stop = Mousetrap . stopCallback ;
Mousetrap . stopCallback = function ( e , element , combo ) {
if ( element . classList . contains ( 'no-mousetrap' ) )
return true ;
return orig _stop ( e , element , combo ) ;
}
Mousetrap . bind ( "up up down down left right left right b a enter" , function ( ) {
var el = document . querySelector ( ".app-main" ) || document . querySelector ( ".ember-chat-container" ) ;
el && el . classList . toggle ( 'ffz-flip' ) ;
} ) ;
2015-02-10 01:34:23 -05:00
this . log ( "Hooking the Ember Moderation Card view." ) ;
2015-05-17 19:02:57 -04:00
var Card = App . _ _container _ _ . resolve ( 'component:moderation-card' ) ,
2015-02-10 01:34:23 -05:00
f = this ;
Card . reopen ( {
2015-07-04 17:06:36 -04:00
ffzForceRedraw : function ( ) {
this . rerender ( ) ;
2015-12-12 13:28:35 -05:00
if ( f . settings . mod _card _history )
this . ffzRenderHistory ( ) ;
} . observes ( "cardInfo.isModeratorOrHigher" , "cardInfo.user.id" ) ,
2015-07-04 17:06:36 -04:00
2015-07-13 21:52:44 -04:00
ffzRebuildInfo : function ( ) {
var el = this . get ( 'element' ) ,
info = el && el . querySelector ( '.info' ) ;
if ( ! info )
return ;
var out = '<span class="stat tooltip" title="Total Views">' + constants . EYE + ' ' + utils . number _commas ( this . get ( 'cardInfo.user.views' ) || 0 ) + '</span>' ,
since = utils . parse _date ( this . get ( 'cardInfo.user.created_at' ) || '' ) ,
followers = this . get ( 'cardInfo.user.ffz_followers' ) ;
if ( typeof followers === "number" ) {
out += '<span class="stat tooltip" title="Followers">' + constants . HEART + ' ' + utils . number _commas ( followers || 0 ) + '</span>' ;
2015-08-04 01:43:08 -04:00
2015-07-13 21:52:44 -04:00
} else if ( followers === undefined ) {
var t = this ;
this . set ( 'cardInfo.user.ffz_followers' , false ) ;
2016-03-23 19:28:22 -04:00
utils . api . get ( "channels/" + this . get ( 'cardInfo.user.id' ) + '/follows' , { limit : 1 } ) . done ( function ( data ) {
2015-07-13 21:52:44 -04:00
t . set ( 'cardInfo.user.ffz_followers' , data . _total ) ;
t . ffzRebuildInfo ( ) ;
} ) . fail ( function ( data ) {
t . set ( 'cardInfo.user.ffz_followers' , undefined ) ;
} ) ;
}
if ( since ) {
2015-11-19 02:45:56 -05:00
var now = Date . now ( ) - ( f . _ws _server _offset || 0 ) ,
age = Math . floor ( ( now - since . getTime ( ) ) / 1000 ) ;
2015-07-13 21:52:44 -04:00
if ( age > 0 ) {
out += '<span class="stat tooltip" title="Member Since: ' + ( age > 86400 ? since . toLocaleDateString ( ) : since . toLocaleString ( ) ) + '">' + constants . CLOCK + ' ' + utils . human _time ( age , 10 ) + '</span>' ;
}
}
info . innerHTML = out ;
} . observes ( "cardInfo.user.views" ) ,
2015-07-29 01:03:10 -04:00
userName : Ember . computed ( "cardInfo.user.id" , "cardInfo.user.display_name" , function ( ) {
var user _id = this . get ( "cardInfo.user.id" ) ,
alias = f . aliases [ user _id ] ;
2015-08-04 01:43:08 -04:00
2015-07-29 01:03:10 -04:00
return alias || this . get ( "cardInfo.user.display_name" ) || user _id . capitalize ( ) ;
} ) ,
2015-11-07 22:56:15 -05:00
willDestroy : function ( ) {
if ( f . _mod _card === this )
f . _mod _card = undefined ;
this . _super ( ) ;
} ,
2015-02-10 01:34:23 -05:00
didInsertElement : function ( ) {
this . _super ( ) ;
try {
2015-07-04 17:06:36 -04:00
if ( f . has _bttv )
2015-02-10 01:34:23 -05:00
return ;
2015-11-07 22:56:15 -05:00
f . _mod _card = this ;
2015-02-10 01:34:23 -05:00
var el = this . get ( 'element' ) ,
2015-07-13 21:52:44 -04:00
controller = this . get ( 'controller' ) ,
2015-11-19 02:45:56 -05:00
t = this ,
2015-07-29 01:03:10 -04:00
line ,
2015-08-04 01:43:08 -04:00
2015-10-17 18:05:44 -04:00
is _mod = controller . get ( 'cardInfo.isModeratorOrHigher' ) ,
2015-10-24 22:44:00 -04:00
chat = window . App && App . _ _container _ _ . lookup ( 'controller:chat' ) ,
user = f . get _user ( ) ,
2015-11-07 22:56:15 -05:00
room _id = chat && chat . get ( 'currentRoom.id' ) ,
is _broadcaster = user && room _id === user . login ,
2015-10-24 22:44:00 -04:00
2015-07-29 01:03:10 -04:00
user _id = controller . get ( 'cardInfo.user.id' ) ,
alias = f . aliases [ user _id ] ;
2015-11-07 22:56:15 -05:00
this . ffz _room _id = room _id ;
2015-07-29 01:03:10 -04:00
// Alias Display
if ( alias ) {
var name = el . querySelector ( 'h3.name' ) ,
link = name && name . querySelector ( 'a' ) ;
if ( link )
name = link ;
if ( name ) {
name . classList . add ( 'ffz-alias' ) ;
name . title = utils . sanitize ( controller . get ( 'cardInfo.user.display_name' ) || user _id . capitalize ( ) ) ;
2015-11-14 23:52:49 -05:00
jQuery ( name ) . tipsy ( { gravity : utils . tooltip _placement ( constants . TOOLTIP _DISTANCE , 'n' ) } ) ;
2015-07-29 01:03:10 -04:00
}
}
2015-02-10 01:34:23 -05:00
2015-02-10 02:42:11 -05:00
// Style it!
2015-07-13 21:52:44 -04:00
el . classList . add ( 'ffz-moderation-card' ) ;
// Info-tize it!
if ( f . settings . mod _card _info ) {
var info = document . createElement ( 'div' ) ,
after = el . querySelector ( 'h3.name' ) ;
if ( after ) {
el . classList . add ( 'ffz-has-info' ) ;
2015-08-04 01:43:08 -04:00
info . className = 'info channel-stats' ;
2015-07-13 21:52:44 -04:00
after . parentElement . insertBefore ( info , after . nextSibling ) ;
this . ffzRebuildInfo ( ) ;
}
}
// Additional Buttons
2015-10-17 18:05:44 -04:00
if ( is _mod && f . settings . mod _card _buttons && f . settings . mod _card _buttons . length ) {
2015-07-13 21:52:44 -04:00
line = document . createElement ( 'div' ) ;
line . className = 'extra-interface interface clearfix' ;
2015-08-04 01:43:08 -04:00
2015-07-13 21:52:44 -04:00
var cmds = { } ,
add _btn _click = function ( cmd ) {
var user _id = controller . get ( 'cardInfo.user.id' ) ,
cont = App . _ _container _ _ . lookup ( 'controller:chat' ) ,
room = cont && cont . get ( 'currentRoom' ) ;
2015-08-04 01:43:08 -04:00
2015-10-17 18:05:44 -04:00
room && room . send ( cmd . replace ( /{user}/g , user _id ) , true ) ;
2015-07-13 21:52:44 -04:00
} ,
2015-08-04 01:43:08 -04:00
2015-07-13 21:52:44 -04:00
add _btn _make = function ( cmd ) {
var btn = document . createElement ( 'button' ) ,
segment = cmd . split ( ' ' , 1 ) [ 0 ] ,
title = cmds [ segment ] > 1 ? cmd . split ( ' ' , cmds [ segment ] ) : [ segment ] ;
if ( /^[!~./]/ . test ( title [ 0 ] ) )
title [ 0 ] = title [ 0 ] . substr ( 1 ) ;
title = _ . map ( title , function ( s ) { return s . capitalize ( ) } ) . join ( ' ' ) ;
btn . className = 'button' ;
btn . innerHTML = utils . sanitize ( title ) ;
btn . title = utils . sanitize ( cmd . replace ( /{user}/g , controller . get ( 'cardInfo.user.id' ) || '{user}' ) ) ;
2015-08-04 01:43:08 -04:00
2015-11-14 23:52:49 -05:00
jQuery ( btn ) . tipsy ( { gravity : utils . tooltip _placement ( constants . TOOLTIP _DISTANCE , 'n' ) } ) ;
2015-07-13 21:52:44 -04:00
btn . addEventListener ( 'click' , add _btn _click . bind ( this , cmd ) ) ;
return btn ;
} ;
2015-08-04 01:43:08 -04:00
2015-07-13 21:52:44 -04:00
var cmds = { } ;
for ( var i = 0 ; i < f . settings . mod _card _buttons . length ; i ++ )
cmds [ f . settings . mod _card _buttons [ i ] . split ( ' ' , 1 ) [ 0 ] ] = ( cmds [ f . settings . mod _card _buttons [ i ] . split ( ' ' , 1 ) [ 0 ] ] || 0 ) + 1 ;
for ( var i = 0 ; i < f . settings . mod _card _buttons . length ; i ++ ) {
var cmd = f . settings . mod _card _buttons [ i ] ,
ind = cmd . indexOf ( '{user}' ) ;
if ( ind === - 1 )
cmd += ' {user}' ;
line . appendChild ( add _btn _make ( cmd ) )
}
2015-08-04 01:43:08 -04:00
2015-07-13 21:52:44 -04:00
el . appendChild ( line ) ;
}
// Key Handling
el . setAttribute ( 'tabindex' , 1 ) ;
if ( f . settings . mod _card _hotkeys ) {
el . classList . add ( 'no-mousetrap' ) ;
el . addEventListener ( 'keyup' , function ( e ) {
var key = e . keyCode || e . which ,
user _id = controller . get ( 'cardInfo.user.id' ) ,
is _mod = controller . get ( 'cardInfo.isModeratorOrHigher' ) ,
room = App . _ _container _ _ . lookup ( 'controller:chat' ) . get ( 'currentRoom' ) ;
if ( is _mod && key == keycodes . P )
2015-10-17 18:05:44 -04:00
room . send ( "/timeout " + user _id + " 1" , true ) ;
2015-07-13 21:52:44 -04:00
else if ( is _mod && key == keycodes . B )
2015-10-17 18:05:44 -04:00
room . send ( "/ban " + user _id , true ) ;
2015-07-13 21:52:44 -04:00
else if ( is _mod && key == keycodes . T )
2015-10-17 18:05:44 -04:00
room . send ( "/timeout " + user _id + " 600" , true ) ;
2015-07-13 21:52:44 -04:00
else if ( is _mod && key == keycodes . U )
2015-10-17 18:05:44 -04:00
room . send ( "/unban " + user _id , true ) ;
2015-07-13 21:52:44 -04:00
else if ( key != keycodes . ESC )
return ;
controller . send ( 'close' ) ;
} ) ;
}
2015-02-10 02:42:11 -05:00
2015-02-10 01:34:23 -05:00
// Only do the big stuff if we're mod.
2015-10-17 18:05:44 -04:00
if ( is _mod ) {
2015-02-10 02:42:11 -05:00
el . classList . add ( 'ffz-is-mod' ) ;
2015-08-04 01:43:08 -04:00
2015-02-10 01:34:23 -05:00
var btn _click = function ( timeout ) {
2015-07-04 17:06:36 -04:00
var user _id = controller . get ( 'cardInfo.user.id' ) ,
room = App . _ _container _ _ . lookup ( 'controller:chat' ) . get ( 'currentRoom' ) ;
2015-02-10 01:34:23 -05:00
2015-07-04 17:06:36 -04:00
if ( timeout === - 1 )
2015-10-17 18:05:44 -04:00
room . send ( "/unban " + user _id , true ) ;
2015-07-04 17:06:36 -04:00
else
2015-10-17 18:05:44 -04:00
room . send ( "/timeout " + user _id + " " + timeout , true ) ;
2015-07-04 17:06:36 -04:00
} ,
2015-02-10 01:34:23 -05:00
2015-07-04 17:06:36 -04:00
btn _make = function ( timeout ) {
var btn = document . createElement ( 'button' )
btn . className = 'button' ;
2015-10-17 18:05:44 -04:00
btn . innerHTML = utils . duration _string ( timeout ) ;
2015-07-04 17:06:36 -04:00
btn . title = "Timeout User for " + utils . number _commas ( timeout ) + " Second" + ( timeout != 1 ? "s" : "" ) ;
2015-02-10 01:34:23 -05:00
2015-07-04 17:06:36 -04:00
if ( f . settings . mod _card _hotkeys && timeout === 600 )
btn . title = "(T)" + btn . title . substr ( 1 ) ;
else if ( f . settings . mod _card _hotkeys && timeout === 1 )
btn . title = "(P)urge - " + btn . title ;
2015-02-10 01:34:23 -05:00
2015-11-14 23:52:49 -05:00
jQuery ( btn ) . tipsy ( { gravity : utils . tooltip _placement ( constants . TOOLTIP _DISTANCE , 'n' ) } ) ;
2015-02-10 01:34:23 -05:00
2015-07-04 17:06:36 -04:00
btn . addEventListener ( 'click' , btn _click . bind ( this , timeout ) ) ;
return btn ;
} ;
2015-02-10 01:34:23 -05:00
2015-07-04 17:06:36 -04:00
if ( f . settings . mod _card _durations && f . settings . mod _card _durations . length ) {
// Extra Moderation
2015-07-13 21:52:44 -04:00
line = document . createElement ( 'div' ) ;
line . className = 'extra-interface interface clearfix' ;
2015-02-10 01:34:23 -05:00
2015-07-04 17:06:36 -04:00
line . appendChild ( btn _make ( 1 ) ) ;
2015-02-10 01:34:23 -05:00
2015-07-04 17:06:36 -04:00
var s = document . createElement ( 'span' ) ;
s . className = 'right' ;
line . appendChild ( s ) ;
2015-02-10 01:34:23 -05:00
2015-07-04 17:06:36 -04:00
for ( var i = 0 ; i < f . settings . mod _card _durations . length ; i ++ )
s . appendChild ( btn _make ( f . settings . mod _card _durations [ i ] ) ) ;
2015-02-10 01:34:23 -05:00
2015-07-04 17:06:36 -04:00
el . appendChild ( line ) ;
2015-02-10 01:34:23 -05:00
2015-07-04 17:06:36 -04:00
// Fix Other Buttons
this . $ ( "button.timeout" ) . remove ( ) ;
}
var ban _btn = el . querySelector ( 'button.ban' ) ;
if ( f . settings . mod _card _hotkeys )
ban _btn . setAttribute ( 'title' , '(B)an User' ) ;
2015-02-10 01:34:23 -05:00
2015-07-04 17:06:36 -04:00
// Unban Button
2015-02-10 01:34:23 -05:00
var unban _btn = document . createElement ( 'button' ) ;
unban _btn . className = 'unban button glyph-only light' ;
2015-02-10 02:42:11 -05:00
unban _btn . innerHTML = CHECK ;
2015-07-04 17:06:36 -04:00
unban _btn . title = ( f . settings . mod _card _hotkeys ? "(U)" : "U" ) + "nban User" ;
2015-02-10 01:34:23 -05:00
2015-11-14 23:52:49 -05:00
jQuery ( unban _btn ) . tipsy ( { gravity : utils . tooltip _placement ( constants . TOOLTIP _DISTANCE , 'n' ) } ) ;
2015-02-10 01:34:23 -05:00
unban _btn . addEventListener ( "click" , btn _click . bind ( this , - 1 ) ) ;
jQuery ( ban _btn ) . after ( unban _btn ) ;
}
// More Fixing Other Buttons
var op _btn = el . querySelector ( 'button.mod' ) ;
if ( op _btn ) {
2015-10-24 22:44:00 -04:00
var can _op = is _broadcaster || ( user && user . is _admin ) || ( user && user . is _staff ) ;
2015-02-10 01:34:23 -05:00
if ( ! can _op )
op _btn . parentElement . removeChild ( op _btn ) ;
}
2015-07-13 21:52:44 -04:00
var msg _btn = el . querySelector ( ".interface > button.message-button" ) ;
if ( msg _btn ) {
msg _btn . innerHTML = 'W' ;
2015-02-10 01:34:23 -05:00
msg _btn . classList . add ( 'glyph-only' ) ;
msg _btn . classList . add ( 'message' ) ;
2015-07-04 17:06:36 -04:00
msg _btn . title = "Whisper User" ;
2015-11-14 23:52:49 -05:00
jQuery ( msg _btn ) . tipsy ( { gravity : utils . tooltip _placement ( constants . TOOLTIP _DISTANCE , 'n' ) } ) ;
2015-08-04 01:43:08 -04:00
2015-07-13 21:52:44 -04:00
var real _msg = document . createElement ( 'button' ) ;
2015-07-29 01:03:10 -04:00
real _msg . className = 'message-button button glyph-only message tooltip' ;
2015-07-13 21:52:44 -04:00
real _msg . innerHTML = MESSAGE ;
real _msg . title = "Message User" ;
2015-08-04 01:43:08 -04:00
2015-07-13 21:52:44 -04:00
real _msg . addEventListener ( 'click' , function ( ) {
2016-03-23 19:28:22 -04:00
window . open ( '//www.twitch.tv/message/compose?to=' + controller . get ( 'cardInfo.user.id' ) ) ;
2015-07-13 21:52:44 -04:00
} )
msg _btn . parentElement . insertBefore ( real _msg , msg _btn . nextSibling ) ;
2015-02-10 01:34:23 -05:00
}
2015-08-04 01:43:08 -04:00
2015-07-29 01:03:10 -04:00
// Alias Button
var alias _btn = document . createElement ( 'button' ) ;
alias _btn . className = 'alias button glyph-only tooltip' ;
alias _btn . innerHTML = constants . EDIT ;
alias _btn . title = "Set Alias" ;
2015-08-04 01:43:08 -04:00
2015-07-29 01:03:10 -04:00
alias _btn . addEventListener ( 'click' , function ( ) {
var user = controller . get ( 'cardInfo.user.id' ) ,
alias = f . aliases [ user ] ;
2015-08-04 01:43:08 -04:00
2016-03-23 19:28:22 -04:00
utils . prompt (
"Alias for <b>" + utils . sanitize ( controller . get ( 'cardInfo.user.display_name' ) || user ) + "</b>" ,
"Please enter an alias for the user. Leave it blank to remove the alias." ,
alias ,
function ( new _val ) {
if ( new _val === null || new _val === undefined )
return ;
new _val = new _val . trim ( ) ;
if ( ! new _val )
new _val = undefined ;
f . aliases [ user ] = new _val ;
f . save _aliases ( ) ;
// Update UI
f . _update _alias ( user ) ;
Ember . propertyDidChange ( controller , 'cardInfo.user.display_name' ) ;
var name = el . querySelector ( 'h3.name' ) ;
if ( name )
name . classList . toggle ( 'ffz-alias' , new _val ) ;
} ) ;
2015-07-29 01:03:10 -04:00
} ) ;
2015-08-04 01:43:08 -04:00
2015-07-29 01:03:10 -04:00
if ( msg _btn )
msg _btn . parentElement . insertBefore ( alias _btn , msg _btn ) ;
else {
var follow _btn = el . querySelector ( ".interface > .follow-button" ) ;
if ( follow _btn )
follow _btn . parentElement . insertBefore ( alias _btn , follow _btn . nextSibling ) ;
}
2015-02-10 01:34:23 -05:00
2015-07-04 17:06:36 -04:00
// Message History
2015-12-12 13:28:35 -05:00
if ( f . settings . mod _card _history )
this . ffzRenderHistory ( ) ;
2015-11-07 22:56:15 -05:00
2015-12-12 13:28:35 -05:00
// Reposition the menu if it's off-screen.
var el _bound = el . getBoundingClientRect ( ) ,
body _bound = document . body . getBoundingClientRect ( ) ,
2015-07-04 17:06:36 -04:00
2015-12-12 13:28:35 -05:00
renderBottom = this . get ( 'cardInfo.renderBottom' ) ,
renderRight = this . get ( 'cardInfo.renderRight' ) ;
2015-07-04 17:06:36 -04:00
2015-12-12 13:28:35 -05:00
if ( renderRight ) {
var offset = ( el _bound . left + el _bound . width ) - renderRight ;
el . style . left = ( el _bound . left - offset ) + "px" ;
2015-07-04 17:06:36 -04:00
}
2015-12-12 13:28:35 -05:00
if ( renderBottom ) {
var offset = el _bound . bottom - renderBottom ;
el . style . top = ( el _bound . top - offset ) + "px" ;
2015-07-06 00:09:21 -04:00
2015-12-12 13:28:35 -05:00
} else if ( el _bound . bottom > body _bound . bottom ) {
2015-07-06 00:09:21 -04:00
var offset = el _bound . bottom - body _bound . bottom ;
if ( el _bound . top - offset > body _bound . top )
el . style . top = ( el _bound . top - offset ) + "px" ;
}
2015-02-10 01:34:23 -05:00
// Focus the Element
this . $ ( ) . draggable ( {
start : function ( ) {
el . focus ( ) ;
} } ) ;
el . focus ( ) ;
} catch ( err ) {
try {
f . error ( "ModerationCardView didInsertElement: " + err ) ;
} catch ( err ) { }
}
2015-11-19 02:45:56 -05:00
} ,
2015-12-12 13:28:35 -05:00
ffzRenderHistory : function ( ) {
var t = this ,
Chat = App . _ _container _ _ . lookup ( 'controller:chat' ) ,
room = Chat && Chat . get ( 'currentRoom' ) ,
delete _links = room && room . get ( 'roomProperties.hide_chat_links' ) ,
tmiSession = room . tmiSession || ( window . TMI && TMI . _sessions && TMI . _sessions [ 0 ] ) ,
room _id = room . get ( 'id' ) ,
user _id = this . get ( 'cardInfo.user.id' ) ,
ffz _room = room && f . rooms && f . rooms [ room _id ] ,
user _history = ffz _room && ffz _room . user _history && ffz _room . user _history [ user _id ] || [ ] ,
el = this . get ( 'element' ) ,
history = el && el . querySelector ( '.chat-history' ) ;
if ( ! history ) {
history = document . createElement ( 'ul' ) ;
history . className = 'interface clearfix chat-history' ;
el . appendChild ( history ) ;
} else {
history . classList . remove ( 'loading' ) ;
history . innerHTML = '' ;
}
if ( user _history . length < 50 ) {
var before = ( user _history . length > 0 ? user _history [ 0 ] . date . getTime ( ) : Date . now ( ) ) - ( f . _ws _server _offset || 0 ) ;
f . ws _send ( "user_history" , [ room _id , user _id , 50 - user _history . length ] , function ( success , data ) {
if ( ! success )
return ;
f . parse _history ( data , null , room _id , delete _links , tmiSession ) ;
var i = data . length ,
was _at _top = history && history . scrollTop >= ( history . scrollHeight - history . clientHeight ) ,
first = true ;
while ( i -- ) {
var msg = data [ i ] ;
if ( ! msg )
continue ;
msg . from _server = true ;
if ( ! msg . date || msg . date . getTime ( ) >= before )
continue ;
if ( first ) {
first = false ;
history . insertBefore ( f . _build _mod _card _history ( {
date : msg . date ,
from : "jtv" ,
style : "admin" ,
cachedTokens : [ "(Server History Above)" ]
} ) , history . firstElementChild ) ;
}
history . insertBefore ( f . _build _mod _card _history ( msg , t ) , history . firstElementChild ) ;
}
if ( was _at _top )
setTimeout ( function ( ) { history . scrollTop = history . scrollHeight ; } ) ;
} ) ;
}
for ( var i = 0 ; i < user _history . length ; i ++ )
history . appendChild ( f . _build _mod _card _history ( user _history [ i ] , t ) ) ;
// Lazy scroll-to-bottom
history . scrollTop = history . scrollHeight ;
} ,
2015-11-19 02:45:56 -05:00
ffzAdjacentHistory : function ( line ) {
var Chat = App . _ _container _ _ . lookup ( 'controller:chat' ) ,
t = this ,
user _id = this . get ( 'cardInfo.user.id' ) ,
room = Chat && Chat . get ( 'currentRoom' ) ,
room _id = room . get ( 'id' ) ,
delete _links = room && room . get ( 'roomProperties.hide_chat_links' ) ,
tmiSession = room . tmiSession || ( window . TMI && TMI . _sessions && TMI . _sessions [ 0 ] ) ,
el = this . get ( 'element' ) ,
history = el && el . querySelector ( '.chat-history' ) ,
logs = el && el . querySelector ( '.chat-history.adjacent-history' ) ,
2015-12-12 13:28:35 -05:00
when = line . date . getTime ( ) ,
scroll _top = logs && logs . scrollTop || history && history . scrollTop || 0 ;
2015-11-19 02:45:56 -05:00
if ( ! history )
return ;
2015-12-12 13:28:35 -05:00
if ( logs ) {
2015-11-19 02:45:56 -05:00
logs . classList . add ( 'loading' ) ;
2015-12-12 13:28:35 -05:00
logs . scrollTop = 0 ;
} else {
2015-11-19 02:45:56 -05:00
history . classList . add ( 'loading' ) ;
2015-12-12 13:28:35 -05:00
history . scrollTop = 0 ;
}
2015-11-19 02:45:56 -05:00
if ( ! f . ws _send ( "adjacent_history" , [ room _id , when , 2 ] , function ( success , data ) {
2015-12-12 13:28:35 -05:00
var was _loading = history . classList . contains ( 'loading' ) ;
if ( logs ) {
2015-11-19 02:45:56 -05:00
logs . classList . remove ( 'loading' ) ;
2015-12-12 13:28:35 -05:00
logs . scrollTop = scroll _top ;
} else {
2015-11-19 02:45:56 -05:00
history . classList . remove ( 'loading' ) ;
2015-12-12 13:28:35 -05:00
history . scrollTop = scroll _top ;
}
2015-11-19 02:45:56 -05:00
2015-12-12 13:28:35 -05:00
if ( ! success || ! data || ! data . length || ! was _loading )
2015-11-19 02:45:56 -05:00
return ;
var had _logs = false ,
found _original = false ,
back ;
if ( logs ) {
had _logs = true ;
logs . innerHTML = '' ;
} else {
logs = document . createElement ( 'ul' ) ;
back = document . createElement ( 'button' ) ;
back . className = 'button back-button' ;
back . innerHTML = '« Back' ;
back . addEventListener ( 'click' , function ( ) {
logs . parentElement . removeChild ( logs ) ;
back . parentElement . removeChild ( back ) ;
history . classList . remove ( 'hidden' ) ;
} ) ;
logs . className = 'interface clearfix chat-history adjacent-history' ;
}
f . parse _history ( data , null , room _id , delete _links , tmiSession , function ( msg ) {
msg . from _server = true ;
var line _time = line . date . getTime ( ) - ( line . from _server ? 0 : ( f . _ws _server _offset || 0 ) ) ,
is _original = ! found _original && Math . abs ( line _time - msg . date . getTime ( ) ) < ( line . from _server ? 50 : 1000 ) && line . from === msg . from && line . message === msg . message ;
msg . original _sender = user _id === msg . from ;
msg . is _original = is _original ;
found _original = found _original || is _original ;
logs . insertBefore ( f . _build _mod _card _history ( msg , t , true ) , logs . firstElementChild ) ;
return true ;
} ) ;
if ( ! had _logs ) {
history . classList . add ( 'hidden' ) ;
history . parentElement . insertBefore ( logs , history ) ;
history . parentElement . insertBefore ( back , logs ) ;
}
if ( found _original )
setTimeout ( function ( ) {
el = logs . querySelector ( '.original-msg' ) ;
if ( el )
logs . scrollTop = ( el . offsetTop - logs . offsetTop ) - ( logs . clientHeight - el . clientHeight ) / 2 ;
} ) ;
} ) )
2015-12-12 13:28:35 -05:00
if ( logs ) {
2015-11-19 02:45:56 -05:00
logs . classList . remove ( 'loading' ) ;
2015-12-12 13:28:35 -05:00
logs . scrollTop = scroll _top ;
} else {
2015-11-19 02:45:56 -05:00
history . classList . remove ( 'loading' ) ;
2015-12-12 13:28:35 -05:00
history . scrollTop = scroll _top ;
}
2015-11-19 02:45:56 -05:00
}
} ) ;
2015-02-10 01:34:23 -05:00
}
2015-11-19 02:45:56 -05:00
FFZ . prototype . _build _mod _card _history = function ( msg , modcard , show _from ) {
2015-11-11 16:03:27 -05:00
var l _el = document . createElement ( 'li' ) ,
2015-11-19 02:45:56 -05:00
out = [ ] ,
2015-11-11 16:03:27 -05:00
f = this ;
2015-11-19 02:45:56 -05:00
style = '' , colored = '' ;
if ( helpers && helpers . getTime )
out . push ( '<span class="timestamp float-left">' + helpers . getTime ( msg . date ) + '</span>' ) ;
2015-12-12 13:28:35 -05:00
var alias = this . aliases [ msg . from ] ,
name = ( msg . tags && msg . tags [ 'display-name' ] ) || ( msg . from && msg . from . capitalize ( ) ) || "unknown user" ;
2015-11-19 02:45:56 -05:00
if ( show _from ) {
// Badges
out . push ( '<span class="badges float-left">' ) ;
out . push ( this . render _badges ( this . get _line _badges ( msg , false ) ) ) ;
out . push ( '</span>' ) ;
// Colors
var raw _color = msg . color ,
colors = raw _color && this . _handle _color ( raw _color ) ,
Layout = App . _ _container _ _ . lookup ( 'controller:layout' ) ,
Settings = App . _ _container _ _ . lookup ( 'controller:settings' ) ,
2015-12-12 13:28:35 -05:00
is _dark = ( Layout && Layout . get ( 'isTheatreMode' ) ) || ( Settings && Settings . get ( 'settings.darkMode' ) ) ;
2015-11-19 02:45:56 -05:00
// Aliases and Styling
2015-12-12 13:28:35 -05:00
var style = colors && 'color:' + ( is _dark ? colors [ 1 ] : colors [ 0 ] ) ,
2015-11-19 02:45:56 -05:00
colored = style ? ' has-color' : '' ;
if ( alias )
out . push ( '<span class="from ffz-alias tooltip' + colored + '" style="' + style + ( colors ? '" data-color="' + raw _color : '' ) + '" title="' + utils . sanitize ( name ) + '">' + utils . sanitize ( alias ) + '</span>' ) ;
else
out . push ( '<span class="from' + colored + '" style="' + style + ( colors ? '" data-color="' + raw _color : '' ) + '">' + utils . sanitize ( name ) + '</span>' ) ;
out . push ( '<span class="colon">:</span> ' ) ;
}
// The message itself.
if ( msg . style !== 'action' ) {
style = '' ;
colored = '' ;
}
var message = '<span class="message' + colored + '" style="' + style + ( colors ? '" data-color="' + raw _color : '' ) + '">' +
( msg . style === 'action' && ! show _from ? '*' + name + ' ' : '' ) + this . render _tokens ( msg . cachedTokens ) + '</span>' ;
if ( msg . deleted )
out . push ( '<span class="deleted"><a class="undelete" href="#" data-message="' + utils . quote _attr ( message ) + '"><message deleted></a></span>' ) ;
else
out . push ( message ) ;
// Line attributes and classes.
2015-11-11 16:03:27 -05:00
l _el . className = 'message-line chat-line clearfix' ;
2015-11-19 02:45:56 -05:00
if ( msg . style )
l _el . classList . add ( msg . style ) ;
if ( msg . original _sender )
l _el . classList . add ( 'original-sender' ) ;
if ( msg . is _original )
l _el . classList . add ( 'original-msg' ) ;
if ( msg . ffz _has _mention )
2015-11-11 16:03:27 -05:00
l _el . classList . add ( 'ffz-mentioned' ) ;
2015-11-19 02:45:56 -05:00
if ( this . settings . prevent _clear && msg . ffz _deleted )
l _el . classList . add ( 'ffz-deleted' ) ;
l _el . setAttribute ( 'data-room' , msg . room ) ;
l _el . setAttribute ( 'data-sender' , msg . from ) ;
l _el . setAttribute ( 'data-deleted' , msg . deleted || false ) ;
l _el . innerHTML = out . join ( "" ) ;
2015-11-11 16:03:27 -05:00
// Interactivity
2015-11-19 02:45:56 -05:00
jQuery ( 'a.undelete' , l _el ) . click ( function ( e ) { this . parentElement . outerHTML = this . getAttribute ( 'data-message' ) ; } ) ;
2016-03-23 19:28:22 -04:00
jQuery ( '.deleted-word' , l _el ) . click ( function ( e ) { jQuery ( this ) . trigger ( 'mouseout' ) ; this . outerHTML = this . getAttribute ( 'data-text' ) ; } ) ;
2015-11-11 16:03:27 -05:00
jQuery ( 'a.deleted-link' , l _el ) . click ( f . _deleted _link _click ) ;
jQuery ( 'img.emoticon' , l _el ) . click ( function ( e ) { f . _click _emote ( this , e ) } ) ;
2015-11-14 23:52:49 -05:00
jQuery ( '.html-tooltip' , l _el ) . tipsy ( { html : true , gravity : utils . tooltip _placement ( 2 * constants . TOOLTIP _DISTANCE , 's' ) } ) ;
2016-03-23 19:28:22 -04:00
jQuery ( '.ffz-tooltip' , l _el ) . tipsy ( { live : true , html : true , title : f . render _tooltip ( ) , gravity : utils . tooltip _placement ( 2 * constants . TOOLTIP _DISTANCE , 's' ) } ) ;
2015-11-11 16:03:27 -05:00
2015-11-19 02:45:56 -05:00
if ( modcard ) {
modcard . get ( 'cardInfo.user.id' ) !== msg . from && jQuery ( 'span.from' , l _el ) . click ( function ( e ) {
var el = modcard . get ( 'element' ) ;
el && f . _roomv && f . _roomv . get ( 'context.model.id' ) === msg . room && f . _roomv . get ( 'controller' ) . send ( 'showModOverlay' , {
sender : msg . from ,
top : parseInt ( el . style . top ) ,
left : parseInt ( el . style . left )
} ) ;
} ) ;
l _el . querySelector ( '.timestamp' ) . addEventListener ( 'click' , function ( e ) {
if ( e . button === 0 )
modcard . ffzAdjacentHistory ( msg ) ;
} ) ;
}
2015-11-11 16:03:27 -05:00
return l _el ;
}
2015-07-31 17:44:20 -04:00
// ----------------
// Aliases
// ----------------
FFZ . prototype . _update _alias = function ( user ) {
var alias = this . aliases && this . aliases [ user ] ,
2015-08-04 01:43:08 -04:00
cap _name = FFZ . get _capitalization ( user ) ,
display _name = alias || cap _name ,
2015-07-31 17:44:20 -04:00
el = this . _roomv && this . _roomv . get ( 'element' ) ,
lines = el && el . querySelectorAll ( '.chat-line[data-sender="' + user + '"]' ) ;
2015-08-04 01:43:08 -04:00
2015-07-31 17:44:20 -04:00
if ( ! lines )
return ;
for ( var i = 0 , l = lines . length ; i < l ; i ++ ) {
var line = lines [ i ] ,
el _from = line . querySelector ( '.from' ) ;
2015-08-04 01:43:08 -04:00
2016-03-23 19:28:22 -04:00
if ( ! el _from )
continue ;
2015-07-31 17:44:20 -04:00
el _from . classList . toggle ( 'ffz-alias' , alias ) ;
el _from . textContent = display _name ;
2015-08-04 01:43:08 -04:00
el _from . title = alias ? cap _name : '' ;
2015-07-31 17:44:20 -04:00
}
2015-11-19 02:45:56 -05:00
// TODO: Update conversations~
2015-07-31 17:44:20 -04:00
}
2015-02-10 01:34:23 -05:00
// ----------------
// Chat Commands
// ----------------
2015-07-04 17:06:36 -04:00
FFZ . chat _commands . purge = function ( room , args ) {
2015-02-10 01:34:23 -05:00
if ( ! args || ! args . length )
return "Purge Usage: /p username [more usernames separated by spaces]" ;
if ( args . length > 10 )
return "Please only purge up to 10 users at once." ;
for ( var i = 0 ; i < args . length ; i ++ ) {
var name = args [ i ] ;
if ( name )
2015-10-17 18:05:44 -04:00
room . room . send ( "/timeout " + name + " 1" , true ) ;
2015-02-10 01:34:23 -05:00
}
}
2015-07-04 17:06:36 -04:00
FFZ . chat _commands . p = function ( room , args ) {
2016-03-23 19:28:22 -04:00
return FFZ . chat _commands . purge . call ( this , room , args ) ;
2015-07-04 17:06:36 -04:00
}
FFZ . chat _commands . p . enabled = function ( ) { return this . settings . short _commands ; }
2015-02-10 01:34:23 -05:00
FFZ . chat _commands . t = function ( room , args ) {
if ( ! args || ! args . length )
return "Timeout Usage: /t username [duration]" ;
2015-10-17 18:05:44 -04:00
room . room . send ( "/timeout " + args . join ( " " ) , true ) ;
2015-02-10 01:34:23 -05:00
}
2015-07-04 17:06:36 -04:00
FFZ . chat _commands . t . enabled = function ( ) { return this . settings . short _commands ; }
2015-02-10 01:34:23 -05:00
FFZ . chat _commands . b = function ( room , args ) {
if ( ! args || ! args . length )
return "Ban Usage: /b username [more usernames separated by spaces]" ;
if ( args . length > 10 )
return "Please only ban up to 10 users at once." ;
for ( var i = 0 ; i < args . length ; i ++ ) {
var name = args [ i ] ;
if ( name )
2015-10-17 18:05:44 -04:00
room . room . send ( "/ban " + name , true ) ;
2015-02-10 01:34:23 -05:00
}
}
2015-07-04 17:06:36 -04:00
FFZ . chat _commands . b . enabled = function ( ) { return this . settings . short _commands ; }
2015-02-10 01:34:23 -05:00
FFZ . chat _commands . u = function ( room , args ) {
if ( ! args || ! args . length )
2015-02-24 00:33:29 -05:00
return "Unban Usage: /u username [more usernames separated by spaces]" ;
2015-02-10 01:34:23 -05:00
if ( args . length > 10 )
return "Please only unban up to 10 users at once." ;
for ( var i = 0 ; i < args . length ; i ++ ) {
var name = args [ i ] ;
if ( name )
2015-10-17 18:05:44 -04:00
room . room . send ( "/unban " + name , true ) ;
2015-02-10 01:34:23 -05:00
}
}
2015-07-04 17:06:36 -04:00
FFZ . chat _commands . u . enabled = function ( ) { return this . settings . short _commands ; }