From 0c66862c372e8454b4936429ac270b1a08e9dc20 Mon Sep 17 00:00:00 2001
From: Mirco Wittrien <23700969+mwittrien@users.noreply.github.com>
Date: Fri, 29 Apr 2022 14:52:56 +0200
Subject: [PATCH] stuff
---
Library/0BDFDB.plugin.js | 11 +++--
Plugins/PluginRepo/PluginRepo.plugin.js | 46 ++++++++++++-------
.../ReadAllNotificationsButton.plugin.js | 24 ++--------
Plugins/SpellCheck/SpellCheck.plugin.js | 24 ++--------
Plugins/ThemeRepo/ThemeRepo.plugin.js | 29 +++++++++---
Plugins/Translator/Translator.plugin.js | 23 ++++------
Themes/_res/SupporterBadge.css | 3 ++
Themes/_res/ThemeDevBadge.css | 3 ++
8 files changed, 82 insertions(+), 81 deletions(-)
diff --git a/Library/0BDFDB.plugin.js b/Library/0BDFDB.plugin.js
index 1d16be13c7..27ba0cc3eb 100644
--- a/Library/0BDFDB.plugin.js
+++ b/Library/0BDFDB.plugin.js
@@ -1648,11 +1648,13 @@ module.exports = (_ => {
}
else BDFDB.DOMUtils.addClass(data.toast, type);
+ let loadingInterval;
let disableInteractions = data.config.disableInteractions && typeof data.config.onClick != "function";
let timeout = typeof data.config.timeout == "number" && !disableInteractions ? data.config.timeout : 3000;
timeout = (timeout > 0 ? timeout : 600000) + 300;
+ if (data.config.ellipsis && typeof data.children == "string") loadingInterval = BDFDB.TimeUtils.interval(_ => data.toast.update(data.children.endsWith(".....") ? data.children.slice(0, -5) : data.children + "."), 500);
- let progressInterval, closeTimeout = BDFDB.TimeUtils.timeout(_ => data.toast.close(), timeout);
+ let closeTimeout = BDFDB.TimeUtils.timeout(_ => data.toast.close(), timeout);
data.toast.close = _ => {
BDFDB.TimeUtils.clear(closeTimeout);
if (document.contains(data.toast)) {
@@ -1660,6 +1662,7 @@ module.exports = (_ => {
data.toast.style.setProperty("pointer-events", "none", "important");
BDFDB.TimeUtils.timeout(_ => {
if (typeof data.config.onClose == "function") data.config.onClose();
+ BDFDB.TimeUtils.clear(loadingInterval);
BDFDB.ArrayUtils.remove(Toasts, id);
BDFDB.DOMUtils.removeLocalStyle("BDFDBcustomToast" + id);
data.toast.remove();
@@ -1710,7 +1713,7 @@ module.exports = (_ => {
componentDidMount() {
data.toast.update = newChildren => {
if (!newChildren) return;
- this.props.children = newChildren;
+ data.children = newChildren;
BDFDB.ReactUtils.forceUpdate(this);
};
}
@@ -1731,7 +1734,7 @@ module.exports = (_ => {
}),
BDFDB.ReactUtils.createElement("div", {
className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN.toasttext, data.config.textClassName),
- children: this.props.children
+ children: data.children
}),
!disableInteractions && BDFDB.ReactUtils.createElement(Internal.LibraryComponents.SvgIcon, {
className: BDFDB.disCN.toastcloseicon,
@@ -1751,7 +1754,7 @@ module.exports = (_ => {
]
});
}
- }, {children: data.children}), data.toast);
+ }, {}), data.toast);
ToastQueues[position].full = (BDFDB.ArrayUtils.sum(Array.from(toasts.childNodes).map(c => {
let height = BDFDB.DOMUtils.getRects(c).height;
diff --git a/Plugins/PluginRepo/PluginRepo.plugin.js b/Plugins/PluginRepo/PluginRepo.plugin.js
index 0b2a6e8cce..83aeec2951 100644
--- a/Plugins/PluginRepo/PluginRepo.plugin.js
+++ b/Plugins/PluginRepo/PluginRepo.plugin.js
@@ -438,26 +438,40 @@ module.exports = (_ => {
installed: this.props.data.state == pluginStates.INSTALLED,
outdated: this.props.data.state == pluginStates.OUTDATED,
onDownload: _ => {
+ if (this.props.downloading) return;
+ this.props.downloading = true;
+ let loadingToast = BDFDB.NotificationUtils.toast(`${BDFDB.LanguageUtils.LibraryStringsFormat("loading", this.props.data.name)} - ${BDFDB.LanguageUtils.LibraryStrings.please_wait}`, {timeout: 0, ellipsis: true});
BDFDB.LibraryRequires.request(this.props.data.rawSourceUrl, (error, response, body) => {
- if (error) BDFDB.NotificationUtils.toast(BDFDB.LanguageUtils.LibraryStringsFormat("download_fail", `Plugin "${this.props.data.name}"`), {type: "danger"});
- else BDFDB.LibraryRequires.fs.writeFile(BDFDB.LibraryRequires.path.join(BDFDB.BDUtils.getPluginsFolder(), this.props.data.rawSourceUrl.split("/").pop()), body, error2 => {
- if (error2) BDFDB.NotificationUtils.toast(BDFDB.LanguageUtils.LibraryStringsFormat("save_fail", `Plugin "${this.props.data.name}"`), {type: "danger"});
- else {
- BDFDB.NotificationUtils.toast(BDFDB.LanguageUtils.LibraryStringsFormat("save_success", `Plugin "${this.props.data.name}"`), {type: "success"});
- if (_this.settings.general.rnmStart) BDFDB.TimeUtils.timeout(_ => {
- if (this.props.data.state == pluginStates.INSTALLED && BDFDB.BDUtils.isPluginEnabled(this.props.data.name) == false) {
- BDFDB.BDUtils.enablePlugin(this.props.data.name, false);
- BDFDB.LogUtils.log(BDFDB.LanguageUtils.LibraryStringsFormat("toast_plugin_started", this.props.data.name), _this);
- }
- }, 3000);
- this.props.data.state = pluginStates.INSTALLED;
- BDFDB.ReactUtils.forceUpdate(this);
- }
- })
- })
+ if (error) {
+ delete this.props.downloading;
+ loadingToast.close();
+ BDFDB.NotificationUtils.toast(BDFDB.LanguageUtils.LibraryStringsFormat("download_fail", `Plugin "${this.props.data.name}"`), {type: "danger"});
+ }
+ else {
+ BDFDB.LibraryRequires.fs.writeFile(BDFDB.LibraryRequires.path.join(BDFDB.BDUtils.getPluginsFolder(), this.props.data.rawSourceUrl.split("/").pop()), body, error2 => {
+ delete this.props.downloading;
+ loadingToast.close();
+ if (error2) BDFDB.NotificationUtils.toast(BDFDB.LanguageUtils.LibraryStringsFormat("save_fail", `Plugin "${this.props.data.name}"`), {type: "danger"});
+ else {
+ BDFDB.NotificationUtils.toast(BDFDB.LanguageUtils.LibraryStringsFormat("save_success", `Plugin "${this.props.data.name}"`), {type: "success"});
+ if (_this.settings.general.rnmStart) BDFDB.TimeUtils.timeout(_ => {
+ if (this.props.data.state == pluginStates.INSTALLED && BDFDB.BDUtils.isPluginEnabled(this.props.data.name) == false) {
+ BDFDB.BDUtils.enablePlugin(this.props.data.name, false);
+ BDFDB.LogUtils.log(BDFDB.LanguageUtils.LibraryStringsFormat("toast_plugin_started", this.props.data.name), _this);
+ }
+ }, 3000);
+ this.props.data.state = pluginStates.INSTALLED;
+ BDFDB.ReactUtils.forceUpdate(this);
+ }
+ });
+ }
+ });
},
onDelete: _ => {
+ if (this.props.deleting) return;
+ this.props.deleting = true;
BDFDB.LibraryRequires.fs.unlink(BDFDB.LibraryRequires.path.join(BDFDB.BDUtils.getPluginsFolder(), this.props.data.rawSourceUrl.split("/").pop()), error => {
+ delete this.props.deleting;
if (error) BDFDB.NotificationUtils.toast(BDFDB.LanguageUtils.LibraryStringsFormat("delete_fail", `Plugin "${this.props.data.name}"`), {type: "danger"});
else {
BDFDB.NotificationUtils.toast(BDFDB.LanguageUtils.LibraryStringsFormat("delete_success", `Plugin "${this.props.data.name}"`));
diff --git a/Plugins/ReadAllNotificationsButton/ReadAllNotificationsButton.plugin.js b/Plugins/ReadAllNotificationsButton/ReadAllNotificationsButton.plugin.js
index f6daf9391a..78d6005560 100644
--- a/Plugins/ReadAllNotificationsButton/ReadAllNotificationsButton.plugin.js
+++ b/Plugins/ReadAllNotificationsButton/ReadAllNotificationsButton.plugin.js
@@ -235,26 +235,20 @@ module.exports = (_ => {
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsGuildList, {
className: BDFDB.disCN.marginbottom20,
disabled: BDFDB.DataUtils.load(this, "blacklist"),
- onClick: disabledGuilds => {
- this.saveBlacklist(disabledGuilds);
- }
+ onClick: disabledGuilds => this.saveBlacklist(disabledGuilds)
}),
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, {
type: "Button",
color: BDFDB.LibraryComponents.Button.Colors.GREEN,
label: "Enable for all Servers",
- onClick: _ => {
- this.batchSetGuilds(settingsPanel, collapseStates, true);
- },
+ onClick: _ => this.batchSetGuilds(settingsPanel, collapseStates, true),
children: BDFDB.LanguageUtils.LanguageStrings.ENABLE
}),
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, {
type: "Button",
color: BDFDB.LibraryComponents.Button.Colors.PRIMARY,
label: "Disable for all Servers",
- onClick: _ => {
- this.batchSetGuilds(settingsPanel, collapseStates, false);
- },
+ onClick: _ => this.batchSetGuilds(settingsPanel, collapseStates, false),
children: BDFDB.LanguageUtils.LanguageStrings.DISABLE
})
]
@@ -303,17 +297,7 @@ module.exports = (_ => {
let messages = [].concat(mentionedMessages).filter(n => n);
if (messages.length) {
clearing = true;
- let toastInterval;
- let loadingString = `${this.labels.toast_clearing} - ${BDFDB.LanguageUtils.LibraryStrings.please_wait}`;
- let currentLoadingString = loadingString;
- let toast = BDFDB.NotificationUtils.toast(currentLoadingString, {
- timeout: 0,
- onClose: _ => {BDFDB.TimeUtils.clear(toastInterval);}
- });
- toastInterval = BDFDB.TimeUtils.interval(_ => {
- currentLoadingString = currentLoadingString.endsWith(".....") ? loadingString : currentLoadingString + ".";
- toast.update(currentLoadingString);
- }, 500);
+ let toast = BDFDB.NotificationUtils.toast(`${this.labels.toast_clearing} - ${BDFDB.LanguageUtils.LibraryStrings.please_wait}`, {timeout: 0, ellipsis: true});
for (let i = 0; i < messages.length; i++) BDFDB.TimeUtils.timeout(_ => {
BDFDB.LibraryModules.RecentMentionUtils.deleteRecentMention(messages[i].id);
if (i == messages.length - 1) {
diff --git a/Plugins/SpellCheck/SpellCheck.plugin.js b/Plugins/SpellCheck/SpellCheck.plugin.js
index 573c061d04..6bd34dee38 100644
--- a/Plugins/SpellCheck/SpellCheck.plugin.js
+++ b/Plugins/SpellCheck/SpellCheck.plugin.js
@@ -119,7 +119,7 @@ module.exports = (_ => {
BDFDB.DOMUtils.remove(BDFDB.dotCN._spellcheckoverlay);
- for (let key in languageToasts) this.killLanguageToast(key);
+ for (let key in languageToasts) languageToasts[key] && languageToasts[key].close();
}
getSettingsPanel (collapseStates = {}) {
@@ -334,26 +334,17 @@ module.exports = (_ => {
}
setDictionary (key, lang) {
- this.killLanguageToast(key);
+ languageToasts[key] && languageToasts[key].close();
if (languages[lang]) {
let ownDictionary = BDFDB.DataUtils.load(this, "owndics", lang) || [];
- let loadingString = `${this.labels.toast_dictionary.replace("{{var0}}", this.getLanguageName(languages[lang]))} - ${BDFDB.LanguageUtils.LibraryStrings.please_wait}`;
- let currentLoadingString = loadingString;
- languageToasts[key] = BDFDB.NotificationUtils.toast(loadingString, {
- timeout: 0,
- position: "center"
- });
- languageToasts[key].interval = BDFDB.TimeUtils.interval(_ => {
- currentLoadingString = currentLoadingString.endsWith(".....") ? loadingString : currentLoadingString + ".";
- languageToasts[key].update(currentLoadingString);
- }, 500);
+ languageToasts[key] = BDFDB.NotificationUtils.toast(`${this.labels.toast_dictionary.replace("{{var0}}", this.getLanguageName(languages[lang]))} - ${BDFDB.LanguageUtils.LibraryStrings.please_wait}`, {timeout: 0, ellipsis: true, position: "center"});
languageToasts[key].lang = lang
const folder = BDFDB.LibraryRequires.path.join(BDFDB.BDUtils.getPluginsFolder(), "dictionaries");
const filePath = BDFDB.LibraryRequires.path.join(folder, lang + ".dic");
const parse = (error, response, body, download) => {
- this.killLanguageToast(key);
+ languageToasts[key].close();
if (error || (response && body.toLowerCase().indexOf("") > -1)) {
BDFDB.NotificationUtils.toast(this.labels.toast_dictionary_fail.replace("{{var0}}", this.getLanguageName(languages[lang])), {
type: "danger",
@@ -398,13 +389,6 @@ module.exports = (_ => {
}, {});
}
- killLanguageToast (key) {
- if (languageToasts[key]) {
- BDFDB.TimeUtils.clear(languageToasts[key].interval);
- languageToasts[key].close();
- }
- }
-
isWordNotInDictionary (unformatedWord) {
let wordLow = unformatedWord.toLowerCase();
let wordWithoutSymbols = wordLow.replace(/[0-9\µ\@\$\£\€\¥\¢\²\³\>\<\|\,\;\.\:\-\_\#\+\*\~\?\¿\\\´\`\}\=\]\)\[\(\{\/\&\%\§\"\!\¡\^\°\n\t\r]/g, "");
diff --git a/Plugins/ThemeRepo/ThemeRepo.plugin.js b/Plugins/ThemeRepo/ThemeRepo.plugin.js
index 7d1a0fd5a9..aca1d81931 100644
--- a/Plugins/ThemeRepo/ThemeRepo.plugin.js
+++ b/Plugins/ThemeRepo/ThemeRepo.plugin.js
@@ -339,7 +339,10 @@ module.exports = (_ => {
}
createThemeFile(name, filename, body) {
return new Promise(callback => BDFDB.LibraryRequires.fs.writeFile(BDFDB.LibraryRequires.path.join(BDFDB.BDUtils.getThemesFolder(), filename), body, error => {
- if (error) BDFDB.NotificationUtils.toast(BDFDB.LanguageUtils.LibraryStringsFormat("save_fail", `Theme "${name}"`), {type: "danger"});
+ if (error) {
+ callback(true);
+ BDFDB.NotificationUtils.toast(BDFDB.LanguageUtils.LibraryStringsFormat("save_fail", `Theme "${name}"`), {type: "danger"});
+ }
else {
BDFDB.NotificationUtils.toast(BDFDB.LanguageUtils.LibraryStringsFormat("save_success", `Theme "${name}"`), {type: "success"});
if (_this.settings.general.rnmStart) BDFDB.TimeUtils.timeout(_ => {
@@ -869,16 +872,30 @@ module.exports = (_ => {
installed: this.props.data.state == themeStates.INSTALLED,
outdated: this.props.data.state == themeStates.OUTDATED,
onDownload: _ => {
- list && BDFDB.LibraryRequires.request(this.props.data.rawSourceUrl, (error, response, body) => {
- if (error) BDFDB.NotificationUtils.toast(BDFDB.LanguageUtils.LibraryStringsFormat("download_fail", `Theme "${this.props.data.name}"`), {type: "danger"});
- else list.createThemeFile(this.props.data.name, this.props.data.rawSourceUrl.split("/").pop(), body).then(_ => {
- this.props.data.state = themeStates.INSTALLED;
- BDFDB.ReactUtils.forceUpdate(this);
+ if (!list || this.props.downloading) return;
+ this.props.downloading = true;
+ let loadingToast = BDFDB.NotificationUtils.toast(`${BDFDB.LanguageUtils.LibraryStringsFormat("loading", this.props.data.name)} - ${BDFDB.LanguageUtils.LibraryStrings.please_wait}`, {timeout: 0, ellipsis: true});
+ BDFDB.LibraryRequires.request(this.props.data.rawSourceUrl, (error, response, body) => {
+ if (error) {
+ delete this.props.downloading;
+ loadingToast.close();
+ BDFDB.NotificationUtils.toast(BDFDB.LanguageUtils.LibraryStringsFormat("download_fail", `Theme "${this.props.data.name}"`), {type: "danger"});
+ }
+ else list.createThemeFile(this.props.data.name, this.props.data.rawSourceUrl.split("/").pop(), body).then(error2 => {
+ delete this.props.downloading;
+ loadingToast.close();
+ if (!error2) {
+ this.props.data.state = themeStates.INSTALLED;
+ BDFDB.ReactUtils.forceUpdate(this);
+ }
});
});
},
onDelete: _ => {
+ if (this.props.deleting) return;
+ this.props.deleting = true;
BDFDB.LibraryRequires.fs.unlink(BDFDB.LibraryRequires.path.join(BDFDB.BDUtils.getThemesFolder(), this.props.data.rawSourceUrl.split("/").pop()), error => {
+ delete this.props.deleting;
if (error) BDFDB.NotificationUtils.toast(BDFDB.LanguageUtils.LibraryStringsFormat("delete_fail", `Theme "${this.props.data.name}"`), {type: "danger"});
else {
BDFDB.NotificationUtils.toast(BDFDB.LanguageUtils.LibraryStringsFormat("delete_success", `Theme "${this.props.data.name}"`));
diff --git a/Plugins/Translator/Translator.plugin.js b/Plugins/Translator/Translator.plugin.js
index 4284b86d77..02b5466ef2 100644
--- a/Plugins/Translator/Translator.plugin.js
+++ b/Plugins/Translator/Translator.plugin.js
@@ -840,7 +840,6 @@ module.exports = (_ => {
let toast = null, toastInterval, finished = false, finishTranslation = translation => {
isTranslating = false;
if (toast) toast.close();
- BDFDB.TimeUtils.clear(toastInterval);
if (finished) return;
finished = true;
@@ -875,25 +874,19 @@ module.exports = (_ => {
if (toast) toast.close();
BDFDB.TimeUtils.clear(toastInterval);
- let loadingString = `${this.labels.toast_translating} (${translationEngines[engine].name}) - ${BDFDB.LanguageUtils.LibraryStrings.please_wait}`;
- let currentLoadingString = loadingString;
- toast = BDFDB.NotificationUtils.toast(loadingString, {
+ toast = BDFDB.NotificationUtils.toast(`${this.labels.toast_translating} (${translationEngines[engine].name}) - ${BDFDB.LanguageUtils.LibraryStrings.please_wait}`, {
timeout: 0,
+ ellipsis: true,
position: "center",
onClose: _ => BDFDB.TimeUtils.clear(toastInterval)
});
toastInterval = BDFDB.TimeUtils.interval((_, count) => {
- if (count > 40) {
- finishTranslation("");
- BDFDB.NotificationUtils.toast(`${this.labels.toast_translating_failed} (${translationEngines[engine].name}) - ${this.labels.toast_translating_tryanother}`, {
- type: "danger",
- position: "center"
- });
- }
- else {
- currentLoadingString = currentLoadingString.endsWith(".....") ? loadingString : currentLoadingString + ".";
- toast.update(currentLoadingString);
- }
+ if (count < 40) return;
+ finishTranslation("");
+ BDFDB.NotificationUtils.toast(`${this.labels.toast_translating_failed} (${translationEngines[engine].name}) - ${this.labels.toast_translating_tryanother}`, {
+ type: "danger",
+ position: "center"
+ });
}, 500);
};
if (this.validTranslator(this.settings.engines.translator, input, output, specialCase)) {
diff --git a/Themes/_res/SupporterBadge.css b/Themes/_res/SupporterBadge.css
index f92870cc99..c82ca66157 100644
--- a/Themes/_res/SupporterBadge.css
+++ b/Themes/_res/SupporterBadge.css
@@ -7,6 +7,9 @@
.supporter-Z3FfwL.hasBadge-4rT8_u .mask-1FEkla {
-webkit-mask: url('data:image/svg+xml; utf8, ') center/cover no-repeat;
}
+.avatar-2e8lTP.supporter-Z3FfwL.hasBadge-4rT8_u > img {
+ -webkit-mask: url('data:image/svg+xml; utf8, ') center/cover no-repeat;
+}
.supporter-Z3FfwL.hasBadge-4rT8_u ~ .avatarHint-k7pYop {
-webkit-mask: url('data:image/svg+xml; utf8, ') center/cover no-repeat;
}
diff --git a/Themes/_res/ThemeDevBadge.css b/Themes/_res/ThemeDevBadge.css
index 3b2452446f..cae92633c2 100644
--- a/Themes/_res/ThemeDevBadge.css
+++ b/Themes/_res/ThemeDevBadge.css
@@ -7,6 +7,9 @@
.dev-A7f2Rx.hasBadge-4rT8_u .mask-1FEkla {
-webkit-mask: url('data:image/svg+xml; utf8, ') center/cover no-repeat;
}
+.avatar-2e8lTP.dev-A7f2Rx.hasBadge-4rT8_u > img {
+ -webkit-mask: url('data:image/svg+xml; utf8, ') center/cover no-repeat;
+}
.dev-A7f2Rx.hasBadge-4rT8_u ~ .avatarHint-k7pYop {
-webkit-mask: url('data:image/svg+xml; utf8, ') center/cover no-repeat;
}