mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-09-03 03:40:56 +00:00
Modified how capitalization is handled. Added code to clean up localStorage of old script's remnants. Added sorting and capitalization of the viewer list.
This commit is contained in:
parent
1663b8e2ea
commit
d961cb954f
5 changed files with 296 additions and 41 deletions
89
src/ember/viewers.js
Normal file
89
src/ember/viewers.js
Normal file
|
@ -0,0 +1,89 @@
|
|||
var FFZ = window.FrankerFaceZ;
|
||||
|
||||
|
||||
// --------------------
|
||||
// Initialization
|
||||
// --------------------
|
||||
|
||||
FFZ.prototype.setup_viewers = function() {
|
||||
this.log("Hooking the Ember Viewers controller.");
|
||||
|
||||
var Viewers = App.__container__.resolve('controller:viewers');
|
||||
this._modify_viewers(Viewers);
|
||||
}
|
||||
|
||||
|
||||
FFZ.prototype._modify_viewers = function(controller) {
|
||||
var f = this;
|
||||
|
||||
controller.reopen({
|
||||
lines: function() {
|
||||
var viewers = this._super(),
|
||||
categories = [],
|
||||
data = {},
|
||||
last_category = null;
|
||||
|
||||
// Get the broadcaster name.
|
||||
var Channel = App.__container__.lookup('controller:channel'),
|
||||
room_id = this.get('parentController.model.id'),
|
||||
broadcaster = Channel && Channel.get('id');
|
||||
|
||||
// We can get capitalization for the broadcaster from the channel.
|
||||
if ( broadcaster ) {
|
||||
var display_name = Channel.get('display_name');
|
||||
if ( display_name )
|
||||
FFZ.capitalization[broadcaster] = [display_name, Date.now()];
|
||||
}
|
||||
|
||||
// If the current room isn't the channel's chat, then we shouldn't
|
||||
// display them as the broadcaster.
|
||||
if ( room_id != broadcaster )
|
||||
broadcaster = null;
|
||||
|
||||
// Now, break the viewer array down into something we can use.
|
||||
for(var i=0; i < viewers.length; i++) {
|
||||
var entry = viewers[i];
|
||||
if ( entry.category ) {
|
||||
last_category = entry.category;
|
||||
categories.push(last_category);
|
||||
data[last_category] = [];
|
||||
|
||||
} else {
|
||||
var viewer = entry.chatter.toLowerCase();
|
||||
if ( ! viewer )
|
||||
continue;
|
||||
|
||||
// If the viewer is the broadcaster, give them their own
|
||||
// group. Don't put them with normal mods!
|
||||
if ( viewer == broadcaster ) {
|
||||
categories.unshift("Broadcaster");
|
||||
data["Broadcaster"] = [viewer];
|
||||
|
||||
} else if ( data.hasOwnProperty(last_category) )
|
||||
data[last_category].push(viewer);
|
||||
}
|
||||
}
|
||||
|
||||
// Now, rebuild the viewer list. However, we're going to actually
|
||||
// sort it this time.
|
||||
viewers = [];
|
||||
for(var i=0; i < categories.length; i++) {
|
||||
var category = categories[i],
|
||||
chatters = data[category];
|
||||
|
||||
if ( ! chatters || ! chatters.length )
|
||||
continue;
|
||||
|
||||
viewers.push({category: category});
|
||||
viewers.push({chatter: ""});
|
||||
|
||||
// Push the chatters, capitalizing them as we go.
|
||||
chatters.sort();
|
||||
while(chatters.length)
|
||||
viewers.push({chatter: FFZ.get_capitalization(chatters.shift())});
|
||||
}
|
||||
|
||||
return viewers;
|
||||
}.property("content.chatters")
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue