2015-01-15 13:58:42 -05:00
|
|
|
var FFZ = window.FrankerFaceZ,
|
2015-07-04 17:06:36 -04:00
|
|
|
constants = require('../constants'),
|
|
|
|
utils = require('../utils'),
|
2015-01-15 13:58:42 -05:00
|
|
|
SENDER_REGEX = /(\sdata-sender="[^"]*"(?=>))/;
|
|
|
|
|
|
|
|
|
|
|
|
// --------------------
|
|
|
|
// Initialization
|
|
|
|
// --------------------
|
|
|
|
|
|
|
|
FFZ.prototype.find_bttv = function(increment, delay) {
|
|
|
|
this.has_bttv = false;
|
|
|
|
if ( window.BTTVLOADED )
|
2015-01-19 15:27:10 -05:00
|
|
|
return this.setup_bttv(delay||0);
|
2015-01-15 13:58:42 -05:00
|
|
|
|
|
|
|
if ( delay >= 60000 )
|
|
|
|
this.log("BetterTTV was not detected after 60 seconds.");
|
|
|
|
else
|
|
|
|
setTimeout(this.find_bttv.bind(this, increment, (delay||0) + increment),
|
|
|
|
increment);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-19 15:27:10 -05:00
|
|
|
FFZ.prototype.setup_bttv = function(delay) {
|
|
|
|
this.log("BetterTTV was detected after " + delay + "ms. Hooking.");
|
2015-01-15 13:58:42 -05:00
|
|
|
this.has_bttv = true;
|
|
|
|
|
2015-02-08 02:14:52 -05:00
|
|
|
// Disable Dark if it's enabled.
|
2015-02-10 01:34:23 -05:00
|
|
|
document.body.classList.remove("ffz-dark");
|
2015-02-08 02:14:52 -05:00
|
|
|
if ( this._dark_style ) {
|
|
|
|
this._dark_style.parentElement.removeChild(this._dark_style);
|
2015-07-13 21:52:44 -04:00
|
|
|
this._dark_style = undefined;
|
|
|
|
}
|
2015-08-04 01:43:08 -04:00
|
|
|
|
2015-07-31 17:44:20 -04:00
|
|
|
if ( this._layout_style ) {
|
|
|
|
this._layout_style.parentElement.removeChild(this._layout_style);
|
|
|
|
this._layout_style = undefined;
|
|
|
|
}
|
2015-08-04 01:43:08 -04:00
|
|
|
|
2015-07-13 21:52:44 -04:00
|
|
|
if ( this._chat_style ) {
|
2015-07-29 01:03:10 -04:00
|
|
|
utils.update_css(this._chat_style, 'chat_font_size', '');
|
|
|
|
utils.update_css(this._chat_style, 'chat_ts_font_size', '');
|
2015-02-08 02:14:52 -05:00
|
|
|
}
|
|
|
|
|
2016-03-23 19:28:22 -04:00
|
|
|
// Remove Sub Count and the Chart
|
|
|
|
if ( this.is_dashboard ) {
|
|
|
|
this._update_subscribers();
|
|
|
|
this._remove_dash_chart();
|
|
|
|
}
|
|
|
|
|
|
|
|
document.body.classList.add('ffz-bttv');
|
|
|
|
|
2015-06-05 03:59:28 -04:00
|
|
|
// Disable Chat Tabs
|
2015-12-12 13:28:35 -05:00
|
|
|
if ( this._chatv ) {
|
|
|
|
if ( this.settings.group_tabs )
|
|
|
|
this._chatv.ffzDisableTabs();
|
|
|
|
|
|
|
|
this._chatv.ffzTeardownMenu();
|
|
|
|
this._chatv.ffzUnloadHost();
|
2015-06-05 03:59:28 -04:00
|
|
|
}
|
|
|
|
|
2015-12-12 13:28:35 -05:00
|
|
|
this.disconnect_extra_chat();
|
|
|
|
|
2015-07-04 17:06:36 -04:00
|
|
|
if ( this._roomv ) {
|
|
|
|
// Disable Chat Pause
|
|
|
|
if ( this.settings.chat_hover_pause )
|
|
|
|
this._roomv.ffzDisableFreeze();
|
|
|
|
|
|
|
|
// And hide the status
|
|
|
|
if ( this.settings.room_status )
|
|
|
|
this._roomv.ffzUpdateStatus();
|
|
|
|
}
|
|
|
|
|
2015-11-11 02:06:02 -05:00
|
|
|
// Disable style blocks.
|
|
|
|
this.toggle_style('chat-setup');
|
|
|
|
this.toggle_style('chat-padding');
|
|
|
|
this.toggle_style('chat-background');
|
|
|
|
|
|
|
|
this.toggle_style('chat-separator');
|
|
|
|
this.toggle_style('chat-separator-3d');
|
|
|
|
this.toggle_style('chat-separator-3d-inset');
|
|
|
|
this.toggle_style('chat-separator-wide');
|
|
|
|
|
|
|
|
this.toggle_style('chat-hc-text');
|
|
|
|
this.toggle_style('chat-hc-bold');
|
|
|
|
this.toggle_style('chat-hc-background');
|
|
|
|
|
|
|
|
this.toggle_style('chat-colors-gray');
|
|
|
|
this.toggle_style('badges-transparent');
|
2016-03-23 19:28:22 -04:00
|
|
|
this.toggle_style('badges-sub-notice');
|
|
|
|
this.toggle_style('badges-sub-notice-on');
|
2015-11-11 02:06:02 -05:00
|
|
|
|
2015-02-10 01:34:23 -05:00
|
|
|
// Disable other features too.
|
2015-11-11 16:03:27 -05:00
|
|
|
document.body.classList.remove('ffz-transparent-badges');
|
2015-07-06 00:09:21 -04:00
|
|
|
document.body.classList.remove("ffz-sidebar-swap");
|
2015-10-24 22:44:00 -04:00
|
|
|
document.body.classList.remove("ffz-portrait");
|
2015-10-17 18:05:44 -04:00
|
|
|
document.body.classList.remove("ffz-flip-dashboard");
|
2015-07-13 21:52:44 -04:00
|
|
|
|
|
|
|
// Remove Following Count
|
|
|
|
if ( this.settings.following_count ) {
|
|
|
|
this._schedule_following_count();
|
|
|
|
this._draw_following_count();
|
2015-08-04 01:43:08 -04:00
|
|
|
this._draw_following_channels();
|
2015-07-13 21:52:44 -04:00
|
|
|
}
|
2015-02-10 01:34:23 -05:00
|
|
|
|
2015-01-15 13:58:42 -05:00
|
|
|
// Send Message Behavior
|
|
|
|
var original_send = BetterTTV.chat.helpers.sendMessage, f = this;
|
|
|
|
BetterTTV.chat.helpers.sendMessage = function(message) {
|
|
|
|
var cmd = message.split(' ', 1)[0].toLowerCase();
|
|
|
|
|
|
|
|
if ( cmd === "/ffz" )
|
2015-02-10 01:34:23 -05:00
|
|
|
f.run_ffz_command(message.substr(5), BetterTTV.chat.store.currentRoom);
|
2015-01-15 13:58:42 -05:00
|
|
|
else
|
|
|
|
return original_send(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-30 00:52:18 -04:00
|
|
|
// Ugly Hack for Current Room, as this is stripped out before we get to
|
|
|
|
// the actual privmsg renderer.
|
|
|
|
var original_handler = BetterTTV.chat.handlers.onPrivmsg,
|
2015-01-15 13:58:42 -05:00
|
|
|
received_room;
|
2015-03-30 00:52:18 -04:00
|
|
|
BetterTTV.chat.handlers.onPrivmsg = function(room, data) {
|
2015-01-15 13:58:42 -05:00
|
|
|
received_room = room;
|
|
|
|
var output = original_handler(room, data);
|
|
|
|
received_room = null;
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Message Display Behavior
|
|
|
|
var original_privmsg = BetterTTV.chat.templates.privmsg;
|
|
|
|
BetterTTV.chat.templates.privmsg = function(highlight, action, server, isMod, data) {
|
2015-03-30 00:52:18 -04:00
|
|
|
try {
|
|
|
|
// Handle badges.
|
|
|
|
f.bttv_badges(data);
|
|
|
|
|
|
|
|
// Now, do everything else manually because things are hard-coded.
|
2015-06-05 03:59:28 -04:00
|
|
|
return '<div class="chat-line'+(highlight?' highlight':'')+(action?' action':'')+(server?' admin':'')+'" data-sender="'+(data.sender||"").toLowerCase()+'" data-room="'+received_room+'">'+
|
2015-03-30 00:52:18 -04:00
|
|
|
BetterTTV.chat.templates.timestamp(data.time)+' '+
|
|
|
|
(isMod?BetterTTV.chat.templates.modicons():'')+' '+
|
|
|
|
BetterTTV.chat.templates.badges(data.badges)+
|
|
|
|
BetterTTV.chat.templates.from(data.nickname, data.color)+
|
|
|
|
BetterTTV.chat.templates.message(data.sender, data.message, data.emotes, action?data.color:false)+
|
|
|
|
'</div>';
|
|
|
|
} catch(err) {
|
|
|
|
f.log("Error: ", err);
|
|
|
|
return original_privmsg(highlight, action, server, isMod, data);
|
|
|
|
}
|
2015-01-15 13:58:42 -05:00
|
|
|
}
|
|
|
|
|
2015-07-04 17:06:36 -04:00
|
|
|
// Whispers too!
|
|
|
|
var original_whisper = BetterTTV.chat.templates.whisper;
|
|
|
|
BetterTTV.chat.templates.whisper = function(data) {
|
|
|
|
try {
|
|
|
|
// Handle badges.
|
|
|
|
f.bttv_badges(data);
|
|
|
|
|
|
|
|
// Now, do everything else manually because things are hard-coded.
|
|
|
|
return '<div class="chat-line whisper" data-sender="' + data.sender + '">' +
|
|
|
|
BetterTTV.chat.templates.timestamp(data.time) + ' ' +
|
|
|
|
(data.badges && data.badges.length ? BetterTTV.chat.templates.badges(data.badges) : '') +
|
|
|
|
BetterTTV.chat.templates.whisperName(data.sender, data.receiver, data.from, data.to, data.fromColor, data.toColor) +
|
|
|
|
BetterTTV.chat.templates.message(data.sender, data.message, data.emotes, false) +
|
|
|
|
'</div>';
|
|
|
|
} catch(err) {
|
|
|
|
f.log("Error: ", err);
|
|
|
|
return original_whisper(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-30 00:52:18 -04:00
|
|
|
// Message Renderer. I had to completely rewrite this method to get it to
|
|
|
|
// use my replacement emoticonizer.
|
|
|
|
var original_message = BetterTTV.chat.templates.message,
|
2015-01-15 13:58:42 -05:00
|
|
|
received_sender;
|
|
|
|
BetterTTV.chat.templates.message = function(sender, message, emotes, colored) {
|
2015-03-30 00:52:18 -04:00
|
|
|
try {
|
|
|
|
colored = colored || false;
|
|
|
|
var rawMessage = encodeURIComponent(message);
|
|
|
|
|
|
|
|
if(sender !== 'jtv') {
|
2015-06-05 03:59:28 -04:00
|
|
|
// Hackilly send our state across.
|
2015-03-30 00:52:18 -04:00
|
|
|
received_sender = sender;
|
|
|
|
var tokenizedMessage = BetterTTV.chat.templates.emoticonize(message, emotes);
|
|
|
|
received_sender = null;
|
|
|
|
|
|
|
|
for(var i=0; i<tokenizedMessage.length; i++) {
|
|
|
|
if(typeof tokenizedMessage[i] === 'string') {
|
|
|
|
tokenizedMessage[i] = BetterTTV.chat.templates.bttvMessageTokenize(sender, tokenizedMessage[i]);
|
|
|
|
} else {
|
|
|
|
tokenizedMessage[i] = tokenizedMessage[i][0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
message = tokenizedMessage.join(' ');
|
|
|
|
}
|
|
|
|
|
2015-06-05 03:59:28 -04:00
|
|
|
return '<span class="message" '+(colored?'style="color: '+colored+'" ':'')+'data-raw="'+rawMessage+'" data-emotes="'+(emotes ? encodeURIComponent(JSON.stringify(emotes)) : 'false')+'">'+message+'</span>';
|
2015-03-30 00:52:18 -04:00
|
|
|
} catch(err) {
|
|
|
|
f.log("Error: ", err);
|
|
|
|
return original_message(sender, message, emotes, colored);
|
|
|
|
}
|
|
|
|
};
|
2015-01-15 13:58:42 -05:00
|
|
|
|
2016-03-23 19:28:22 -04:00
|
|
|
// Emoji!
|
|
|
|
var parse_emoji = function(token) {
|
|
|
|
var setting = f.settings.parse_emoji,
|
|
|
|
output = [],
|
|
|
|
segments = token.split(constants.EMOJI_REGEX),
|
|
|
|
text = null;
|
|
|
|
|
|
|
|
if ( setting === 0 )
|
|
|
|
return [token];
|
|
|
|
|
|
|
|
while(segments.length) {
|
|
|
|
text = (text || '') + segments.shift();
|
|
|
|
if ( segments.length ) {
|
|
|
|
var match = segments.shift(),
|
|
|
|
eid = utils.emoji_to_codepoint(match),
|
|
|
|
data = f.emoji_data[eid],
|
|
|
|
src = data && (setting === 3 ? data.one_src : (setting === 2 ? data.noto_src : data.tw_src));
|
|
|
|
|
|
|
|
if ( src ) {
|
|
|
|
if ( text && text.length )
|
|
|
|
output.push(text);
|
|
|
|
var code = utils.quote_attr(data.raw);
|
|
|
|
output.push(['<img class="emoticon emoji ffz-tooltip" height="18px" data-ffz-emoji="' + eid + '" src="' + utils.quote_attr(src) + '" data-regex="' + code + '" alt="' + code + '">']);
|
|
|
|
text = null;
|
|
|
|
} else
|
|
|
|
text = (text || '') + match;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( text && text.length )
|
|
|
|
output.push(text);
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2015-01-15 13:58:42 -05:00
|
|
|
// Emoticonize
|
|
|
|
var original_emoticonize = BetterTTV.chat.templates.emoticonize;
|
|
|
|
BetterTTV.chat.templates.emoticonize = function(message, emotes) {
|
|
|
|
var tokens = original_emoticonize(message, emotes),
|
2015-08-04 01:43:08 -04:00
|
|
|
|
2015-06-05 03:59:28 -04:00
|
|
|
room = (received_room || BetterTTV.getChannel()),
|
|
|
|
l_room = room && room.toLowerCase(),
|
|
|
|
l_sender = received_sender && received_sender.toLowerCase(),
|
|
|
|
sets = f.getEmotes(l_sender, l_room),
|
2016-03-23 19:28:22 -04:00
|
|
|
emotes = {}, emote,
|
2015-06-05 03:59:28 -04:00
|
|
|
user = f.get_user(),
|
2016-03-23 19:28:22 -04:00
|
|
|
new_tokens = [],
|
2015-06-05 03:59:28 -04:00
|
|
|
mine = user && user.login === l_sender;
|
2015-01-15 13:58:42 -05:00
|
|
|
|
2016-03-23 19:28:22 -04:00
|
|
|
// Build an object with all of our emotes.
|
|
|
|
for(var i=0; i < sets.length; i++) {
|
|
|
|
var emote_set = f.emote_sets[sets[i]];
|
|
|
|
if ( emote_set && emote_set.emoticons )
|
|
|
|
for(var emote_id in emote_set.emoticons) {
|
|
|
|
emote = emote_set.emoticons[emote_id];
|
2016-03-27 02:15:32 -04:00
|
|
|
if ( ! emotes.hasOwnProperty(emote.name) )
|
2016-03-23 19:28:22 -04:00
|
|
|
emotes[emote.name] = emote;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(var i=0, l=tokens.length; i < l; i++) {
|
|
|
|
var token = tokens[i];
|
|
|
|
if ( typeof token !== "string" ) {
|
|
|
|
new_tokens.push(token);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Split the token!
|
|
|
|
var segments = token.split(' '),
|
|
|
|
text = [], segment;
|
|
|
|
|
|
|
|
for(var x=0,y=segments.length; x < y; x++) {
|
|
|
|
segment = segments[x];
|
2016-03-27 02:15:32 -04:00
|
|
|
if ( emotes.hasOwnProperty(segment) ) {
|
|
|
|
emote = emotes[segment];
|
2016-03-23 19:28:22 -04:00
|
|
|
if ( text.length ) {
|
|
|
|
var toks = parse_emoji(text.join(' ') + ' ');
|
|
|
|
for(var q=0; q < toks.length; q++)
|
|
|
|
new_tokens.push(toks[q]);
|
|
|
|
|
|
|
|
text = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
new_tokens.push(['<img class="emoticon ffz-tooltip" data-ffz-set="' + emote.set_id + '" data-ffz-emote="' + emote.id + '" srcset="' + utils.quote_attr(emote.srcSet || "") + '" src="' + utils.quote_attr(emote.urls[1]) + '" data-regex="' + utils.quote_attr(emote.name) + '">']);
|
|
|
|
|
|
|
|
if ( mine && l_room )
|
|
|
|
f.add_usage(l_room, emote);
|
|
|
|
|
|
|
|
text.push('');
|
|
|
|
} else
|
|
|
|
text.push(segment);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( text.length > 1 || (text.length === 1 && text[0] !== '') ) {
|
|
|
|
var toks = parse_emoji(text.join(' ') + ' ');
|
|
|
|
for(var q=0; q < toks.length; q++)
|
|
|
|
new_tokens.push(toks[q]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return new_tokens;
|
|
|
|
}
|
2015-01-15 13:58:42 -05:00
|
|
|
|
|
|
|
this.update_ui_link();
|
|
|
|
}
|