/* BetterDiscordApp Core JavaScript
* Version: 1.53
* Author: Jiiks | http://jiiks.net
* Date: 27/08/2015 - 16:36
* Last Update: 02/04/2016
* https://github.com/Jiiks/BetterDiscordApp
*/
var BD;
function Core() {
BD = this;
}
Core.prototype.init = function () {
var self = this;
this.version = version;
if (this.version < bdConfig.versionInfo.supportedVersion) {
this.alert("Not Supported", "BetterDiscord v" + this.version + "(your version)" + " is not supported by the latest js(" + bdConfig.versionInfo.version + ").
Please download the latest version from BetterDiscord.net");
return;
}
this.modules = {
emoteModule: new EmoteModule(),
publicServers: new PublicServers(),
emoteMenu: new QuickEmoteMenu(),
cssEditor: new customCssEditor(),
settingsPanel: new SettingsPanel(),
utils: new Utils(),
voiceMode: new VoiceMode(),
pluginModule: new pluginModule(),
themeModule: new ThemeModule()
}
this.modules.utils.getHash();
this.modules.emoteModule.init();
this.initSettings();
this.initObserver();
//Incase were too fast
function gwDefer() {
self.modules.utils.log(new Date().getTime() + " Defer");
if ($(".guilds-wrapper .guilds").children().length > 0) {
self.modules.utils.log(new Date().getTime() + " Defer Loaded");
var guilds = $(".guilds>li:first-child");
var showChannelsButton = $("", {
class: "btn",
id: "bd-show-channels",
text: "R",
css: {
"cursor": "pointer"
},
click: function () {
self.settingsCookie["bda-gs-3"] = false;
$("body").removeClass("bd-minimal-chan");
self.saveSettings();
}
});
$(".guilds-wrapper").prepend(showChannelsButton);
self.modules.pluginModule.loadPlugins();
if (typeof (themesupport2) !== "undefined") {
self.modules.themeModule.loadThemes();
}
self.modules.settingsPanel.init();
self.modules.quickEmoteMenu.init(false);
window.addEventListener("beforeunload", function(){
if(self.settingsCookie["bda-dc-0"]){
$('.btn.btn-disconnect').click();
}
});
self.modules.publicServers.init();
self.modules.emoteModule.autoCapitalize();
/*Display new features in BetterDiscord*/
if (self.settingsCookie["version"] < bdConfig.versionInfo.version) {
var cl = self.constructChangelog();
$("body").append(cl);
self.settingsCookie["version"] = bdConfig.versionInfo.version;
self.saveSettings();
}
$("head").append("");
$("head").append('');
} else {
setTimeout(gwDefer, 100);
}
}
$(document).ready(function () {
setTimeout(gwDefer, 1000);
});
};
Core.prototype.initSettings = function () {
if ($.cookie("better-discord") == undefined) {
this.settingsCookie = bdConfig.defaults;
this.saveSettings();
} else {
this.loadSettings();
for (var setting in defaultCookie) {
if (this.settingsCookie[setting] == undefined) {
this.settingsCookie[setting] = bdConfig.defaults[setting];
this.saveSettings();
}
}
}
};
Core.prototype.saveSettings = function () {
$.cookie("better-discord", JSON.stringify(this.settingsCookie), {
expires: 365,
path: '/'
});
};
Core.prototype.loadSettings = function () {
this.settingsCookie = JSON.parse($.cookie("better-discord"));
};
Core.prototype.initObserver = function () {
var self = this;
this.observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
if($(mutation.target).find(".emoji-picker").length) {
var fc = mutation.target.firstChild;
if(fc.classList.contains("popout")) {
self.modules.quickEmoteMenu.obsCallback($(fc));
}
}
if (typeof pluginModule !== "undefined") self.modules.pluginModule.rawObserver(mutation);
if (mutation.target.getAttribute('class') != null) {
//console.log(mutation.target)
if(mutation.target.classList.contains('title-wrap') || mutation.target.classList.contains('chat')){
// quickEmoteMenu.obsCallback();
self.modules.voiceMode.obsCallback();
if (typeof pluginModule !== "undefined") self.modules.pluginModule.channelSwitch();
}
if (mutation.target.getAttribute('class').indexOf('scroller messages') != -1) {
if (typeof self.modules.pluginModule !== "undefined") self.modules.pluginModule.newMessage();
}
}
self.modules.emoteModule.obsCallback(mutation);
});
});
//noinspection JSCheckFunctionSignatures
mainObserver.observe(document, {
childList: true,
subtree: true
});
};
Core.prototype.constructChangelog = function () {
var changeLog = '' +
'