1
0
Fork 0
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:
SirStendec 2015-02-08 02:01:09 -05:00
parent c9bd39de8a
commit b284bd0f8d
15 changed files with 2313 additions and 190 deletions

View file

@ -1,15 +1,147 @@
var FFZ = window.FrankerFaceZ;
FFZ.prototype.show_notification = function(message) {
// ---------------------
// Initialization
// ---------------------
FFZ.prototype.setup_notifications = function() {
this.log("Adding event handler for window focus.");
window.addEventListener("focus", this.clear_notifications.bind(this));
}
// ---------------------
// Settings
// ---------------------
FFZ.settings_info.highlight_notifications = {
type: "boolean",
value: false,
visible: function() { return ! this.has_bttv },
name: "Highlight Notifications",
help: "Display notifications when a highlighted word appears in chat in an unfocused tab.",
on_update: function(val, direct) {
// Check to see if we have notification permission. If this is
// enabled, at least.
if ( ! val || ! direct )
return;
if ( Notification.permission === "denied" ) {
this.log("Notifications have been denied by the user.");
this.settings.set("highlight_notifications", false);
return;
} else if ( Notification.permission === "granted" )
return;
var f = this;
Notification.requestPermission(function(e) {
if ( e === "denied" ) {
f.log("Notifications have been denied by the user.");
f.settings.set("highlight_notifications", false);
}
});
}
};
// ---------------------
// Socket Commands
// ---------------------
FFZ.ws_commands.message = function(message) {
this.show_mesage(message);
}
// ---------------------
// Notifications
// ---------------------
FFZ._notifications = {};
FFZ._last_notification = 0;
FFZ.prototype.clear_notifications = function() {
for(var k in FFZ._notifications) {
var n = FFZ._notifications[k];
if ( n )
try {
n.close();
} catch(err) { }
}
FFZ._notifications = {};
FFZ._last_notification = 0;
}
FFZ.prototype.show_notification = function(message, title, tag, timeout, on_click, on_close) {
var perm = Notification.permission;
if ( perm === "denied " )
return false;
if ( perm === "granted" ) {
title = title || "FrankerFaceZ";
timeout = timeout || 10000;
var options = {
lang: "en-US",
dir: "ltr",
body: message,
tag: tag || "FrankerFaceZ",
icon: "http://cdn.frankerfacez.com/icon32.png"
};
var f = this,
n = new Notification(title, options),
nid = FFZ._last_notification++;
FFZ._notifications[nid] = n;
n.addEventListener("click", function() {
delete FFZ._notifications[nid];
if ( on_click )
on_click.bind(f)();
});
n.addEventListener("close", function() {
delete FFZ._notifications[nid];
if ( on_close )
on_close.bind(f)();
});
if ( typeof timeout == "number" )
n.addEventListener("show", function() {
setTimeout(function() {
delete FFZ._notifications[nid];
n.close();
}, timeout);
});
return;
}
var f = this;
Notification.requestPermission(function(e) {
f.show_notification(message, title, tag);
});
}
// ---------------------
// Noty Notification
// ---------------------
FFZ.prototype.show_message = function(message) {
window.noty({
text: message,
theme: "ffzTheme",
layout: "bottomCenter",
closeWith: ["button"]
}).show();
}
FFZ.ws_commands.message = function(message) {
this.show_notification(message);
}