Core rewrite

This commit is contained in:
Jiiks 2016-04-11 11:10:25 +03:00
parent 8a15d57e39
commit 3a365f30ed
1 changed files with 53 additions and 64 deletions

View File

@ -8,12 +8,6 @@
var BD; var BD;
var settingsPanel, emoteModule, utils, quickEmoteMenu, opublicServers, voiceMode, pluginModule, themeModule, customCssEditor;
var mainObserver;
var mainCore;
var settingsCookie = {};
function Core() { function Core() {
BD = this; BD = this;
} }
@ -21,30 +15,38 @@ function Core() {
Core.prototype.init = function () { Core.prototype.init = function () {
var self = this; var self = this;
this.version = version; this.version = version;
this.jsVersion = jsVersion;
if (this.version < supportedVersion) { if (this.version < bdConfig.versionInfo.supportedVersion) {
this.alert("Not Supported", "BetterDiscord v" + this.version + "(your version)" + " is not supported by the latest js(" + this.jsVersion + ").<br><br> Please download the latest version from <a href='https://betterdiscord.net' target='_blank'>BetterDiscord.net</a>"); this.alert("Not Supported", "BetterDiscord v" + this.version + "(your version)" + " is not supported by the latest js(" + bdConfig.versionInfo.version + ").<br><br> Please download the latest version from <a href='https://betterdiscord.net' target='_blank'>BetterDiscord.net</a>");
return; return;
} }
this.utils = new Utils(); 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()
}
utils = new Utils(); this.modules.utils.getHash();
utils.getHash();
emoteModule = new EmoteModule();
quickEmoteMenu = new QuickEmoteMenu();
voiceMode = new VoiceMode();
emoteModule.init(); this.modules.emoteModule.init();
this.initSettings(); this.initSettings();
this.initObserver(); this.initObserver();
//Incase were too fast //Incase were too fast
function gwDefer() { function gwDefer() {
console.log(new Date().getTime() + " Defer"); self.modules.utils.log(new Date().getTime() + " Defer");
if ($(".guilds-wrapper .guilds").children().length > 0) { if ($(".guilds-wrapper .guilds").children().length > 0) {
console.log(new Date().getTime() + " Defer Loaded"); self.modules.utils.log(new Date().getTime() + " Defer Loaded");
var guilds = $(".guilds>li:first-child"); var guilds = $(".guilds>li:first-child");
var showChannelsButton = $("<button/>", { var showChannelsButton = $("<button/>", {
@ -55,7 +57,7 @@ Core.prototype.init = function () {
"cursor": "pointer" "cursor": "pointer"
}, },
click: function () { click: function () {
settingsCookie["bda-gs-3"] = false; self.settingsCookie["bda-gs-3"] = false;
$("body").removeClass("bd-minimal-chan"); $("body").removeClass("bd-minimal-chan");
self.saveSettings(); self.saveSettings();
} }
@ -63,39 +65,29 @@ Core.prototype.init = function () {
$(".guilds-wrapper").prepend(showChannelsButton); $(".guilds-wrapper").prepend(showChannelsButton);
opublicServers = new PublicServers(); self.modules.pluginModule.loadPlugins();
customCssEditor = new CustomCssEditor();
pluginModule = new PluginModule();
pluginModule.loadPlugins();
if (typeof (themesupport2) !== "undefined") { if (typeof (themesupport2) !== "undefined") {
themeModule = new ThemeModule(); self.modules.themeModule.loadThemes();
themeModule.loadThemes();
} }
settingsPanel = new SettingsPanel(); self.modules.settingsPanel.init();
settingsPanel.init();
quickEmoteMenu.init(false); self.modules.quickEmoteMenu.init(false);
$("#tc-settings-button").on("click", function () {
settingsPanel.show();
});
window.addEventListener("beforeunload", function(){ window.addEventListener("beforeunload", function(){
if(settingsCookie["bda-dc-0"]){ if(self.settingsCookie["bda-dc-0"]){
$('.btn.btn-disconnect').click(); $('.btn.btn-disconnect').click();
} }
}); });
self.modules.publicServers.init();
opublicServers.init(); self.modules.emoteModule.autoCapitalize();
emoteModule.autoCapitalize();
/*Display new features in BetterDiscord*/ /*Display new features in BetterDiscord*/
if (settingsCookie["version"] < jsVersion) { if (self.settingsCookie["version"] < bdConfig.versionInfo.version) {
var cl = self.constructChangelog(); var cl = self.constructChangelog();
$("body").append(cl); $("body").append(cl);
settingsCookie["version"] = jsVersion; self.settingsCookie["version"] = bdConfig.versionInfo.version;
self.saveSettings(); self.saveSettings();
} }
@ -115,14 +107,14 @@ Core.prototype.init = function () {
Core.prototype.initSettings = function () { Core.prototype.initSettings = function () {
if ($.cookie("better-discord") == undefined) { if ($.cookie("better-discord") == undefined) {
settingsCookie = defaultCookie; this.settingsCookie = bdConfig.defaults;
this.saveSettings(); this.saveSettings();
} else { } else {
this.loadSettings(); this.loadSettings();
for (var setting in defaultCookie) { for (var setting in defaultCookie) {
if (settingsCookie[setting] == undefined) { if (this.settingsCookie[setting] == undefined) {
settingsCookie[setting] = defaultCookie[setting]; this.settingsCookie[setting] = bdConfig.defaults[setting];
this.saveSettings(); this.saveSettings();
} }
} }
@ -130,38 +122,39 @@ Core.prototype.initSettings = function () {
}; };
Core.prototype.saveSettings = function () { Core.prototype.saveSettings = function () {
$.cookie("better-discord", JSON.stringify(settingsCookie), { $.cookie("better-discord", JSON.stringify(this.settingsCookie), {
expires: 365, expires: 365,
path: '/' path: '/'
}); });
}; };
Core.prototype.loadSettings = function () { Core.prototype.loadSettings = function () {
settingsCookie = JSON.parse($.cookie("better-discord")); this.settingsCookie = JSON.parse($.cookie("better-discord"));
}; };
Core.prototype.initObserver = function () { Core.prototype.initObserver = function () {
mainObserver = new MutationObserver(function (mutations) { var self = this;
this.observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) { mutations.forEach(function (mutation) {
if($(mutation.target).find(".emoji-picker").length) { if($(mutation.target).find(".emoji-picker").length) {
var fc = mutation.target.firstChild; var fc = mutation.target.firstChild;
if(fc.classList.contains("popout")) { if(fc.classList.contains("popout")) {
quickEmoteMenu.obsCallback($(fc)); self.modules.quickEmoteMenu.obsCallback($(fc));
} }
} }
if (typeof pluginModule !== "undefined") pluginModule.rawObserver(mutation); if (typeof pluginModule !== "undefined") self.modules.pluginModule.rawObserver(mutation);
if (mutation.target.getAttribute('class') != null) { if (mutation.target.getAttribute('class') != null) {
//console.log(mutation.target) //console.log(mutation.target)
if(mutation.target.classList.contains('title-wrap') || mutation.target.classList.contains('chat')){ if(mutation.target.classList.contains('title-wrap') || mutation.target.classList.contains('chat')){
// quickEmoteMenu.obsCallback(); // quickEmoteMenu.obsCallback();
voiceMode.obsCallback(); self.modules.voiceMode.obsCallback();
if (typeof pluginModule !== "undefined") pluginModule.channelSwitch(); if (typeof pluginModule !== "undefined") self.modules.pluginModule.channelSwitch();
} }
if (mutation.target.getAttribute('class').indexOf('scroller messages') != -1) { if (mutation.target.getAttribute('class').indexOf('scroller messages') != -1) {
if (typeof pluginModule !== "undefined") pluginModule.newMessage(); if (typeof self.modules.pluginModule !== "undefined") self.modules.pluginModule.newMessage();
} }
} }
emoteModule.obsCallback(mutation); self.modules.emoteModule.obsCallback(mutation);
}); });
}); });
@ -184,15 +177,15 @@ Core.prototype.constructChangelog = function () {
' <div class="scroller-wrap">' + ' <div class="scroller-wrap">' +
' <div class="scroller">'; ' <div class="scroller">';
if (bdchangelog.changes != null) { if (bdConfig.changelog.changes != null) {
changeLog += '' + changeLog += '' +
'<h1 class="changelog-added">' + '<h1 class="changelog-added">' +
' <span>New Stuff</span>' + ' <span>New Stuff</span>' +
'</h1>' + '</h1>' +
'<ul>'; '<ul>';
for (var change in bdchangelog.changes) { for (var change in bdConfig.changelog.changes) {
change = bdchangelog.changes[change]; change = bdConfig.changelog.changes[change];
changeLog += '' + changeLog += '' +
'<li>' + '<li>' +
@ -204,15 +197,15 @@ Core.prototype.constructChangelog = function () {
changeLog += '</ul>'; changeLog += '</ul>';
} }
if (bdchangelog.fixes != null) { if (bdConfig.changelog.fixes != null) {
changeLog += '' + changeLog += '' +
'<h1 class="changelog-fixed">' + '<h1 class="changelog-fixed">' +
' <span>Fixed</span>' + ' <span>Fixed</span>' +
'</h1>' + '</h1>' +
'<ul>'; '<ul>';
for (var fix in bdchangelog.fixes) { for (var fix in bdConfig.changelog.fixes) {
fix = bdchangelog.fixes[fix]; fix = bdConfig.changelog.fixes[fix];
changeLog += '' + changeLog += '' +
'<li>' + '<li>' +
@ -224,15 +217,15 @@ Core.prototype.constructChangelog = function () {
changeLog += '</ul>'; changeLog += '</ul>';
} }
if (bdchangelog.upcoming != null) { if (bdConfig.changelog.upcoming != null) {
changeLog += '' + changeLog += '' +
'<h1 class="changelog-in-progress">' + '<h1 class="changelog-in-progress">' +
' <span>Coming Soon</span>' + ' <span>Coming Soon</span>' +
'</h1>' + '</h1>' +
'<ul>'; '<ul>';
for (var upc in bdchangelog.upcoming) { for (var upc in bdConfig.changelog.upcoming) {
upc = bdchangelog.upcoming[upc]; upc = bdConfig.changelog.upcoming[upc];
changeLog += '' + changeLog += '' +
'<li>' + '<li>' +
@ -269,8 +262,4 @@ Core.prototype.alert = function (title, text) {
' </div>' + ' </div>' +
' </div>' + ' </div>' +
'</div>'); '</div>');
};
Core.prototype.getUtils = function() {
return this.utils;
}; };