let's see what breaks

This commit is contained in:
Zack Rauen 2017-10-29 18:43:32 -04:00
parent 8a2cda49dd
commit 7897b2cd77
1 changed files with 1 additions and 761 deletions

View File

@ -1526,7 +1526,7 @@ function SettingsPanel() {
SettingsPanel.prototype.init = function () {
var self = this;
self.v2SettingsPanel = new V2_SettingsPanel();
self.construct();
// self.construct();
var body = $("body");
if (settingsCookie["bda-es-0"]) {
@ -1588,67 +1588,6 @@ SettingsPanel.prototype.init = function () {
var customCssInitialized = false;
var lastTab = "";
SettingsPanel.prototype.changeTab = function (tab) {
var self = this;
lastTab = tab;
var controlGroups = $("#bd-control-groups");
$(".bd-tab").removeClass("selected");
$(".bd-pane").hide();
$("#" + tab).addClass("selected");
$("#" + tab.replace("tab", "pane")).show();
switch (tab) {
case "bd-settings-tab":
$(".bda-slist-top").show();
break;
case "bd-emotes-tab":
$(".bda-slist-top").show();
break;
case "bd-customcss-tab":
$(".bda-slist-top").show();
if (!customCssInitialized) {
customCssEditor.init();
customCssInitialized = true;
}
break;
case "bd-themes-tab":
$(".bda-slist-top:first").hide();
break;
case "bd-plugins-tab":
$(".bda-slist-top:first").hide();
break;
default:
$(".bda-slist-top").show();
break;
}
};
SettingsPanel.prototype.updateSetting = function (checkbox) {
var cb = $(checkbox).children().find('input[type="checkbox"]');
var enabled = !cb.is(":checked");
var id = cb.attr("id");
cb.prop("checked", enabled);
if(id == "bda-css-2") {
$("#app-mount").removeClass("bd-hide-bd");
customCssEditor.hideBackdrop = enabled;
if(enabled) {
$("#app-mount").addClass("bd-hide-bd")
}
}
if(id == "bda-gs-8" && enabled) {
mainCore.alert("Developer Mode Enabled", "Use F8 to break/resume execution<br>More coming soon")
}
settingsCookie[id] = enabled;
this.updateSettings();
};
SettingsPanel.prototype.updateSettings = function() {
if (settingsCookie["bda-es-0"]) {
$("#twitchcord-button-container").show();
@ -1713,274 +1652,6 @@ SettingsPanel.prototype.updateSettings = function() {
mainCore.saveSettings();
};
SettingsPanel.prototype.construct = function () {
var self = this;
panel = $("<div/>", {
id: "bd-pane",
class: "settings-inner",
css: {
"display": "none"
}
});
//Panel start and core settings
var settingsInner = '\
<div class="scroller-wrap">\
<div class="scroller settings-wrapper settings-panel">\
<div class="tab-bar TOP">\
<div class="tab-bar-item bd-tab" id="bd-settings-tab" onclick=\'settingsPanel.changeTab("bd-settings-tab");\'>Core\
</div>\
<div class="tab-bar-item bd-tab" id="bd-emotes-tab" onclick=\'settingsPanel.changeTab("bd-emotes-tab");\'>Emotes\
</div>\
<div class="tab-bar-item bd-tab" id="bd-customcss-tab" onclick=\'settingsPanel.changeTab("bd-customcss-tab");\'>Custom CSS\
</div>\
<div class="tab-bar-item bd-tab" id="bd-plugins-tab" onclick=\'settingsPanel.changeTab("bd-plugins-tab");\'>Plugins\
</div>\
<div class="tab-bar-item bd-tab" id="bd-themes-tab" onclick=\'settingsPanel.changeTab("bd-themes-tab");\'>Themes\
</div>\
<div class="bda-slist-top">\
<button class="btn btn-primary" onclick="utils.exportSettings(); return false;">Export</button>\
<button class="btn btn-primary" onclick="utils.importSettings(); return false;">Import</button>\
</div>\
</div>\
<div class="bd-settings">\
<div class="bd-pane control-group" id="bd-settings-pane" style="display:none;">\
<ul class="checkbox-group">\
';
for(var setting in settings) {
var sett = settings[setting];
var id = sett["id"];
if(sett["cat"] != "core" || !sett["implemented"] || sett["hidden"]) continue;
settingsInner += '\
<li>\
<div class="checkbox" onclick="settingsPanel.updateSetting(this);">\
<div class="checkbox-inner">\
<input type="checkbox" id="'+id+'" '+(settingsCookie[id] ? "checked" : "")+'>\
<span></span>\
</div>\
<span>\
'+setting+' - '+sett["info"]+'\
</span>\
</div>\
</li>\
';
}
settingsInner += '\
</ul>\
</div>\
';
//End core settings
//Emote settings
settingsInner += '\
<div class="bd-pane control-group" id="bd-emotes-pane" style="display:none;">\
<ul class="checkbox-group">\
';
for(var setting in settings) {
var sett = settings[setting];
var id = sett["id"];
if(sett["cat"] != "emote" || !sett["implemented"] || sett["hidden"]) continue;
settingsInner += '\
<li>\
<div class="checkbox" onclick="settingsPanel.updateSetting(this);">\
<div class="checkbox-inner">\
<input type="checkbox" id="'+id+'" '+(settingsCookie[id] ? "checked" : "")+'>\
<span></span>\
</div>\
<span>\
'+setting+' - '+sett["info"]+'\
</span>\
</div>\
</li>\
';
}
settingsInner += '\
</ul>\
</div>\
';
//End emote settings
//Custom CSS Editor
var _ccss = window.bdStorage.get("bdcustomcss");
var ccss = "";
if(_ccss !== null && _ccss !== "") {
ccss = atob(_ccss);
}
customCssEditor.applyCustomCss(ccss, true, false);
settingsInner += '\
<div class="bd-pane control-group" id="bd-customcss-pane" style="display:none;">\
<div id="editor-detached" style="display:none;">\
<h3>Editor Detached</h3>\
<button class="btn btn-primary" onclick="customCssEditor.attach(); return false;">Attach</button>\
</div>\
<div id="bd-customcss-innerpane">\
<textarea id="bd-custom-css-ta">'+ccss+'</textarea>\
</div>\
</div>\
';
//End Custom CSS Editor
//Plugin pane
settingsInner += '\
<div class="bd-pane control-group" id="bd-plugins-pane" style="display:show;">\
<div class="bda-slist-top">\
<button class="btn btn-primary" onclick=\'betterDiscordIPC.send("asynchronous-message", { "arg": "opendir", "path": "plugindir" }); return false;\'>Open Plugin Folder</button>\
<button class="btn btn-primary" onclick=\'window.open("https://betterdiscord.net/plugins"); return false;\'>Get Plugins</button>\
</div>\
<ul class="bda-slist">\
';
$.each(bdplugins, function() {
var plugin = this["plugin"];
var hasSettings = false;
if(typeof(plugin.getSettingsPanel) == "function") {
hasSettings = plugin.getSettingsPanel() != null && plugin.getSettingsPanel() != "";
}
settingsInner += '\
<li>\
<div class="bda-left">\
<span class="bda-name">'+plugin.getName()+' v'+plugin.getVersion()+' by '+plugin.getAuthor()+'</span>\
<div class="scroller-wrap fade">\
<div class="scroller bda-description">'+plugin.getDescription()+'</div>\
</div>\
</div>\
<div class="bda-right">\
<div class="checkbox" onclick="pluginModule.handlePlugin(this);">\
<div class="checkbox-inner">\
<input id="'+plugin.getName().replace(" ", "__")+'" type="checkbox" '+(pluginCookie[plugin.getName()] ? "checked" : "")+'>\
<span></span>\
</div>\
<span></span>\
</div>\
<button class="btn btn-primary bda-plugin-reload" onclick="return false;" disabled>Reload</button>\
<button class="btn btn-primary bda-plugin-settings" onclick=\'pluginModule.showSettings("'+plugin.getName()+'"); return false;\' '+(hasSettings ? "" : "disabled")+'>Settings</button>\
</div>\
</li>\
';
});
settingsInner += '\
</ul>\
</div>\
';
//End plugin pane
//Theme pane
settingsInner += '\
<div class="bd-pane control-group" id="bd-themes-pane" style="display:none;">\
<div class="bda-slist-top">\
<button class="btn btn-primary" onclick=\'betterDiscordIPC.send("asynchronous-message", { "arg": "opendir", "path": "themedir" }); return false;\'>Open Theme Folder</button>\
<button class="btn btn-primary" onclick=\'window.open("https://betterdiscord.net/themes"); return false;\'>Get Themes</button>\
</div>\
<ul class="bda-slist">\
';
if(typeof(themesupport2) === "undefined") {
settingsInner += "Your version does not support themes!";
} else {
$.each(bdthemes, function() {
settingsInner += '\
<li>\
<div class="bda-left">\
<span class="bda-name">'+this["name"].replace(/_/g, " ")+' v'+this["version"]+' by '+this["author"]+'</span>\
<div class="scroller-wrap fade">\
<div class="scroller bda-description">'+this["description"]+'</div>\
</div>\
</div>\
<div class="bda-right">\
<div class="checkbox" onclick="themeModule.handleTheme(this);">\
<div class="checkbox-inner">\
<input id="ti'+this["name"]+'" type="checkbox" '+(themeCookie[this["name"]] ? "checked" : "")+'>\
<span></span>\
</div>\
<span></span>\
</div>\
<button class="btn btn-primary bda-plugin-reload" onclick="return false;" disabled>Reload</button>\
</div>\
</li>\
';
});
}
settingsInner += '\
</ul>\
</div>\
';
//End theme panel
//Footer
settingsInner += '\
<div style="background:#2E3136; color:#ADADAD; height:30px; position:absolute; bottom:0; left:0; right:0;">\
<span style="line-height:30px;margin-left:10px;">BetterDiscord v' + ((typeof(version) == "undefined") ? bdVersion : version) + '(JSv' + jsVersion + ') by Jiiks</span>\
<span style="float:right;line-height:30px;margin-right:10px;"><a href="http://betterdiscord.net" target="_blank">BetterDiscord.net</a></span>\
<span id="bd-changelog" onclick=\'$("body").append(mainCore.constructChangelog());\'>changelog</span>\
</div>\
</div></div>\
';
function showSettings() {
$(".tab-bar-item").removeClass("selected");
settingsButton.addClass("selected");
$(".form .settings-right .settings-inner").first().hide();
panel.show();
if (lastTab == "") {
self.changeTab("bd-settings-tab");
} else {
self.changeTab(lastTab);
}
}
settingsButton = $("<div/>", {
class: "tab-bar-item",
text: "BetterDiscord",
id: "bd-settings-new",
click: showSettings
});
panel.html(settingsInner);
this.panel = panel;
};
SettingsPanel.prototype.inject = function(mutation) {
if(this.injectNew(mutation)) return;
if(mutation.type != "childList") return;
if(mutation.addedNodes.length <= 0) return;
if($(mutation.addedNodes[0]).find(".user-settings-modal").length <= 0) return;
var self = this;
this.panel.hide();
var tabBar = $(".tab-bar.SIDE").first();
$(".tab-bar.SIDE .tab-bar-item").click(function () {
$(".form .settings-right .settings-inner").first().show();
$("#bd-settings-new").removeClass("selected");
self.panel.hide();
});
tabBar.append(settingsButton);
$(".form .settings-right .settings-inner").last().after(self.panel);
$("#bd-settings-new").removeClass("selected");
};
/*New settingspanel temp until v2*/
SettingsPanel.prototype.injectNew = function(mutation) {
@ -2032,330 +1703,6 @@ SettingsPanel.prototype.injectNew = function(mutation) {
return true;
};
SettingsPanel.prototype.versionInfo = function() {
let self = this;
let element = $("<div/>", {
class: 'bd-versioninfo-wrapper'
}).append($("<span/>", {
text: `BetterDiscord v${(typeof(version) === "undefined" ? bdVersion : version)}:${jsVersion} by `
})).append($("<a/>", {
text: 'Jiiks',
href: 'https://google.com',
target: '_blank'
}));
return element;
}
SettingsPanel.prototype.tabBarNew = function() {
let self = this;
let _tabBar = $("<div/>", {
class: 'tab-bar TOP',
style: 'border-bottom:none'
});
let items = [
{ 'id': 'bd-core', 'text': 'Core' },
{ 'id': 'bd-emotes', 'text': 'Emotes' },
{ 'id': 'bd-customcss', 'text': 'Custom CSS' },
{ 'id': 'bd-plugins', 'text': 'Plugins' },
{ 'id': 'bd-themes', 'text': 'Themes' }
];
items.map(value => {
_tabBar.append($("<div/>", {
class: 'tab-bar-item bd-tab',
text: value.text,
id: value.id,
click: () => self.changeTabNew(value.id)
}));
});
return _tabBar;
}
SettingsPanel.prototype.changeTabNew = function(id) {
$(".bd-tab").removeClass("selected");
$(`#${id}`).addClass("selected");
$(".bd-pane").hide();
$(`#${id}-pane`).show();
if(id === 'bd-customcss') {
if (!customCssInitialized) {
customCssEditor.init();
customCssInitialized = true;
}
}
}
SettingsPanel.prototype.updateSettingNew = function (id, checked) {
if(id == "bda-css-2") {
$("#app-mount").removeClass("bd-hide-bd");
customCssEditor.hideBackdrop = checked;
if(checked) {
$("#app-mount").addClass("bd-hide-bd")
}
}
if(id == "bda-gs-8" && checked) {
mainCore.alert("Developer Mode Enabled", "Use F8 to break/resume execution<br>More coming soon")
}
settingsCookie[id] = checked;
this.updateSettings();
};
SettingsPanel.prototype.settingsSwitch = function(key) {
let self = this;
let setting = settings[key];
return $("<div/>", {
class: 'ui-flex flex-vertical flex-justify-start flex-align-stretch flex-nowrap ui-switch-item'
}).append($("<div/>", {
class: 'ui-flex flex-horizontal flex-justify-start flex-align-stretch flex-nowrap'
}).append($("<h3/>", {
class: 'ui-form-title h3 margin-reset margin-reset ui-flex-child',
text: key
})).append($("<label/>", {
class: 'ui-switch-wrapper ui-flex-child',
style: 'flex: 0 0 auto'
}).append($("<input/>", {
class: 'ui-switch-checkbox',
type: 'checkbox',
change: function() { self.updateSettingNew(setting.id, this.checked) },
checked: settingsCookie[setting.id]
})).append($("<div/>", {
class: 'ui-switch'
})))).append($("<div/>", {
class: 'ui-form-text style-description margin-top-4',
style: 'flex: 1 1 auto',
text: setting.info
}));
}
SettingsPanel.prototype.corePaneNew = function() {
let self = this;
let _pane = $("<div/>", {
class: 'ui-form-item bd-pane',
id: 'bd-core-pane',
style: 'display:none'
});
Object.keys(settings).map(value => {
let setting = settings[value];
if(setting.cat !== 'core' || !setting.implemented || setting.hidden) return false;
_pane.append(self.settingsSwitch(value))
});
return _pane;
}
SettingsPanel.prototype.emotesPaneNew = function() {
let self = this;
let _pane = $("<div/>", {
class: 'ui-form-item bd-pane',
id: 'bd-emotes-pane',
style: 'display:none'
});
Object.keys(settings).map(value => {
let setting = settings[value];
if(setting.cat !== 'emote' || !setting.implemented || setting.hidden) return false;
_pane.append(self.settingsSwitch(value))
});
return _pane;
}
SettingsPanel.prototype.customCssPaneNew = function() {
let self = this;
let _pane = $("<div/>", {
class: 'ui-form-item bd-pane',
id: 'bd-customcss-pane',
style: 'display:none'
});
let attachBtn = $("<div/>", {
id: 'editor-detached',
style: 'display:none'
}).append($("<h3/>", {
text: 'Editor Detached'
})).append($("<button/>", {
class: 'btn btn-primary',
text: 'Attach',
click: () => { customCssEditor.attach(); }
}));
_pane.append(attachBtn);
let _ccss = window.bdStorage.get("bdcustomcss");
let ccss = "";
if(_ccss !== null && _ccss !== "") {
ccss = atob(_ccss);
}
let innerPane = $("<div/>", {
id: 'bd-customcss-innerpane'
}).append($("<textarea/>", {
id: 'bd-custom-css-ta',
text: ccss
}));
_pane.append(innerPane);
return _pane;
}
SettingsPanel.prototype.pluginTemp = function(plugin, cb) {
let item = $("<li/>", {
}).append($("<div/>", {
class: 'bda-left'
}).append($("<span/>", {
class: 'bda-name',
text: `${plugin.getName()} v${plugin.getVersion()} by ${plugin.getAuthor()}`
})).append($("<div/>", {
class: 'scroller-wrap fade'
}).append($("<div/>", {
class: 'scroller bda-description',
text: plugin.getDescription()
})))).append($("<div/>", {
class: 'bda-right'
}).append($("<label/>", {
class: 'ui-switch-wrapper ui-flex-child',
style: 'flex: 0 0 auto'
}).append($("<input/>", {
class: 'ui-switch-checkbox',
type: 'checkbox',
change: function() { pluginModule.handlePluginT(plugin.getName(), this.checked) },
checked: pluginCookie[plugin.getName()]
})).append($("<div/>", {
class: 'ui-switch'
}))).append($("<button/>", {
text: 'Reload',
disabled: true,
enabled: false,
click: () => { return false; }
})).append($("<button/>", {
text: 'Settings',
click: () => { pluginModule.showSettingsT(plugin.getName()) }
})));
return item;
}
SettingsPanel.prototype.pluginsPaneNew = function() {
let self = this;
let list = $("<ul/>", {
class: 'bda-slist'
});
$.each(bdplugins, function() {
let plugin = this["plugin"];
list.append(self.pluginTemp(plugin));
});
return $("<div/>", {
class: 'ui-form-item bd-pane',
id: 'bd-plugins-pane',
style: 'display:none'
}).append(list);
}
SettingsPanel.prototype.themeTemp = function(theme) {
let item = $("<li/>", {
}).append($("<div/>", {
class: 'bda-left'
}).append($("<span/>", {
class: 'bda-name',
text: `${theme["name"].replace(/_/g, " ")} v${theme["version"]} by ${theme["author"]}`
})).append($("<div/>", {
class: 'scroller-wrap fade'
}).append($("<div/>", {
class: 'scroller bda-description',
text: theme["description"]
})))).append($("<div/>", {
class: 'bda-right'
}).append($("<label/>", {
class: 'ui-switch-wrapper ui-flex-child',
style: 'flex: 0 0 auto'
}).append($("<input/>", {
class: 'ui-switch-checkbox',
type: 'checkbox',
change: function() { themeModule.handleThemeT(theme["name"], this.checked) },
checked: themeCookie[theme["name"]]
})).append($("<div/>", {
class: 'ui-switch'
}))).append($("<button/>", {
text: 'Reload',
disabled: true,
enabled: false,
click: () => { return false; }
})));
return item;
}
SettingsPanel.prototype.themesPaneNew = function() {
let self = this;
let list = $("<ul/>", {
class: 'bda-slist'
});
$.each(bdthemes, function() {
let theme = this;
list.append(self.themeTemp(theme));
});
return $("<div/>", {
class: 'ui-form-item bd-pane',
id: 'bd-themes-pane',
style: 'display:none'
}).append(list);
}
SettingsPanel.prototype.panesNew = function() {
let self = this;
let _panes = $("<div/>", {
class: 'bd-settings-panes'
});
_panes.append(self.corePaneNew());
_panes.append(self.emotesPaneNew());
_panes.append(self.customCssPaneNew());
_panes.append(self.pluginsPaneNew());
_panes.append(self.themesPaneNew());
return _panes;
}
SettingsPanel.prototype.settingsPaneNew = function() {
let self = this;
if(self.constructed) return self.constructed;
let tools = $(".tools").clone();
tools.find(".btn-close").on("click", () => { $(".tools").first().find(".btn-close").click(); });
self.constructed = $("<div/>", {
class: 'content-region',
id: 'bd-settingspane',
style: 'display:none'
}).append($("<div/>", {
class: 'scroller-wrap fade dark'
}).append($("<div/>", {
class: 'scroller'
}).append($("<div/>", {
class: 'content-column'
}).append(self.tabBarNew()).append(self.panesNew())).append(tools)));
return self.constructed;
};
SettingsPanel.prototype.showBdSettingsPane = function() {
$(".ui-standard-sidebar-view .content-region").first().hide();
$("#bd-settingspane").show();
};
SettingsPanel.prototype.hideBdSettingsPane = function() {
$(".ui-standard-sidebar-view .content-region").first().show();
$("#bd-settingspane").hide();
};
/* BetterDiscordApp Utilities JavaScript
* Version: 1.0
* Author: Jiiks | http://jiiks.net
@ -2435,113 +1782,6 @@ Utils.prototype.err = function (message) {
console.log('%c[%cBetterDiscord%c] %c' + message + '', 'color: red;', 'color: red; font-weight:700;', 'color:red;', '');
};
Utils.prototype.importSettings = function() {
mainCore.alert("Import Settings", '<div class="form" style="width:100%;"><div class="control-group"><textarea id="bda-import-textarea" style="min-height:150px;"></textarea></div><button id="bda-import-settings" class="btn btn-primary">Import</button></div>');
$("#bda-import-settings").off("click").on("click", function() {
var obj;
try {
obj = JSON.parse($("#bda-import-textarea").val());
}catch(err) {
mainCore.alert("Invalid Data", err);
return false;
}
try {
for(key in obj.settings) {
var val = obj.settings[key];
if(settingsCookie.hasOwnProperty(key)) {
settingsCookie[key] = val;
var cb = $("#" + key);
cb.prop("checked", val);
settingsPanel.updateSettings();
}
}
window.bdStorage.set("bdcustomcss", obj.customCss);
var ccss = window.bdStorage.get("bdcustomcss");
if (!customCssInitialized) {
customCssEditor.init();
customCssInitialized = true;
}
customCssEditor.applyCustomCss(ccss, settingsCookie["bda-css-0"], false);
customCssEditor.editor.setValue(ccss);
}catch(err) {
mainCore.alert("Invalid Data", err);
return false;
}
try {
$.each(obj.plugins, function(plugin) {
var enabled = obj.plugins[plugin];
if(bdplugins.hasOwnProperty(plugin)) {
pluginCookie[plugin] = enabled;
var cb = $("#"+plugin.replace(" ", "__"));
if(cb.is(":checked") && !enabled) {
bdplugins[plugin]["plugin"].stop();
cb.prop("checked", false);
}
if(!cb.is(":checked") && enabled) {
bdplugins[plugin]["plugin"].start();
cb.prop("checked", true);
}
}
});
pluginModule.savePluginData();
}catch(err) {
mainCore.alert("Failed to load plugin data", err);
return false;
}
try {
themeCookie = obj.themes;
$.each(themeCookie, function(theme) {
var enabled = themeCookie[theme];
var id = "#ti" + theme;
if(bdthemes.hasOwnProperty(theme)) {
if($(id).is(":checked") && !enabled) {
$(id).prop("checked", false);
$("#"+theme).remove();
}
if(!$(id).is(":checked") && enabled) {
$(id).prop("checked", true);
$("head").append('<style id="' + theme + '">' + unescape(bdthemes[theme]["css"]) + '</style>');
}
}
});
themeModule.saveThemeData();
}catch(err) {
mainCore.alert("Failed to load theme data", err);
return false;
}
return false;
});
};
Utils.prototype.exportSettings = function() {
var obj = {
settings: settingsCookie,
customCss: window.bdStorage.get("bdcustomcss"),
plugins: pluginCookie,
themes: themeCookie,
favEmotes: window.bdStorage.get("bdfavemotes")
};
mainCore.alert("Export Settings", '<div class="form" style="width:100%;"><div class="control-group"><textarea style="min-height:150px;">'+JSON.stringify(obj)+'</textarea></div></div>');
};
Utils.prototype.addBackdrop = function(target) {
var backDrop = $("<div/>", {
class: "bda-backdrop",
"data-bdbackdrop": target,
mouseup: function() {
$('[data-bdalert="'+target+'"]').remove();
$(this).remove();
}
});
$("#app-mount").append(backDrop)
};
Utils.prototype.removeBackdrop = function(target) {
$('[data-bdbackdrop="'+target+'"]').remove();
};
/* BetterDiscordApp VoiceMode JavaScript
* Version: 1.0
* Author: Jiiks | http://jiiks.net