mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-07-27 13:08:30 +00:00
Add settings support. Make FFZ menu modular. Add support for chat row styles. Add support for dark twitch (disabled). Add support for SRL races. Update SRL race dialog. Everything.
This commit is contained in:
parent
c9bd39de8a
commit
b284bd0f8d
15 changed files with 2313 additions and 190 deletions
|
@ -5,11 +5,72 @@ var FFZ = window.FrankerFaceZ,
|
|||
};
|
||||
|
||||
|
||||
// ---------------------
|
||||
// Settings
|
||||
// ---------------------
|
||||
|
||||
FFZ.settings_info.capitalize = {
|
||||
type: "boolean",
|
||||
value: true,
|
||||
|
||||
visible: function() { return ! this.has_bttv },
|
||||
|
||||
name: "Username Capitalization",
|
||||
help: "Display names in chat with proper capitalization."
|
||||
};
|
||||
|
||||
|
||||
FFZ.settings_info.keywords = {
|
||||
type: "button",
|
||||
value: [],
|
||||
|
||||
visible: function() { return ! this.has_bttv },
|
||||
|
||||
name: "Highlight Keywords",
|
||||
help: "Set additional keywords that will be highlighted in chat.",
|
||||
|
||||
method: function() {
|
||||
var old_val = this.settings.keywords.join(", "),
|
||||
new_val = prompt("Highlight Keywords\n\nPlease enter a comma-separated list of words that you would like to be highlighted in chat.", old_val);
|
||||
|
||||
if ( ! new_val )
|
||||
return;
|
||||
|
||||
// Split them up.
|
||||
new_val = new_val.trim().split(/\W*,\W*/);
|
||||
|
||||
if ( new_val.length == 1 && (new_val[0] == "" || new_val[0] == "disable") )
|
||||
new_val = [];
|
||||
|
||||
this.settings.set("keywords", new_val);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
FFZ.settings_info.chat_rows = {
|
||||
type: "boolean",
|
||||
value: false,
|
||||
|
||||
visible: function() { return ! this.has_bttv },
|
||||
|
||||
name: "Chat Line Backgrounds",
|
||||
help: "Display alternating background colors for lines in chat.",
|
||||
|
||||
on_update: function(val) {
|
||||
document.querySelector(".app-main").classList.toggle("ffz-chat-background", val);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// ---------------------
|
||||
// Initialization
|
||||
// ---------------------
|
||||
|
||||
FFZ.prototype.setup_line = function() {
|
||||
// Alternating Background
|
||||
document.querySelector('.app-main').classList.toggle('ffz-chat-background', this.settings.chat_rows);
|
||||
this._last_row = {};
|
||||
|
||||
this.log("Hooking the Ember Line controller.");
|
||||
|
||||
var Line = App.__container__.resolve('controller:line'),
|
||||
|
@ -26,8 +87,7 @@ FFZ.prototype.setup_line = function() {
|
|||
|
||||
return tokens;
|
||||
|
||||
}.property("model.message", "isModeratorOrHigher", "controllers.emoticons.emoticons.[]")
|
||||
// TODO: Copy the new properties from the new Twitch!
|
||||
}.property("model.message", "isModeratorOrHigher")
|
||||
});
|
||||
|
||||
|
||||
|
@ -39,16 +99,55 @@ FFZ.prototype.setup_line = function() {
|
|||
this._super();
|
||||
|
||||
var el = this.get('element'),
|
||||
user = this.get('context.model.from');
|
||||
user = this.get('context.model.from'),
|
||||
room = this.get('context.parentController.content.id'),
|
||||
row_type = this.get('context.model.ffzAlternate');
|
||||
|
||||
el.setAttribute('data-room', this.get('context.parentController.content.id'));
|
||||
if ( row_type === undefined ) {
|
||||
row_type = f._last_row[room] = f._last_row.hasOwnProperty(room) ? !f._last_row[room] : false;
|
||||
this.set("context.model.ffzAlternate", row_type);
|
||||
}
|
||||
|
||||
el.classList.toggle('ffz-alternate', row_type);
|
||||
el.setAttribute('data-room', room);
|
||||
el.setAttribute('data-sender', user);
|
||||
|
||||
f.render_badge(this);
|
||||
|
||||
if ( localStorage.ffzCapitalize != 'false' )
|
||||
if ( f.settings.capitalize )
|
||||
f.capitalize(this, user);
|
||||
|
||||
// Check for any mentions.
|
||||
var mentioned = el.querySelector('span.mentioned');
|
||||
if ( mentioned ) {
|
||||
el.classList.add("ffz-mentioned");
|
||||
|
||||
if ( ! document.hasFocus() && ! this.get('context.model.ffzNotified') && f.settings.highlight_notifications ) {
|
||||
var cap_room = FFZ.get_capitalization(room),
|
||||
cap_user = FFZ.get_capitalization(user),
|
||||
room_name = cap_room,
|
||||
msg = this.get("context.model.message");
|
||||
|
||||
if ( this.get("context.parentController.content.isGroupRoom") )
|
||||
room_name = this.get("context.parentController.content.tmiRoom.displayName");
|
||||
|
||||
if ( this.get("context.model.style") == "action" )
|
||||
msg = "* " + cap_user + " " + msg;
|
||||
else
|
||||
msg = cap_user + ": " + msg;
|
||||
|
||||
f.show_notification(
|
||||
msg,
|
||||
"Twitch Chat Mention in " + room_name,
|
||||
cap_room,
|
||||
60000,
|
||||
window.focus.bind(window)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Mark that we've checked this message for mentions.
|
||||
this.set('context.model.ffzNotified', true);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -56,12 +155,6 @@ FFZ.prototype.setup_line = function() {
|
|||
var user = this.get_user();
|
||||
if ( user && user.name )
|
||||
FFZ.capitalization[user.login] = [user.name, Date.now()];
|
||||
|
||||
// Load the mention words.
|
||||
if ( localStorage.ffzMentionize )
|
||||
this.mention_words = JSON.parse(localStorage.ffzMentionize);
|
||||
else
|
||||
this.mention_words = [];
|
||||
}
|
||||
|
||||
|
||||
|
@ -73,6 +166,10 @@ FFZ.capitalization = {};
|
|||
FFZ._cap_fetching = 0;
|
||||
|
||||
FFZ.get_capitalization = function(name, callback) {
|
||||
// Use the BTTV code if it's present.
|
||||
if ( window.BetterTTV )
|
||||
return BetterTTV.chat.helpers.lookupDisplayName(name);
|
||||
|
||||
name = name.toLowerCase();
|
||||
if ( name == "jtv" || name == "twitchnotify" )
|
||||
return name;
|
||||
|
@ -113,9 +210,9 @@ FFZ.chat_commands.capitalization = function(room, args) {
|
|||
enabled = false;
|
||||
|
||||
if ( enabled === undefined )
|
||||
return "Chat Name Capitalization is currently " + (localStorage.ffzCapitalize != "false" ? "enabled." : "disabled.");
|
||||
return "Chat Name Capitalization is currently " + (this.settings.capitalize ? "enabled." : "disabled.");
|
||||
|
||||
localStorage.ffzCapitalize = enabled;
|
||||
this.settings.set("capitalize", enabled);
|
||||
return "Chat Name Capitalization is now " + (enabled ? "enabled." : "disabled.");
|
||||
}
|
||||
|
||||
|
@ -128,55 +225,61 @@ FFZ.chat_commands.capitalization.help = "Usage: /ffz capitalization <on|off>\nEn
|
|||
|
||||
FFZ._regex_cache = {};
|
||||
|
||||
FFZ.get_regex = function(word) {
|
||||
return FFZ._regex_cache[word] = FFZ._regex_cache[word] || RegExp("\\b" + reg_escape(word) + "\\b", "i");
|
||||
FFZ._get_rex = function(word) {
|
||||
return FFZ._regex_cache[word] = FFZ._regex_cache[word] || RegExp("\\b" + reg_escape(word) + "\\b", "ig");
|
||||
}
|
||||
|
||||
FFZ._mentions_to_regex = function(list) {
|
||||
return FFZ._regex_cache[list] = FFZ._regex_cache[list] || RegExp("\\b(?:" + _.chain(list).map(reg_escape).value().join("|") + ")\\b", "ig");
|
||||
}
|
||||
|
||||
|
||||
FFZ.prototype._mentionize = function(controller, tokens) {
|
||||
if ( ! this.mention_words )
|
||||
var mention_words = this.settings.keywords;
|
||||
if ( ! mention_words )
|
||||
return tokens;
|
||||
|
||||
if ( typeof tokens == "string" )
|
||||
tokens = [tokens];
|
||||
|
||||
_.each(this.mention_words, function(word) {
|
||||
var eo = {mentionedUser: word, own: false};
|
||||
var regex = FFZ._mentions_to_regex(mention_words);
|
||||
|
||||
tokens = _.compact(_.flatten(_.map(tokens, function(token) {
|
||||
if ( _.isObject(token) )
|
||||
return token;
|
||||
return _.chain(tokens).map(function(token) {
|
||||
if ( !_.isString(token) )
|
||||
return token;
|
||||
else if ( !token.match(regex) )
|
||||
return [token];
|
||||
|
||||
var tbits = token.split(FFZ.get_regex(word)), bits = [];
|
||||
tbits.forEach(function(val, ind) {
|
||||
bits.push(val);
|
||||
if ( ind !== tbits.length - 1 )
|
||||
bits.push(eo);
|
||||
});
|
||||
return bits;
|
||||
})));
|
||||
});
|
||||
|
||||
return tokens;
|
||||
return _.zip(
|
||||
_.map(token.split(regex), _.identity),
|
||||
_.map(token.match(regex), function(e) {
|
||||
return {
|
||||
mentionedUser: e,
|
||||
own: false
|
||||
};
|
||||
})
|
||||
);
|
||||
}).flatten().compact().value();
|
||||
}
|
||||
|
||||
|
||||
FFZ.chat_commands.mentionize = function(room, args) {
|
||||
if ( args && args.length ) {
|
||||
this.mention_words = args.join(" ").trim().split(/\W*,\W*/);
|
||||
if ( this.mention_words.length == 1 && this.mention_words[0] == "disable" )
|
||||
this.mention_words = [];
|
||||
var mention_words = args.join(" ").trim().split(/\W*,\W*/);
|
||||
if ( mention_words.length == 1 && mention_words[0] == "disable" )
|
||||
mention_words = [];
|
||||
|
||||
localStorage.ffzMentionize = JSON.stringify(this.mention_words);
|
||||
this.settings.set("keywords", mention_words);
|
||||
}
|
||||
|
||||
if ( this.mention_words.length )
|
||||
return "The following words will be treated as mentions: " + this.mention_words.join(", ");
|
||||
var mention_words = this.settings.keywords;
|
||||
if ( mention_words.length )
|
||||
return "The following words will be highlighted: " + mention_words.join(", ");
|
||||
else
|
||||
return "There are no words set that will be treated as mentions.";
|
||||
return "There are no words set that will be highlighted.";
|
||||
}
|
||||
|
||||
FFZ.chat_commands.mentionize.help = "Usage: /ffz mentionize <comma, separated, word, list|disable>\nSet a list of words that will also be treated as mentions and be displayed specially in chat.";
|
||||
FFZ.chat_commands.mentionize.help = "Usage: /ffz mentionize <comma, separated, word, list|disable>\nSet a list of words that will also be highlighted in chat.";
|
||||
|
||||
|
||||
// ---------------------
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue