BetterDiscordApp-rauenzi/js/settingspanel.js

120 lines
3.9 KiB
JavaScript
Raw Normal View History

2015-08-26 11:37:05 +02:00
/* BetterDiscordApp Settings Panel JavaScript
2015-08-30 11:17:06 +02:00
* Version: 1.3
2015-08-26 11:37:05 +02:00
* Author: Jiiks | http://jiiks.net
* Date: 26/08/2015 - 11:54
2015-08-30 11:17:06 +02:00
* Last Update: 30/08/2015 - 12:16
2015-08-26 11:37:05 +02:00
* https://github.com/Jiiks/BetterDiscordApp
*/
2015-08-29 08:55:06 +02:00
var links = { "Check for updates": "#", "Jiiks.net": "http://jiiks.net", "Twitter": "http://twitter.com/jiiksi", "Github": "https://github.com/jiiks" };
2015-08-26 11:37:05 +02:00
function SettingsPanel() {
}
SettingsPanel.prototype.getPanel = function() {
return this.tcSettingsPanel;
}
SettingsPanel.prototype.init = function() {
var self = this;
this.tcSettingsPanel = $("<div/>", { id: "tc-settings-panel" });
this.getPanel().append($("<div/>", { id: "tc-settings-panel-header" }).append($("<h2/>", { text: "BetterDiscord - Settings" })).append($("<span/>", { id: "tc-settings-close", text: "X", style:"cursor:pointer;" })));
var settingsList = $("<ul/>");
this.getPanel().append($("<div/>", { id: "tc-settings-panel-body" }).append(settingsList));
$.each(settings, function(key, value) {
var son = "tc-switch-on";
var sof = "tc-switch-off";
2015-08-28 09:42:05 +02:00
if(settingsCookie[value.id]) {
2015-08-26 11:37:05 +02:00
son = "tc-switch-on active";
}else {
sof = "tc-switch-off active";
}
2015-08-30 11:17:06 +02:00
console.log(value.implemented);
settingsList.append($("<li/>").append($("<h2/>", { text: key})).append($("<span/>", { html: " - <span>" + value.info + "</span>" + (value.implemented == false ? '<span style="color:red"> Coming Soon</span>' : "") })).append($("<div/>", { class: value.implemented ? "tc-switch" : "tc-switch disabled", id: value.id }).append($("<span/>", { class: sof, text: "OFF" })).append($("<span/>", { class: son, text: "ON" }))));
2015-08-26 11:37:05 +02:00
})
var settingsFooter = $("<div/>", { id: "tc-settings-panel-footer" });
2015-08-29 08:55:06 +02:00
settingsFooter.append($("<span/>", { id: "tc-about", text: "BDA v" + version + "(js "+jsVersion+") by Jiiks | Settings are automatically saved." } ));
2015-08-26 11:37:05 +02:00
var tcLinks = $("<span/>", { id: "tc-links" });
$.each(links, function(key, value) {
tcLinks.append($("<a/>", { href: value, text: key }));
tcLinks.append($("<span/>", { text: " | " }));
})
settingsFooter.append(tcLinks);
this.getPanel().append(settingsFooter);
$("body").append(this.getPanel());
$("#tc-settings-close").on("click", function(e) { self.show(); });
$(".tc-switch").on("click", function() { self.handler($(this)) });
2015-08-30 11:17:06 +02:00
if(settingsCookie["bda-es-0"]) {
$("#twitchcord-button-container").show();
} else {
$("#twitchcord-button-container").hide();
}
if(settingsCookie["bda-gs-2"]) {
$("body").addClass("bd-minimal");
} else {
$("body").removeClass("bd-minimal");
}
if(settingsCookie["bda-gs-3"]) {
$("body").addClass("bd-minimal-chan");
} else {
$("body").removeClass("bd-minimal-chan");
}
2015-08-26 11:37:05 +02:00
}
SettingsPanel.prototype.show = function() {
this.getPanel().toggle();
$("#tc-settings-li").removeClass();
if(this.getPanel().is(":visible")) {
$("#tc-settings-li").addClass("active");
}
}
SettingsPanel.prototype.handler = function(e){
var sid = e.attr("id");
var enabled = settingsCookie[sid];
enabled = !enabled;
settingsCookie[sid] = enabled;
var swoff = $("#" + sid + " .tc-switch-off");
var swon = $("#" + sid + " .tc-switch-on");
swoff.removeClass("active");
swon.removeClass("active");
if(enabled) {
swon.addClass("active");
} else {
swoff.addClass("active");
}
2015-08-29 08:55:06 +02:00
if(settingsCookie["bda-es-0"]) {
2015-08-26 11:37:05 +02:00
$("#twitchcord-button-container").show();
} else {
$("#twitchcord-button-container").hide();
}
2015-08-26 18:40:10 +02:00
2015-08-30 11:17:06 +02:00
if(settingsCookie["bda-gs-2"]) {
$("body").addClass("bd-minimal");
} else {
$("body").removeClass("bd-minimal");
}
if(settingsCookie["bda-gs-3"]) {
$("body").addClass("bd-minimal-chan");
} else {
$("body").removeClass("bd-minimal-chan");
}
2015-08-26 18:40:10 +02:00
2015-08-30 11:17:06 +02:00
core.saveSettings();
2015-08-26 11:37:05 +02:00
}