This commit is contained in:
Mirco Wittrien 2019-10-30 13:27:14 +01:00
parent 7b6cfa7eb1
commit 037d97e5cd
18 changed files with 32 additions and 29 deletions

View File

@ -228,7 +228,7 @@ var BDFDB = {myPlugins: BDFDB && BDFDB.myPlugins || {}, cleanUps: BDFDB && BDFDB
} }
} }
changeLogHTML += `</div>` changeLogHTML += `</div>`
if (logs) BDFDB.openModal(plugin, {header:BDFDB.LanguageUtils.LanguageStrings.CHANGE_LOG, children:BDFDB.ReactUtils.elementToReact(BDFDB.DOMUtils.create(changeLogHTML)), selector:"BDFDB-changelogmodal"}); if (logs) BDBDFDB.ModalUtils.open(plugin, {header:BDFDB.LanguageUtils.LanguageStrings.CHANGE_LOG, children:BDFDB.ReactUtils.elementToReact(BDFDB.DOMUtils.create(changeLogHTML)), selector:"BDFDB-changelogmodal"});
}; };
BDFDB.PluginUtils.createSettingsPanel = function (plugin, children) { BDFDB.PluginUtils.createSettingsPanel = function (plugin, children) {
if (!BDFDB.ObjectUtils.is(plugin) || !children || (!BDFDB.ReactUtils.isValidElement(children) && !BDFDB.ArrayUtils.is(children)) || (BDFDB.ArrayUtils.is(children) && !children.length)) return; if (!BDFDB.ObjectUtils.is(plugin) || !children || (!BDFDB.ReactUtils.isValidElement(children) && !BDFDB.ArrayUtils.is(children)) || (BDFDB.ArrayUtils.is(children) && !children.length)) return;
@ -3316,8 +3316,9 @@ var BDFDB = {myPlugins: BDFDB && BDFDB.myPlugins || {}, cleanUps: BDFDB && BDFDB
return selectMenu; return selectMenu;
}; };
BDFDB.openModal = function (plugin, config) { BDFDB.ModalUtils.open = {};
BDFDB.ModalUtils.open = function (plugin, config) {
if (!BDFDB.ObjectUtils.is(plugin) || !BDFDB.ObjectUtils.is(config)) return; if (!BDFDB.ObjectUtils.is(plugin) || !BDFDB.ObjectUtils.is(config)) return;
var modal, headerchildren = [], contentchildren = [], footerchildren = [], modalprops, cancels = [], closeModal = _ => { var modal, headerchildren = [], contentchildren = [], footerchildren = [], modalprops, cancels = [], closeModal = _ => {
if (BDFDB.ObjectUtils.is(modalprops) && typeof modalprops.onClose == "function") modalprops.onClose(); if (BDFDB.ObjectUtils.is(modalprops) && typeof modalprops.onClose == "function") modalprops.onClose();
@ -3463,11 +3464,10 @@ var BDFDB = {myPlugins: BDFDB && BDFDB.myPlugins || {}, cleanUps: BDFDB && BDFDB
}); });
} }
}; };
BDFDB.ModalUtils.confirm = function (plugin, text, callback) {
BDFDB.openConfirmModal = function (plugin, text, callback) {
if (!BDFDB.ObjectUtils.is(plugin) || typeof text != "string") return; if (!BDFDB.ObjectUtils.is(plugin) || typeof text != "string") return;
callback = typeof callback == "function" ? callback : _ => {}; callback = typeof callback == "function" ? callback : _ => {};
BDFDB.openModal(plugin, {text, header:"Are you sure?", selector:"BDFDB-confirmmodal", buttons:[ BDFDB.ModalUtils.open(plugin, {text, header:"Are you sure?", selector:"BDFDB-confirmmodal", buttons:[
{contents: BDFDB.LanguageUtils.LanguageStrings.OKAY, close:true, color:"RED", click:callback}, {contents: BDFDB.LanguageUtils.LanguageStrings.OKAY, close:true, color:"RED", click:callback},
{contents: BDFDB.LanguageUtils.LanguageStrings.CANCEL, close:true} {contents: BDFDB.LanguageUtils.LanguageStrings.CANCEL, close:true}
]}); ]});
@ -7976,6 +7976,9 @@ var BDFDB = {myPlugins: BDFDB && BDFDB.myPlugins || {}, cleanUps: BDFDB && BDFDB
BDFDB.getDiscordZoomFactor = BDFDB.DiscordUtils.getZoomFactor; BDFDB.getDiscordZoomFactor = BDFDB.DiscordUtils.getZoomFactor;
BDFDB.getDiscordFontScale = BDFDB.DiscordUtils.getFontScale; BDFDB.getDiscordFontScale = BDFDB.DiscordUtils.getFontScale;
BDFDB.openModal = BDFDB.ModalUtils.open;
BDFDB.openConfirmModal = BDFDB.ModalUtils.confirm;
BDFDB.BdUtils = BDFDB.BDUtils; BDFDB.BdUtils = BDFDB.BDUtils;
BDFDB.getPluginsFolder = BDFDB.BDUtils.getPluginsFolder; BDFDB.getPluginsFolder = BDFDB.BDUtils.getPluginsFolder;
BDFDB.getThemesFolder = BDFDB.BDUtils.getThemesFolder; BDFDB.getThemesFolder = BDFDB.BDUtils.getThemesFolder;

File diff suppressed because one or more lines are too long

View File

@ -221,7 +221,7 @@ class ChatAliases {
} }
} }
else if (action == "removeall") { else if (action == "removeall") {
BDFDB.openConfirmModal(this, "Are you sure you want to remove all added Words from your list?", () => { BDFDB.ModalUtils.confirm(this, "Are you sure you want to remove all added Words from your list?", () => {
this.aliases = {}; this.aliases = {};
update(); update();
}); });

View File

@ -235,7 +235,7 @@ class ChatFilter {
} }
} }
else if (action == "removeall") { else if (action == "removeall") {
BDFDB.openConfirmModal(this, "Are you sure you want to remove all added Words from your list?", () => { BDFDB.ModalUtils.confirm(this, "Are you sure you want to remove all added Words from your list?", () => {
this.words[rtype] = {}; this.words[rtype] = {};
update(); update();
}); });

View File

@ -73,7 +73,7 @@ class EditChannels {
color: BDFDB.LibraryComponents.Button.Colors.RED, color: BDFDB.LibraryComponents.Button.Colors.RED,
label: "Reset all Channels", label: "Reset all Channels",
onClick: _ => { onClick: _ => {
BDFDB.openConfirmModal(this, "Are you sure you want to reset all channels?", () => { BDFDB.ModalUtils.confirm(this, "Are you sure you want to reset all channels?", () => {
BDFDB.DataUtils.remove(this, "channels"); BDFDB.DataUtils.remove(this, "channels");
this.forceUpdateAll(); this.forceUpdateAll();
}); });
@ -184,7 +184,7 @@ class EditChannels {
showChannelSettings (info) { showChannelSettings (info) {
var data = BDFDB.DataUtils.load(this, "channels", info.id) || {}; var data = BDFDB.DataUtils.load(this, "channels", info.id) || {};
BDFDB.openModal(this, { BDFDB.ModalUtils.open(this, {
size: "MEDIUM", size: "MEDIUM",
header: this.labels.modal_header_text, header: this.labels.modal_header_text,
subheader: info.name, subheader: info.name,

View File

@ -56,7 +56,7 @@ class EditServers {
color: BDFDB.LibraryComponents.Button.Colors.RED, color: BDFDB.LibraryComponents.Button.Colors.RED,
label: "Reset all Servers", label: "Reset all Servers",
onClick: _ => { onClick: _ => {
BDFDB.openConfirmModal(this, "Are you sure you want to reset all servers?", () => { BDFDB.ModalUtils.confirm(this, "Are you sure you want to reset all servers?", () => {
BDFDB.DataUtils.remove(this, "servers"); BDFDB.DataUtils.remove(this, "servers");
this.forceUpdateAll(); this.forceUpdateAll();
}); });
@ -224,7 +224,7 @@ class EditServers {
showServerSettings (info) { showServerSettings (info) {
var data = BDFDB.DataUtils.load(this, "servers", info.id) || {}; var data = BDFDB.DataUtils.load(this, "servers", info.id) || {};
BDFDB.openModal(this, { BDFDB.ModalUtils.open(this, {
size: "MEDIUM", size: "MEDIUM",
header: this.labels.modal_header_text, header: this.labels.modal_header_text,
subheader: info.name, subheader: info.name,

View File

@ -119,7 +119,7 @@ class EditUsers {
color: BDFDB.LibraryComponents.Button.Colors.RED, color: BDFDB.LibraryComponents.Button.Colors.RED,
label: "Reset all Users", label: "Reset all Users",
onClick: _ => { onClick: _ => {
BDFDB.openConfirmModal(this, "Are you sure you want to reset all users?", () => { BDFDB.ModalUtils.confirm(this, "Are you sure you want to reset all users?", () => {
BDFDB.DataUtils.remove(this, "users"); BDFDB.DataUtils.remove(this, "users");
this.forceUpdateAll(); this.forceUpdateAll();
}); });
@ -232,7 +232,7 @@ class EditUsers {
let data = BDFDB.DataUtils.load(this, "users", info.id) || {}; let data = BDFDB.DataUtils.load(this, "users", info.id) || {};
let member = BDFDB.LibraryModules.MemberStore.getMember(BDFDB.LibraryModules.LastGuildStore.getGuildId(), info.id) || {}; let member = BDFDB.LibraryModules.MemberStore.getMember(BDFDB.LibraryModules.LastGuildStore.getGuildId(), info.id) || {};
BDFDB.openModal(this, { BDFDB.ModalUtils.open(this, {
size: "MEDIUM", size: "MEDIUM",
header: this.labels.modal_header_text, header: this.labels.modal_header_text,
subheader: member.nick || info.username, subheader: member.nick || info.username,

View File

@ -179,7 +179,7 @@ class MessageUtilities {
} }
resetAll (settingspanel) { resetAll (settingspanel) {
BDFDB.openConfirmModal(this, "Are you sure you want to delete all key bindings?", () => { BDFDB.ModalUtils.confirm(this, "Are you sure you want to delete all key bindings?", () => {
BDFDB.DataUtils.remove(this, "bindings"); BDFDB.DataUtils.remove(this, "bindings");
let bindings = BDFDB.DataUtils.get(this, "bindings"); let bindings = BDFDB.DataUtils.get(this, "bindings");
settingspanel.querySelectorAll(BDFDB.dotCN.select).forEach(wrap => { settingspanel.querySelectorAll(BDFDB.dotCN.select).forEach(wrap => {

View File

@ -147,7 +147,7 @@ class NotificationSounds {
BDFDB.ListenerUtils.add(this, settingspanel, "click", ".btn-addsong", e => {this.saveAudio(settingspanel);}); BDFDB.ListenerUtils.add(this, settingspanel, "click", ".btn-addsong", e => {this.saveAudio(settingspanel);});
BDFDB.ListenerUtils.add(this, settingspanel, "keyup", ".songInput", e => {if (e.which == 13) this.saveAudio(settingspanel);}); BDFDB.ListenerUtils.add(this, settingspanel, "keyup", ".songInput", e => {if (e.which == 13) this.saveAudio(settingspanel);});
BDFDB.ListenerUtils.add(this, settingspanel, "click", ".reset-button", () => { BDFDB.ListenerUtils.add(this, settingspanel, "click", ".reset-button", () => {
BDFDB.openConfirmModal(this, "Are you sure you want to delete all added songs?", () => { BDFDB.ModalUtils.confirm(this, "Are you sure you want to delete all added songs?", () => {
BDFDB.DataUtils.remove(this, "choices"); BDFDB.DataUtils.remove(this, "choices");
BDFDB.DataUtils.remove(this, "audios"); BDFDB.DataUtils.remove(this, "audios");
this.loadAudios(); this.loadAudios();

View File

@ -141,7 +141,7 @@ class PersonalPins {
BDFDB.initElements(settingspanel, this); BDFDB.initElements(settingspanel, this);
settingspanel.querySelector(".reset-button").addEventListener("click", () => { settingspanel.querySelector(".reset-button").addEventListener("click", () => {
BDFDB.openConfirmModal(this, "Are you sure you want to delete all pinned notes?", () => { BDFDB.ModalUtils.confirm(this, "Are you sure you want to delete all pinned notes?", () => {
BDFDB.DataUtils.remove(this, "pins"); BDFDB.DataUtils.remove(this, "pins");
}); });
}); });

View File

@ -123,7 +123,7 @@ class PinDMs {
BDFDB.initElements(settingspanel, this); BDFDB.initElements(settingspanel, this);
BDFDB.ListenerUtils.add(this, settingspanel, "click", ".reset-button", () => { BDFDB.ListenerUtils.add(this, settingspanel, "click", ".reset-button", () => {
BDFDB.openConfirmModal(this, "Are you sure you want to unpin all pinned DMs?", () => { BDFDB.ModalUtils.confirm(this, "Are you sure you want to unpin all pinned DMs?", () => {
BDFDB.DataUtils.remove(this, "pinnedDMs"); BDFDB.DataUtils.remove(this, "pinnedDMs");
BDFDB.DataUtils.remove(this, "pinnedRecents"); BDFDB.DataUtils.remove(this, "pinnedRecents");
}); });

View File

@ -391,7 +391,7 @@ class PluginRepo {
} }
removeAllFromOwnList (settingspanel) { removeAllFromOwnList (settingspanel) {
BDFDB.openConfirmModal(this, "Are you sure you want to remove all added Plugins from your own list?", () => { BDFDB.ModalUtils.confirm(this, "Are you sure you want to remove all added Plugins from your own list?", () => {
BDFDB.DataUtils.save([], this, "ownlist", "ownlist"); BDFDB.DataUtils.save([], this, "ownlist", "ownlist");
BDFDB.DOMUtils.remove(settingspanel.querySelector(BDFDB.dotCN.hovercard)); BDFDB.DOMUtils.remove(settingspanel.querySelector(BDFDB.dotCN.hovercard));
}); });

View File

@ -261,7 +261,7 @@ class RepoControls {
}); });
}; };
if (!BDFDB.DataUtils.get(this, "settings", "confirmDelete")) deleteFile(); if (!BDFDB.DataUtils.get(this, "settings", "confirmDelete")) deleteFile();
else BDFDB.openConfirmModal(this, `Are you sure you want to delete the ${type} "${name}"?`, () => { else BDFDB.ModalUtils.confirm(this, `Are you sure you want to delete the ${type} "${name}"?`, () => {
deleteFile(); deleteFile();
}); });
}); });
@ -389,7 +389,7 @@ class RepoControls {
} }
toggleAll (type, container, enable) { toggleAll (type, container, enable) {
BDFDB.openConfirmModal(this, `Are you sure you want to ${enable ? "enable" : "disable"} all ${type[0].toUpperCase() + type.slice(1)}s?`, () => { BDFDB.ModalUtils.confirm(this, `Are you sure you want to ${enable ? "enable" : "disable"} all ${type[0].toUpperCase() + type.slice(1)}s?`, () => {
for (let header of container.querySelectorAll(BDFDB.dotCN._repoheader)) { for (let header of container.querySelectorAll(BDFDB.dotCN._repoheader)) {
if (header.querySelector(BDFDB.dotCN._reponame).textContent.toLowerCase().indexOf(this.name.toLowerCase()) != 0) { if (header.querySelector(BDFDB.dotCN._reponame).textContent.toLowerCase().indexOf(this.name.toLowerCase()) != 0) {
let switchwrap = header.querySelector(BDFDB.dotCN._repocheckboxwrap); let switchwrap = header.querySelector(BDFDB.dotCN._repocheckboxwrap);

View File

@ -183,7 +183,7 @@ class ServerFolders {
BDFDB.initElements(settingspanel, this); BDFDB.initElements(settingspanel, this);
BDFDB.ListenerUtils.add(this, settingspanel, "click", ".removecustom-button", () => { BDFDB.ListenerUtils.add(this, settingspanel, "click", ".removecustom-button", () => {
BDFDB.openConfirmModal(this, "Are you sure you want to remove all custom icons?", () => { BDFDB.ModalUtils.confirm(this, "Are you sure you want to remove all custom icons?", () => {
BDFDB.DataUtils.remove(this, "customicons"); BDFDB.DataUtils.remove(this, "customicons");
}); });
}); });
@ -229,7 +229,7 @@ class ServerFolders {
foldersdata = BDFDB.ObjectUtils.sort(BDFDB.DataUtils.load(this, "folders"), "position"); foldersdata = BDFDB.ObjectUtils.sort(BDFDB.DataUtils.load(this, "folders"), "position");
} }
let oldfolders = Object.keys(foldersdata).filter(n => n.indexOf("folder") == 0); let oldfolders = Object.keys(foldersdata).filter(n => n.indexOf("folder") == 0);
if (oldfolders.length) BDFDB.openConfirmModal(this, `Old ServerFolders data detected!\nFound ${oldfolders.length} old custom folders in the ServerFolders.config.json.\nPress the '${BDFDB.LanguageUtils.LanguageStrings.OKAY}' button to automatically create a native folder for each old folder and to automatically put the servers in them.`, "Convert?", () => { if (oldfolders.length) BDFDB.ModalUtils.confirm(this, `Old ServerFolders data detected!\nFound ${oldfolders.length} old custom folders in the ServerFolders.config.json.\nPress the '${BDFDB.LanguageUtils.LanguageStrings.OKAY}' button to automatically create a native folder for each old folder and to automatically put the servers in them.`, "Convert?", () => {
let oldGuildFolders = Object.assign({}, BDFDB.LibraryModules.FolderStore.guildFolders); let oldGuildFolders = Object.assign({}, BDFDB.LibraryModules.FolderStore.guildFolders);
let guildsInFolders = []; let guildsInFolders = [];
let guildFolders = []; let guildFolders = [];
@ -351,7 +351,7 @@ class ServerFolders {
danger: true, danger: true,
action: e => { action: e => {
BDFDB.closeContextMenu(BDFDB.DOMUtils.getParent(BDFDB.dotCN.contextmenu, e.target)); BDFDB.closeContextMenu(BDFDB.DOMUtils.getParent(BDFDB.dotCN.contextmenu, e.target));
BDFDB.openConfirmModal(this, `Are you sure you want to remove the folder${folder.folderName ? (" '" + folder.folderName + '"') : ""}?`, () => {this.removeFolder(folderid);}); BDFDB.ModalUtils.confirm(this, `Are you sure you want to remove the folder${folder.folderName ? (" '" + folder.folderName + '"') : ""}?`, () => {this.removeFolder(folderid);});
} }
}) })
}); });

View File

@ -88,7 +88,7 @@ class ServerHider {
BDFDB.initElements(settingspanel, this); BDFDB.initElements(settingspanel, this);
BDFDB.ListenerUtils.add(this, settingspanel, "click", ".reset-button", () => { BDFDB.ListenerUtils.add(this, settingspanel, "click", ".reset-button", () => {
BDFDB.openConfirmModal(this, "Are you sure you want to reset all servers?", () => { BDFDB.ModalUtils.confirm(this, "Are you sure you want to reset all servers?", () => {
BDFDB.DataUtils.remove(this, "servers"); BDFDB.DataUtils.remove(this, "servers");
BDFDB.GuildUtils.getAll().forEach(info => {if (!info.div.getAttribute("folder")) BDFDB.DOMUtils.hide(info.div);}); BDFDB.GuildUtils.getAll().forEach(info => {if (!info.div.getAttribute("folder")) BDFDB.DOMUtils.hide(info.div);});
}); });

View File

@ -55,7 +55,7 @@ class StalkerNotifications {
if (this.started) return; if (this.started) return;
BDFDB.PluginUtils.init(this); BDFDB.PluginUtils.init(this);
BDFDB.openConfirmModal(this, "StalkerNotifications has been discontinued and was merged with FriendNotifications. To download FriendNotifications click the 'OK' button bellow. This will delete StalkerNotifications and download FriendNotifications.", "Update Notification", () => { BDFDB.ModalUtils.confirm(this, "StalkerNotifications has been discontinued and was merged with FriendNotifications. To download FriendNotifications click the 'OK' button bellow. This will delete StalkerNotifications and download FriendNotifications.", "Update Notification", () => {
require("request")("https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/FriendNotifications/FriendNotifications.plugin.js", (error, response, body) => { require("request")("https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/FriendNotifications/FriendNotifications.plugin.js", (error, response, body) => {
if (error) BDFDB.NotificationUtils.toast(`Unable to download FriendNotifications.plugin.js.`, {type:"error"}); if (error) BDFDB.NotificationUtils.toast(`Unable to download FriendNotifications.plugin.js.`, {type:"error"});
else { else {

View File

@ -451,7 +451,7 @@ class ThemeRepo {
} }
removeAllFromOwnList (settingspanel) { removeAllFromOwnList (settingspanel) {
BDFDB.openConfirmModal(this, "Are you sure you want to remove all added Themes from your own list?", () => { BDFDB.ModalUtils.confirm(this, "Are you sure you want to remove all added Themes from your own list?", () => {
BDFDB.DataUtils.save([], this, "ownlist", "ownlist"); BDFDB.DataUtils.save([], this, "ownlist", "ownlist");
BDFDB.DOMUtils.remove(settingspanel.querySelector(BDFDB.dotCN.hovercard)); BDFDB.DOMUtils.remove(settingspanel.querySelector(BDFDB.dotCN.hovercard));
}); });

View File

@ -75,7 +75,7 @@ class UserNotes {
BDFDB.initElements(settingspanel, this); BDFDB.initElements(settingspanel, this);
BDFDB.ListenerUtils.add(this, settingspanel, "click", ".remove-button", () => { BDFDB.ListenerUtils.add(this, settingspanel, "click", ".remove-button", () => {
BDFDB.openConfirmModal(this, "Are you sure you want to remove all usernotes?", () => { BDFDB.ModalUtils.confirm(this, "Are you sure you want to remove all usernotes?", () => {
BDFDB.DataUtils.remove(this, "notes"); BDFDB.DataUtils.remove(this, "notes");
}); });
}); });