BetterDiscordApp-v1/dev/js/09pluginModule.js

122 lines
3.3 KiB
JavaScript
Raw Normal View History

2015-12-16 12:21:46 +01:00
/* BetterDiscordApp PluginModule JavaScript
* Version: 1.0
* Author: Jiiks | http://jiiks.net
* Date: 16/12/2015
* https://github.com/Jiiks/BetterDiscordApp
*/
var pluginCookie = {};
function PluginModule() {
2016-04-10 14:43:27 +02:00
2015-12-16 12:21:46 +01:00
}
2016-04-10 14:43:27 +02:00
PluginModule.prototype.loadPlugins = function () {
2015-12-16 12:21:46 +01:00
this.loadPluginData();
2016-04-10 14:43:27 +02:00
$.each(bdplugins, function () {
2015-12-16 12:21:46 +01:00
var plugin = this["plugin"];
plugin.load();
2016-04-10 14:43:27 +02:00
2015-12-16 12:21:46 +01:00
var name = plugin.getName();
var enabled = false;
2016-04-10 14:43:27 +02:00
if (pluginCookie.hasOwnProperty(name)) {
2015-12-16 12:21:46 +01:00
enabled = pluginCookie[name];
} else {
pluginCookie[name] = false;
}
2016-04-10 14:43:27 +02:00
if (enabled) {
2015-12-16 12:21:46 +01:00
plugin.start();
}
});
};
2016-04-10 14:43:27 +02:00
PluginModule.prototype.handlePlugin = function (checkbox) {
2015-12-16 12:21:46 +01:00
var cb = $(checkbox).children().find('input[type="checkbox"]');
var enabled = !cb.is(":checked");
2016-05-22 18:40:07 +02:00
var id = cb.attr("id").replace("__", " ");
2015-12-16 12:21:46 +01:00
cb.prop("checked", enabled);
2016-04-10 14:43:27 +02:00
if (enabled) {
2015-12-16 12:21:46 +01:00
bdplugins[id]["plugin"].start();
pluginCookie[id] = true;
} else {
bdplugins[id]["plugin"].stop();
pluginCookie[id] = false;
}
2016-04-10 14:43:27 +02:00
2015-12-16 12:21:46 +01:00
this.savePluginData();
};
2016-04-10 14:43:27 +02:00
PluginModule.prototype.showSettings = function (plugin) {
if (bdplugins[plugin] != null) {
if (typeof bdplugins[plugin].plugin.getSettingsPanel === "function") {
var panel = bdplugins[plugin].plugin.getSettingsPanel();
$(".modal-inner").off("click.bdpsm").on("click.bdpsm", function (e) {
if ($("#bd-psm-id").length) {
$(".bd-psm").remove();
} else {
$(".bd-psm").attr("id", "bd-psm-id");
}
});
$(".modal").append('<div class="bd-psm"><div class="scroller-wrap" style="height:100%"><div id="bd-psm-s" class="scroller" style="padding:10px;"></div></div></div>');
$("#bd-psm-s").append(panel);
}
}
};
PluginModule.prototype.loadPluginData = function () {
2015-12-16 12:21:46 +01:00
var cookie = $.cookie("bd-plugins");
2016-04-10 14:43:27 +02:00
if (cookie != undefined) {
pluginCookie = JSON.parse($.cookie("bd-plugins"));
2015-12-16 12:21:46 +01:00
}
};
2016-04-10 14:43:27 +02:00
PluginModule.prototype.savePluginData = function () {
$.cookie("bd-plugins", JSON.stringify(pluginCookie), {
expires: 365,
path: '/'
});
};
PluginModule.prototype.newMessage = function () {
$.each(bdplugins, function () {
if (!pluginCookie[this.plugin.getName()]) return;
if (typeof this.plugin.onMessage === "function") {
this.plugin.onMessage();
}
});
};
PluginModule.prototype.channelSwitch = function () {
$.each(bdplugins, function () {
if (!pluginCookie[this.plugin.getName()]) return;
if (typeof this.plugin.onSwitch === "function") {
this.plugin.onSwitch();
}
});
};
PluginModule.prototype.socketEvent = function (e, data) {
$.each(bdplugins, function () {
if (!pluginCookie[this.plugin.getName()]) return;
if (typeof this.plugin.socketEvent === "function") {
this.plugin.socketEvent(data);
}
});
};
PluginModule.prototype.rawObserver = function(e) {
$.each(bdplugins, function() {
if (!pluginCookie[this.plugin.getName()]) return;
if(typeof this.plugin.observer === "function") {
this.plugin.observer(e);
}
});
2015-12-16 12:21:46 +01:00
};