This commit is contained in:
Mirco Wittrien 2021-01-10 11:41:01 +01:00
parent 71873ffe21
commit ed78d18f07
7 changed files with 71 additions and 107 deletions

View File

@ -50,7 +50,8 @@ module.exports = (_ => {
defaults: {
settings: {
showToasts: {value: true, disableIfNative: true, noteIfNative: true},
showSupportBadges: {value: true, disableIfNative: false, noteIfNative: true}
showSupportBadges: {value: true, disableIfNative: false, noteIfNative: true},
useChromium: {value: false, disableIfNative: false, noteIfNative: true}
}
},
});
@ -547,11 +548,11 @@ module.exports = (_ => {
BDFDB.PluginUtils.cleanUp = function (plugin) {
BDFDB.TimeUtils.suppress(_ => {
if (!BDFDB.ObjectUtils.is(plugin)) return;
if (plugin == BDFDB) {
if (plugin == window.BDFDB_Global) {
delete window.BDFDB_Global.loaded;
BDFDB.TimeUtils.interval((interval, count) => {
if (count > 60 || window.BDFDB_Global.loaded) BDFDB.TimeUtils.clear(interval);
if (window.BDFDB_Global.loaded) for (let pluginName in BDFDB_Global.ObjectUtils.sort(PluginStores.loaded)) BDFDB.TimeUtils.timeout(_ => {
if (window.BDFDB_Global.loaded) for (let pluginName in BDFDB.ObjectUtils.sort(PluginStores.loaded)) BDFDB.TimeUtils.timeout(_ => {
if (PluginStores.loaded[pluginName].started) BDFDB.BDUtils.reloadPlugin(pluginName);
});
}, 1000);
@ -2951,9 +2952,9 @@ module.exports = (_ => {
if (key === undefined) return config;
else {
let keydata = configIsObject ? (BDFDB.ObjectUtils.is(config[key]) || config[key] == undefined ? BDFDB.ObjectUtils.deepAssign({}, config[key]) : config[key]) : null;
if (id === undefined) return keydata;
else return !BDFDB.ObjectUtils.is(keydata) || keydata[id] === undefined ? null : keydata[id];
let keyData = configIsObject ? (BDFDB.ObjectUtils.is(config[key]) || config[key] === undefined ? BDFDB.ObjectUtils.deepAssign({}, config[key]) : config[key]) : null;
if (id === undefined) return keyData;
else return !BDFDB.ObjectUtils.is(keyData) || keyData[id] === undefined ? null : keyData[id];
}
};
BDFDB.DataUtils.remove = function (plugin, key, id) {
@ -4011,16 +4012,15 @@ module.exports = (_ => {
for (let i = 0; i < tempArray.length; i++) tempArray[i] = 0;
newV = tempArray.concat(newV);
}
let oldvValue = 0, newValue = 0;
for (let i in oldV.reverse()) oldvValue += (oldV[i] * (10 ** i));
let oldValue = 0, newValue = 0;
for (let i in oldV.reverse()) oldValue += (oldV[i] * (10 ** i));
for (let i in newV.reverse()) newValue += (newV[i] * (10 ** i));
return (newValue - oldvValue) / (10 ** (length-1));
return (newValue - oldValue) / (10 ** (length-1));
};
BDFDB.DiscordUtils = {};
BDFDB.DiscordUtils.openLink = function (url, inbuilt, minimized) {
if (!inbuilt) window.open(url, "_blank");
else {
BDFDB.DiscordUtils.openLink = function (url, options = {}) {
if (options.inBuilt || options.inBuilt === undefined && settings.useChromium) {
let browserWindow = new LibraryRequires.electron.remote.BrowserWindow({
frame: true,
resizeable: true,
@ -4033,8 +4033,9 @@ module.exports = (_ => {
});
browserWindow.setMenu(null);
browserWindow.loadURL(url);
if (minimized) browserWindow.minimize(null);
if (options.minimized) browserWindow.minimize(null);
}
else window.open(url, "_blank");
};
BDFDB.DiscordUtils.getFolder = function () {
var built = BDFDB.DiscordUtils.getBuilt();
@ -5000,7 +5001,7 @@ module.exports = (_ => {
InternalComponents.LibraryComponents.CollapseContainer = reactInitialized && class BDFDB_CollapseContainer extends LibraryModules.React.Component {
render() {
if (!BDFDB.ObjectUtils.is(this.props.collapseStates)) this.props.collapseStates = {};
this.props.collapsed = this.props.collapsed && (this.props.collapseStates[this.props.title] || this.props.collapseStates[this.props.title] == undefined);
this.props.collapsed = this.props.collapsed && (this.props.collapseStates[this.props.title] || this.props.collapseStates[this.props.title] === undefined);
this.props.collapseStates[this.props.title] = this.props.collapsed;
return BDFDB.ReactUtils.createElement("div", {
className: BDFDB.DOMUtils.formatClassName(this.props.collapsed && BDFDB.disCN.collapsecontainercollapsed, this.props.mini ? BDFDB.disCN.collapsecontainermini : BDFDB.disCN.collapsecontainer, this.props.className),
@ -7841,6 +7842,7 @@ module.exports = (_ => {
const languages = BDFDB.ArrayUtils.removeCopies(BDFDB.ArrayUtils.is(config.languages) ? config.languages : ["en"].concat(Object.keys(BDFDB.ObjectUtils.filter(BDFDB.LanguageUtils.languages, n => n.discord))).filter(n => !n.startsWith("en-") && !n.startsWith("$") && n != language)).sort();
let translations = {};
strings = BDFDB.ObjectUtils.sort(strings);
const stringKeys = Object.keys(strings);
translations[language] = BDFDB.ObjectUtils.toArray(strings);
let text = Object.keys(translations[language]).map(k => translations[language][k]).join("\n\n");
@ -7893,10 +7895,14 @@ module.exports = (_ => {
};
let fails = 0, next = lang => {
if (!lang) {
let formatTranslation = (l, s, i) => {
l = l == "en" ? "default" : l;
return config.cached && config.cached[l] && config.cached[l][stringKeys[i]] || (translations[language][i][0] == translations[language][i][0].toUpperCase() ? BDFDB.LibraryModules.StringUtils.upperCaseFirstChar(s) : s);
};
let format = config.asObject ? ((l, isNotFirst) => {
return `${isNotFirst ? "," : ""}\n\t\t"${l == "en" ? "default" : l}": {${translations[l].map((s, i) => `\n\t\t\t"${Object.keys(strings)[i]}": "${translations[language][i][0] == translations[language][i][0].toUpperCase() ? BDFDB.LibraryModules.StringUtils.upperCaseFirstChar(s) : s}"`).join(",")}\n\t\t}`;
return `${isNotFirst ? "," : ""}\n\t\t"${l == "en" ? "default" : l}": {${translations[l].map((s, i) => `\n\t\t\t"${stringKeys[i]}": "${formatTranslation(l, s, i)}"`).join(",")}\n\t\t}`;
}) : ((l, isNotFirst) => {
return `\n\t\t\t\t\t${l == "en" ? "default" : `case "${l}"`}:${l.length > 2 ? "\t" : "\t\t"}// ${BDFDB.LanguageUtils.languages[l].name}\n\t\t\t\t\t\treturn {${translations[l].map((s, i) => `\n\t\t\t\t\t\t\t${Object.keys(strings)[i]}:${"\t".repeat(10 - ((Object.keys(strings)[i].length + 2) / 4))}"${translations[language][i][0] == translations[language][i][0].toUpperCase() ? BDFDB.LibraryModules.StringUtils.upperCaseFirstChar(s) : s}"`).join(",")}\n\t\t\t\t\t\t};`;
return `\n\t\t\t\t\t${l == "en" ? "default" : `case "${l}"`}:${l.length > 2 ? "\t" : "\t\t"}// ${BDFDB.LanguageUtils.languages[l].name}\n\t\t\t\t\t\treturn {${translations[l].map((s, i) => `\n\t\t\t\t\t\t\t${stringKeys[i]}:${"\t".repeat(10 - ((stringKeys[i].length + 2) / 4))}"${formatTranslation(l, s, i)}"`).join(",")}\n\t\t\t\t\t\t};`;
});
let result = Object.keys(translations).filter(n => n != "en").sort().map((l, i) => format(l, i)).join("");
if (translations.en) result += format("en", result ? 1 : 0);
@ -7927,14 +7933,6 @@ module.exports = (_ => {
window.BDFDB = BDFDB;
}
window.BDFDB_Global = Object.assign({
PluginUtils: {
buildPlugin: BDFDB.PluginUtils.buildPlugin,
cleanUp: BDFDB.PluginUtils.cleanUp
}
}, config);
Object.freeze(BDFDB);
for (let obj in DiscordObjects) if (!DiscordObjects[obj]) {
DiscordObjects[obj] = function () {};
BDFDB.DiscordObjects[obj] = function () {};
@ -7946,12 +7944,18 @@ module.exports = (_ => {
}
if (css) BDFDB.DOMUtils.appendLocalStyle("BDFDB", css.replace(/[\n\t\r]/g, "").replace(/\[REPLACE_CLASS_([A-z0-9_]+?)\]/g, function(a, b) {return BDFDB.dotCN[b];}));
window.BDFDB_Global.loaded = true;
delete window.BDFDB_Global.loading;
BDFDB.LogUtils.log("Finished loading library.");
window.BDFDB_Global = Object.assign({
started: true,
loaded: true,
PluginUtils: {
buildPlugin: BDFDB.PluginUtils.buildPlugin,
cleanUp: BDFDB.PluginUtils.cleanUp
}
}, config);
while (PluginStores.delayedLoad.length) PluginStores.delayedLoad.shift().load();
while (PluginStores.delayedStart.length) PluginStores.delayedStart.shift().start();
while (pluginQueue.length) {

View File

@ -64,14 +64,11 @@ module.exports = (_ => {
}
} : (([Plugin, BDFDB]) => {
const textUrlReplaceString = "DEVILBRO_BD_GOOGLESEARCHREPLACE_REPLACEURL";
var settings = {}, engines = {}, enabledEngines = {};
var engines = {}, enabledEngines = {};
return class GoogleSearchReplace extends Plugin {
onLoad () {
this.defaults = {
settings: {
useChromium: {value: false, description: "Use an inbuilt browser window instead of opening your default browser"},
},
engines: {
_all: {value: true, name: BDFDB.LanguageUtils.LanguageStrings.FORM_LABEL_ALL, url: null},
Ask: {value: true, name: "Ask", url: "https://ask.com/web?q=" + textUrlReplaceString},
@ -102,13 +99,6 @@ module.exports = (_ => {
getSettingsPanel (collapseStates = {}) {
let settingsPanel, settingsItems = [];
for (let key in settings) settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
type: "Switch",
plugin: this,
keys: ["settings", key],
label: this.defaults.settings[key].description,
value: settings[key]
}));
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsPanelList, {
title: "Search Engines:",
children: Object.keys(engines).filter(n => n && n != "_all").map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
@ -131,7 +121,6 @@ module.exports = (_ => {
}
forceUpdateAll () {
settings = BDFDB.DataUtils.get(this, "settings");
engines = BDFDB.DataUtils.get(this, "engines");
enabledEngines = BDFDB.ObjectUtils.filter(engines, n => n);
}
@ -157,7 +146,9 @@ module.exports = (_ => {
persisting: true,
action: event => {
if (!event.shiftKey) BDFDB.ContextMenuUtils.close(e.instance);
BDFDB.DiscordUtils.openLink(this.defaults.engines[engineKeys[0]].url.replace(textUrlReplaceString, encodeURIComponent(text)), !settings.useChromium, event.shiftKey);
BDFDB.DiscordUtils.openLink(this.defaults.engines[engineKeys[0]].url.replace(textUrlReplaceString, encodeURIComponent(text)), {
minimized: event.shiftKey
});
}
}));
}
@ -171,9 +162,13 @@ module.exports = (_ => {
action: event => {
if (!event.shiftKey) BDFDB.ContextMenuUtils.close(e.instance);
if (key == "_all") {
for (let key2 in enginesWithoutAll) BDFDB.DiscordUtils.openLink(this.defaults.engines[key2].url.replace(textUrlReplaceString, encodeURIComponent(text)), settings.useChromium, event.shiftKey);
for (let key2 in enginesWithoutAll) BDFDB.DiscordUtils.openLink(this.defaults.engines[key2].url.replace(textUrlReplaceString, encodeURIComponent(text)), {
minimized: event.shiftKey
});
}
else BDFDB.DiscordUtils.openLink(this.defaults.engines[key].url.replace(textUrlReplaceString, encodeURIComponent(text)), settings.useChromium, event.shiftKey);
else BDFDB.DiscordUtils.openLink(this.defaults.engines[key].url.replace(textUrlReplaceString, encodeURIComponent(text)), {
minimized: event.shiftKey
});
}
}));
if (!items.length) items.push(BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuItem, {

View File

@ -93,7 +93,6 @@ module.exports = (_ => {
this.defaults = {
settings: {
useChromium: {value: false, description: "Use an inbuilt browser window instead of opening your default browser"},
addTranslateButton: {value: true, description: "Add an translate button to the chatbar"},
sendOriginalMessage: {value: false, description: "Send the original message together with the translation"}
},
@ -255,7 +254,7 @@ module.exports = (_ => {
if (foundTranslation && foundInput && foundOutput) {
if (document.querySelector(".googletranslate-tooltip")) {
BDFDB.ContextMenuUtils.close(e.instance);
BDFDB.DiscordUtils.openLink(this.getGoogleTranslatePageURL(foundInput.id, foundOutput.id, text), settings.useChromium);
BDFDB.DiscordUtils.openLink(this.getGoogleTranslatePageURL(foundInput.id, foundOutput.id, text));
}
else createTooltip();
}

View File

@ -121,21 +121,20 @@ module.exports = (_ => {
this.defaults = {
settings: {
resizeImage: {value: true, inner: false, description: "Always resize image to fit the whole image modal"},
addDetails: {value: true, inner: false, description: "Add image details (name, size, amount) in the image modal"},
showAsHeader: {value: true, inner: false, description: "Show image details as a details header above the image in the chat"},
showOnHover: {value: false, inner: false, description: "Show image details as Tooltip in the chat"},
enableGallery: {value: true, inner: false, description: "Display previous/next Images in the same message in the image modal"},
enableZoom: {value: true, inner: false, description: "Create a zoom lens if you press down on an image in the image modal"},
enableCopyImg: {value: true, inner: false, description: "Add a copy image option in the image modal"},
enableSaveImg: {value: true, inner: false, description: "Add a save image as option in the image modal"},
useChromium: {value: false, inner: false, description: "Use an inbuilt browser window instead of opening your default browser"},
resizeImage: {value: true, inner: false, description: "Always resize Image to fit the whole Image Modal"},
addDetails: {value: true, inner: false, description: "Add Image Details (Name, Size, Amount) in the Image Modal"},
showAsHeader: {value: true, inner: false, description: "Show Image Details as a Details Header above the Image in the Chat"},
showOnHover: {value: false, inner: false, description: "Show Image Details as Tooltip in the Chat"},
enableGallery: {value: true, inner: false, description: "Display previous/next Images in the same message in the Image Modal"},
enableZoom: {value: true, inner: false, description: "Create a Zoom Lens if you press down on an Image in the Image Modal"},
enableCopyImg: {value: true, inner: false, description: "Add a copy Image option in the Image Modal"},
enableSaveImg: {value: true, inner: false, description: "Add a save Image as option in the Image Modal"},
addUserAvatarEntry: {value: true, inner: true, description: "User Avatars"},
addGuildIconEntry: {value: true, inner: true, description: "Server Icons"},
addEmojiEntry: {value: true, inner: true, description: "Custom Emojis/Emotes"}
},
amounts: {
hoverDelay: {value: 0, min: 0, description: "Image Tooltip delay (in millisec)"}
hoverDelay: {value: 0, min: 0, description: "Image Tooltip Delay (in ms)"}
},
zoomSettings: {
zoomlevel: {value: 2, digits: 1, minValue: 1, maxValue: 20, unit: "x", label: "ACCESSIBILITY_ZOOM_LEVEL_LABEL"},
@ -602,7 +601,9 @@ module.exports = (_ => {
persisting: true,
action: event => {
if (!event.shiftKey) BDFDB.ContextMenuUtils.close(e.instance);
BDFDB.DiscordUtils.openLink(this.defaults.engines[engineKeys[0]].url.replace(imgUrlReplaceString, encodeURIComponent(url)), settings.useChromium, event.shiftKey);
BDFDB.DiscordUtils.openLink(this.defaults.engines[engineKeys[0]].url.replace(imgUrlReplaceString, encodeURIComponent(url)), {
minimized: event.shiftKey
});
}
}) : BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuItem, {
label: this.labels.context_reverseimagesearch,
@ -619,9 +620,13 @@ module.exports = (_ => {
action: event => {
if (!event.shiftKey) BDFDB.ContextMenuUtils.close(e.instance);
if (key == "_all") {
for (let key2 in enginesWithoutAll) BDFDB.DiscordUtils.openLink(this.defaults.engines[key2].url.replace(imgUrlReplaceString, encodeURIComponent(url)), settings.useChromium, event.shiftKey);
for (let key2 in enginesWithoutAll) BDFDB.DiscordUtils.openLink(this.defaults.engines[key2].url.replace(imgUrlReplaceString, encodeURIComponent(url)), {
minimized: event.shiftKey
});
}
else BDFDB.DiscordUtils.openLink(this.defaults.engines[key].url.replace(imgUrlReplaceString, encodeURIComponent(url)), settings.useChromium, event.shiftKey);
else BDFDB.DiscordUtils.openLink(this.defaults.engines[key].url.replace(imgUrlReplaceString, encodeURIComponent(url)), {
minimized: event.shiftKey
});
}
}))
})
@ -1485,8 +1490,8 @@ module.exports = (_ => {
toast_copyimage_failed: "无法将图像复制到剪贴板",
toast_copyimage_success: "复制到剪贴板的图像",
toast_copyimagelink_success: "复制的图像链接到剪贴板",
toast_saveimage_failed: "无法将图片保存到“ {{path}}”中",
toast_saveimage_success: "已将图像保存在“ {{path}}”中"
toast_saveimage_failed: "无法将图片保存到'{{path}}'中",
toast_saveimage_success: "已将图像保存在'{{path}}'中"
};
case "zh-TW": // Chinese (Traditional)
return {
@ -1500,8 +1505,8 @@ module.exports = (_ => {
toast_copyimage_failed: "無法將圖像複製到剪貼板",
toast_copyimage_success: "複製到剪貼板的圖像",
toast_copyimagelink_success: "複製的圖像鏈接到剪貼板",
toast_saveimage_failed: "無法將圖片保存到“ {{path}}”中",
toast_saveimage_success: "已將圖像保存在“ {{path}}”中"
toast_saveimage_failed: "無法將圖片保存到'{{path}}'中",
toast_saveimage_success: "已將圖像保存在'{{path}}'中"
};
default: // English
return {

View File

@ -279,7 +279,7 @@ module.exports = (_ => {
else if (this.props.plugin.url.indexOf("https://gist.githubusercontent.com/") == 0) {
gitUrl = this.props.plugin.url.replace("//gist.githubusercontent", "//gist.github").split("/raw/")[0];
}
if (gitUrl) BDFDB.DiscordUtils.openLink(gitUrl, settings.useChromium);
if (gitUrl) BDFDB.DiscordUtils.openLink(gitUrl);
}
})
})
@ -303,7 +303,7 @@ module.exports = (_ => {
else if (this.props.plugin.url.indexOf("https://gist.githubusercontent.com/") == 0) {
gitUrl = this.props.plugin.url.replace("//gist.githubusercontent", "//gist.github").split("/raw/")[0];
}
if (gitUrl) BDFDB.DiscordUtils.openLink(gitUrl, settings.useChromium);
if (gitUrl) BDFDB.DiscordUtils.openLink(gitUrl);
}
}],
buttons: isBeta ? [
@ -494,7 +494,6 @@ module.exports = (_ => {
this.defaults = {
settings: {
useChromium: {value: false, description: "Use an inbuilt browser window instead of opening your default browser"},
notifyOutdated: {value: true, description: "Get a notification when one of your Plugins is outdated"},
notifyNewEntries: {value: true, description: "Get a notification when there are new entries in the Repo"}
},

View File

@ -58,57 +58,20 @@ module.exports = (_ => {
return template.content.firstElementChild;
}
} : (([Plugin, BDFDB]) => {
var settings = {};
var urls = {
const urls = {
steam: ["https://steamcommunity.", "https://help.steampowered.", "https://store.steampowered.", "a.akamaihd.net/"]
};
return class SteamProfileLink extends Plugin {
onLoad () {
this.defaults = {
settings: {
useChromium: {value: false, description: "Use inbuilt browser instead of default if fails to open Steam"}
}
};
}
onLoad () {}
onStart () {
for (let key in urls) BDFDB.ListenerUtils.add(this, document, "click", urls[key].map(url => url.indexOf("http") == 0 ? `a[href^="${url}"]` : `a[href*="${url}"][href*="${key}"]`).join(", "), e => {
this.openIn(e, key, e.currentTarget.href);
});
this.forceUpdateAll();
}
onStop () {}
getSettingsPanel (collapseStates = {}) {
let settingsPanel, settingsItems = [];
settingsItems = settingsItems.concat(this.createSelects(false));
for (let key in settings) settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
type: "Switch",
plugin: this,
keys: ["settings", key],
label: this.defaults.settings[key].description,
value: settings[key]
}));
return settingsPanel = BDFDB.PluginUtils.createSettingsPanel(this, settingsItems);
}
onSettingsClosed () {
if (this.SettingsUpdated) {
delete this.SettingsUpdated;
this.forceUpdateAll();
}
}
forceUpdateAll () {
settings = BDFDB.DataUtils.get(this, "settings");
}
openIn (e, key, url) {
let platform = BDFDB.LibraryModules.StringUtils.upperCaseFirstChar(key);
@ -123,7 +86,7 @@ module.exports = (_ => {
openInSteam (url) {
BDFDB.LibraryRequires.request(url, (error, response, body) => {
if (BDFDB.LibraryRequires.electron.shell.openExternal("steam://openurl/" + response.request.href));
else BDFDB.DiscordUtils.openLink(response.request.href, settings.useChromium);
else BDFDB.DiscordUtils.openLink(response.request.href);
});
}
};

View File

@ -548,7 +548,7 @@ module.exports = (_ => {
else if (this.props.theme.url.indexOf("https://gist.githubusercontent.com/") == 0) {
gitUrl = this.props.theme.url.replace("//gist.githubusercontent", "//gist.github").split("/raw/")[0];
}
if (gitUrl) BDFDB.DiscordUtils.openLink(gitUrl, settings.useChromium);
if (gitUrl) BDFDB.DiscordUtils.openLink(gitUrl);
}
})
})
@ -595,7 +595,7 @@ module.exports = (_ => {
else if (this.props.theme.url.indexOf("https://gist.githubusercontent.com/") == 0) {
gitUrl = this.props.theme.url.replace("//gist.githubusercontent", "//gist.github").split("/raw/")[0];
}
if (gitUrl) BDFDB.DiscordUtils.openLink(gitUrl, settings.useChromium);
if (gitUrl) BDFDB.DiscordUtils.openLink(gitUrl);
}
}],
buttons: isBeta ? [
@ -786,7 +786,6 @@ module.exports = (_ => {
this.defaults = {
settings: {
useChromium: {value: false, description: "Use an inbuilt browser window instead of opening your default browser"},
keepOnTop: {value: false, description: "Keep the preview window always on top"},
notifyOutdated: {value: true, description: "Get a notification when one of your Themes is outdated"},
notifyNewentries: {value: true, description: "Get a notification when there are new entries in the Repo"}