2015-01-15 13:58:42 -05:00
|
|
|
var FFZ = window.FrankerFaceZ,
|
|
|
|
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-03-30 00:52:18 -04:00
|
|
|
this.log("WOO");
|
|
|
|
|
2015-02-10 01:34:23 -05:00
|
|
|
// this.track('setCustomVariable', '3', 'BetterTTV', BetterTTV.info.versionString());
|
2015-01-15 13:58:42 -05:00
|
|
|
|
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);
|
|
|
|
delete this._dark_style;
|
|
|
|
}
|
|
|
|
|
2015-02-10 01:34:23 -05:00
|
|
|
// Disable other features too.
|
|
|
|
document.body.classList.remove("ffz-chat-colors");
|
|
|
|
document.body.classList.remove("ffz-chat-background");
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
return '<div class="chat-line'+(highlight?' highlight':'')+(action?' action':'')+(server?' admin':'')+'" data-sender="'+data.sender+'" data-room="'+received_room+'">'+
|
|
|
|
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-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') {
|
|
|
|
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(' ');
|
|
|
|
}
|
|
|
|
|
|
|
|
return '<span class="message" '+(colored?'style="color: '+colored+'" ':'')+'data-raw="'+rawMessage+'">'+message+'</span>';
|
|
|
|
} catch(err) {
|
|
|
|
f.log("Error: ", err);
|
|
|
|
return original_message(sender, message, emotes, colored);
|
|
|
|
}
|
|
|
|
};
|
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-01-16 17:45:37 -05:00
|
|
|
sets = f.getEmotes(received_sender, received_room),
|
2015-01-15 13:58:42 -05:00
|
|
|
emotes = [];
|
|
|
|
|
|
|
|
// Build a list of emotes that match.
|
|
|
|
_.each(sets, function(set_id) {
|
|
|
|
var set = f.emote_sets[set_id];
|
|
|
|
if ( ! set )
|
|
|
|
return;
|
|
|
|
|
|
|
|
_.each(set.emotes, function(emote) {
|
|
|
|
_.any(tokens, function(token) {
|
|
|
|
return _.isString(token) && token.match(emote.regex);
|
|
|
|
}) && emotes.push(emote);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Don't bother proceeding if we have no emotes.
|
|
|
|
if ( ! emotes.length )
|
|
|
|
return tokens;
|
|
|
|
|
|
|
|
// Why is emote parsing so bad? ;_;
|
|
|
|
_.each(emotes, function(emote) {
|
2015-01-15 22:19:05 -05:00
|
|
|
var eo = ['<img class="emoticon" src="' + emote.url + (emote.hidden ? "" : '" alt="' + emote.name + '" title="' + emote.name) + '" />'],
|
2015-01-15 13:58:42 -05:00
|
|
|
old_tokens = tokens;
|
|
|
|
|
|
|
|
tokens = [];
|
|
|
|
|
|
|
|
if ( ! old_tokens || ! old_tokens.length )
|
|
|
|
return tokens;
|
|
|
|
|
|
|
|
for(var i=0; i < old_tokens.length; i++) {
|
|
|
|
var token = old_tokens[i];
|
|
|
|
if ( typeof token != "string" ) {
|
|
|
|
tokens.push(token);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
var tbits = token.split(emote.regex);
|
|
|
|
tbits.forEach(function(val, ind) {
|
|
|
|
if ( val && val.length )
|
|
|
|
tokens.push(val);
|
|
|
|
|
|
|
|
if ( ind !== tbits.length - 1 )
|
|
|
|
tokens.push(eo);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return tokens;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.update_ui_link();
|
|
|
|
}
|