BetterDiscordApp-v1/dev/js/10themeModule.js

64 lines
1.6 KiB
JavaScript
Raw Normal View History

2015-12-16 12:21:46 +01:00
/* BetterDiscordApp ThemeModule JavaScript
* Version: 1.0
* Author: Jiiks | http://jiiks.net
* Date: 16/12/2015
* https://github.com/Jiiks/BetterDiscordApp
*/
var themeCookie = {};
function ThemeModule() {
2016-04-10 14:43:27 +02:00
2015-12-16 12:21:46 +01:00
}
2016-04-10 14:43:27 +02:00
ThemeModule.prototype.loadThemes = function () {
2015-12-16 12:21:46 +01:00
this.loadThemeData();
2016-04-10 14:43:27 +02:00
$.each(bdthemes, function () {
2015-12-16 12:21:46 +01:00
var name = this["name"];
var enabled = false;
2016-04-10 14:43:27 +02:00
if (themeCookie.hasOwnProperty(name)) {
if (themeCookie[name]) {
2015-12-16 12:21:46 +01:00
enabled = true;
}
} else {
themeCookie[name] = false;
}
2016-04-10 14:43:27 +02:00
if (enabled) {
$("head").append('<style id="' + name + '">' + unescape(bdthemes[name]["css"]) + '</style>');
2015-12-16 12:21:46 +01:00
}
});
};
2016-04-10 14:43:27 +02:00
ThemeModule.prototype.handleTheme = function (checkbox) {
2015-12-16 12:21:46 +01:00
var cb = $(checkbox).children().find('input[type="checkbox"]');
var enabled = !cb.is(":checked");
var id = cb.attr("id").substring(2);
cb.prop("checked", enabled);
2016-04-10 14:43:27 +02:00
if (enabled) {
$("head").append('<style id="' + id + '">' + unescape(bdthemes[id]["css"]) + '</style>');
2015-12-16 12:21:46 +01:00
themeCookie[id] = true;
} else {
2016-04-10 14:43:27 +02:00
$("#" + id).remove();
2015-12-16 12:21:46 +01:00
themeCookie[id] = false;
}
2016-04-10 14:43:27 +02:00
2015-12-16 12:21:46 +01:00
this.saveThemeData();
};
2016-04-10 14:43:27 +02:00
ThemeModule.prototype.loadThemeData = function () {
2015-12-16 12:21:46 +01:00
var cookie = $.cookie("bd-themes");
2016-04-10 14:43:27 +02:00
if (cookie != undefined) {
2015-12-16 12:21:46 +01:00
themeCookie = JSON.parse($.cookie("bd-themes"));
}
};
2016-04-10 14:43:27 +02:00
ThemeModule.prototype.saveThemeData = function () {
$.cookie("bd-themes", JSON.stringify(themeCookie), {
expires: 365,
path: '/'
});
2015-12-16 12:21:46 +01:00
};