This commit is contained in:
Mirco Wittrien 2021-01-29 20:57:25 +01:00
parent ab1a05b144
commit 1618979620
6 changed files with 113 additions and 114 deletions

View File

@ -7173,6 +7173,7 @@ module.exports = (_ => {
onColorChange: color => { onColorChange: color => {
this.handleChange(!color ? "" : (this.props.mode == "comp" ? BDFDB.ColorUtils.convert(color, "RGBCOMP").slice(0, 3).join(",") : (this.props.noAlpha ? BDFDB.ColorUtils.convert(color, "RGB") : color))); this.handleChange(!color ? "" : (this.props.mode == "comp" ? BDFDB.ColorUtils.convert(color, "RGBCOMP").slice(0, 3).join(",") : (this.props.noAlpha ? BDFDB.ColorUtils.convert(color, "RGB") : color)));
}, },
ref: this.props.controlsRef,
pickerConfig: {gradient: false, alpha: this.props.mode != "comp" && !this.props.noAlpha} pickerConfig: {gradient: false, alpha: this.props.mode != "comp" && !this.props.noAlpha}
}) })
}) : null, }) : null,
@ -7180,7 +7181,8 @@ module.exports = (_ => {
filter: this.props.filter, filter: this.props.filter,
mode: this.props.mode, mode: this.props.mode,
useFilePath: this.props.useFilePath, useFilePath: this.props.useFilePath,
searchFolders: this.props.searchFolders searchFolders: this.props.searchFolders,
ref: this.props.controlsRef
}) : null }) : null
].flat(10).filter(n => n); ].flat(10).filter(n => n);
@ -7216,7 +7218,10 @@ module.exports = (_ => {
}) : null, }) : null,
inputChildren.length == 1 ? inputChildren[0] : BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.Flex, { inputChildren.length == 1 ? inputChildren[0] : BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.Flex, {
align: InternalComponents.LibraryComponents.Flex.Align.CENTER, align: InternalComponents.LibraryComponents.Flex.Align.CENTER,
children: inputChildren.map((child, i) => i != 0 ? BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.Flex.Child, {shrink: 0, children: child}) : child) children: inputChildren.map((child, i) => i != 0 ? BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.Flex.Child, {
shrink: 0,
children: child
}) : child)
}), }),
this.props.errorMessage ? BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.TextElement, { this.props.errorMessage ? BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.TextElement, {
className: BDFDB.disCN.carderror, className: BDFDB.disCN.carderror,

View File

@ -18,8 +18,8 @@ module.exports = (_ => {
"description": "Allow the user to configure their own chat-aliases which will automatically be replaced before the message is being sent" "description": "Allow the user to configure their own chat-aliases which will automatically be replaced before the message is being sent"
}, },
"changeLog": { "changeLog": {
"fixed": { "improved": {
"New Aliases": "You can add new Aliases again" "Canary Changes": "Preparing Plugins for the changes that are already done on Discord Canary"
} }
} }
}; };
@ -267,11 +267,11 @@ module.exports = (_ => {
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, { BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, {
type: "Button", type: "Button",
label: "Pick a Word Value and Replacement Value:", label: "Pick a Word Value and Replacement Value:",
key: "ADDBUTTON", disabled: !Object.keys(values).every(valueName => values[valueName]),
disabled: !Object.keys(values).every(valuename => values[valuename]),
children: BDFDB.LanguageUtils.LanguageStrings.ADD, children: BDFDB.LanguageUtils.LanguageStrings.ADD,
ref: instance => {if (instance) values.addButton = instance;},
onClick: _ => { onClick: _ => {
this.saveWord(values.wordValue, values.replaceValue, settingsPanel.props._node.querySelector(".input-replacevalue input[type='file']")); this.saveWord(values);
BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates); BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates);
} }
}), }),
@ -502,36 +502,30 @@ module.exports = (_ => {
} }
openAddModal (wordValue) { openAddModal (wordValue) {
let values = { let values = {wordValue, replaceValue: ""};
wordValue, let configs = BDFDB.ObjectUtils.map(BDFDB.ObjectUtils.filter(this.defaults.configs, key => key != "file", true), n => n.value);
replaceValue: ""
};
BDFDB.ModalUtils.open(this, { BDFDB.ModalUtils.open(this, {
size: "MEDIUM", size: "MEDIUM",
header: BDFDB.LanguageUtils.LibraryStringsFormat("add_to", "ChatAliases"), header: BDFDB.LanguageUtils.LibraryStringsFormat("add_to", "ChatAliases"),
subHeader: "", subHeader: "",
children: [ children: [
this.createInputs(values), this.createInputs(values),
BDFDB.ArrayUtils.remove(Object.keys(this.defaults.configs), "file").map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, { Object.keys(configs).map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, {
type: "Switch", type: "Switch",
className: "input-config" + key,
label: this.defaults.configs[key].description, label: this.defaults.configs[key].description,
value: this.defaults.configs[key].value value: configs[key],
onChange: value => {configs[key] = value;}
})) }))
].flat(10).filter(n => n), ].flat(10).filter(n => n),
buttons: [{ buttons: [{
key: "ADDBUTTON", disabled: !Object.keys(values).every(valueName => values[valueName]),
disabled: !Object.keys(values).every(valuename => values[valuename]),
contents: BDFDB.LanguageUtils.LanguageStrings.ADD, contents: BDFDB.LanguageUtils.LanguageStrings.ADD,
color: "BRAND", color: "BRAND",
close: true, close: true,
onClick: modal => { ref: instance => {if (instance) values.addButton = instance;},
let configs = {}; onClick: _ => {
for (let key in this.defaults.configs) { this.saveWord(values, configs);
let configInput = modal.querySelector(`.input-config${key} ${BDFDB.dotCN.switchinner}`);
if (configInput) configs[key] = configInput.checked;
}
this.saveWord(values.wordValue, values.replaceValue, modal.querySelector(".input-replacevalue input[type='file']"), configs);
this.forceUpdateAll(); this.forceUpdateAll();
} }
}] }]
@ -552,11 +546,8 @@ module.exports = (_ => {
if (!values.wordValue) instance.props.errorMessage = "Choose a Word Value"; if (!values.wordValue) instance.props.errorMessage = "Choose a Word Value";
else if (aliases[values.wordValue]) instance.props.errorMessage = "Word Value already used, saving will overwrite old Alias"; else if (aliases[values.wordValue]) instance.props.errorMessage = "Word Value already used, saving will overwrite old Alias";
else delete instance.props.errorMessage; else delete instance.props.errorMessage;
let addButtonIns = BDFDB.ReactUtils.findOwner(BDFDB.ReactUtils.findOwner(instance, {name: ["BDFDB_Modal", "BDFDB_SettingsPanel"], up: true}), {key: "ADDBUTTON"}); values.addButton.props.disabled = !Object.keys(values).every(valueName => values[valueName]);
if (addButtonIns) { BDFDB.ReactUtils.forceUpdate(values.addButton);
addButtonIns.props.disabled = !Object.keys(values).every(valuename => values[valuename]);
BDFDB.ReactUtils.forceUpdate(addButtonIns);
}
} }
}) })
}), }),
@ -564,44 +555,40 @@ module.exports = (_ => {
title: "With:", title: "With:",
className: BDFDB.disCN.marginbottom8, className: BDFDB.disCN.marginbottom8,
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextInput, { children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextInput, {
className: "input-replacevalue",
type: "file", type: "file",
useFilePath: true, useFilePath: true,
value: values.replaceValue, value: values.replaceValue,
placeholder: values.replaceValue, placeholder: values.replaceValue,
autoFocus: true, autoFocus: true,
errorMessage: !values.replaceValue && "Choose a Replacement Value", errorMessage: !values.replaceValue && "Choose a Replacement Value",
controlsRef: instance => {if (instance) values.fileSelection = instance;},
onChange: (value, instance) => { onChange: (value, instance) => {
values.replaceValue = value.trim(); values.replaceValue = value.trim();
if (!values.replaceValue) instance.props.errorMessage = "Choose a Replacement Value"; if (!values.replaceValue) instance.props.errorMessage = "Choose a Replacement Value";
else delete instance.props.errorMessage; else delete instance.props.errorMessage;
let addButtonIns = BDFDB.ReactUtils.findOwner(BDFDB.ReactUtils.findOwner(instance, {name: ["BDFDB_Modal", "BDFDB_SettingsPanel"], up: true}), {key: "ADDBUTTON"}); values.addButton.props.disabled = !Object.keys(values).every(valueName => values[valueName]);
if (addButtonIns) { BDFDB.ReactUtils.forceUpdate(values.addButton);
addButtonIns.props.disabled = !Object.keys(values).every(valuename => values[valuename]);
BDFDB.ReactUtils.forceUpdate(addButtonIns);
}
} }
}) })
}) })
]; ];
} }
saveWord (wordValue, replaceValue, fileSelection, aliasConfigs = configs) { saveWord (values, aliasConfigs = configs) {
console.log(wordValue, replaceValue, fileSelection); if (!values.wordValue || !values.replaceValue || !values.fileSelection) return;
if (!wordValue || !replaceValue || !fileSelection) return;
let filedata = null; let filedata = null;
if (fileSelection.files && fileSelection.files[0] && BDFDB.LibraryRequires.fs.existsSync(replaceValue)) { if (values.fileSelection.files && values.fileSelection.files[0] && BDFDB.LibraryRequires.fs.existsSync(values.replaceValue)) {
filedata = JSON.stringify({ filedata = JSON.stringify({
data: BDFDB.LibraryRequires.fs.readFileSync(replaceValue).toString("base64"), data: BDFDB.LibraryRequires.fs.readFileSync(values.replaceValue).toString("base64"),
name: fileSelection.files[0].name, name: values.fileSelection.files[0].name,
type: fileSelection.files[0].type type: values.fileSelection.files[0].type
}); });
} }
aliases[wordValue] = { aliases[values.wordValue] = {
replace: replaceValue, replace: values.replaceValue,
filedata: filedata, filedata: filedata,
case: aliasConfigs.case, case: aliasConfigs.case,
exact: wordValue.indexOf(" ") > -1 ? false : aliasConfigs.exact, exact: values.wordValue.indexOf(" ") > -1 ? false : aliasConfigs.exact,
autoc: aliasConfigs.regex ? false : aliasConfigs.autoc, autoc: aliasConfigs.regex ? false : aliasConfigs.autoc,
regex: aliasConfigs.regex, regex: aliasConfigs.regex,
file: filedata != null file: filedata != null

View File

@ -14,12 +14,12 @@ module.exports = (_ => {
"info": { "info": {
"name": "ChatFilter", "name": "ChatFilter",
"author": "DevilBro", "author": "DevilBro",
"version": "3.4.8", "version": "3.4.9",
"description": "Allows the user to censor Words or block complete Messages/Statuses" "description": "Allows the user to censor Words or block complete Messages/Statuses"
}, },
"changeLog": { "changeLog": {
"improved": { "improved": {
"Status Option": "Plugin now also checks custom statuses, can be disabled" "Canary Changes": "Preparing Plugins for the changes that are already done on Discord Canary"
} }
} }
}; };
@ -155,9 +155,9 @@ module.exports = (_ => {
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, { BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, {
type: "Button", type: "Button",
label: "Pick a Word Value and Replacement Value:", label: "Pick a Word Value and Replacement Value:",
key: "ADDBUTTON",
disabled: !Object.keys(values).every(valuename => values[valuename]), disabled: !Object.keys(values).every(valuename => values[valuename]),
children: BDFDB.LanguageUtils.LanguageStrings.ADD, children: BDFDB.LanguageUtils.LanguageStrings.ADD,
ref: instance => {if (instance) values.addButton = instance;},
onClick: _ => { onClick: _ => {
this.saveWord(values); this.saveWord(values);
BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates); BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates);
@ -508,32 +508,29 @@ module.exports = (_ => {
openAddModal (wordValue) { openAddModal (wordValue) {
let values = {wordValue, replaceValue: "", choice: "blocked"}; let values = {wordValue, replaceValue: "", choice: "blocked"};
let configs = BDFDB.ObjectUtils.map(this.defaults.configs, n => n.value);
BDFDB.ModalUtils.open(this, { BDFDB.ModalUtils.open(this, {
size: "MEDIUM", size: "MEDIUM",
header: BDFDB.LanguageUtils.LibraryStringsFormat("add_to", "ChatFilter"), header: BDFDB.LanguageUtils.LibraryStringsFormat("add_to", "ChatFilter"),
subHeader: "", subHeader: "",
children: [ children: [
this.createInputs(values), this.createInputs(values),
BDFDB.ArrayUtils.remove(Object.keys(this.defaults.configs), "file").map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, { Object.keys(configs).map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, {
type: "Switch", type: "Switch",
className: "input-config" + key,
label: this.defaults.configs[key].description, label: this.defaults.configs[key].description,
value: this.defaults.configs[key].value value: configs[key],
onChange: value => {configs[key] = value;}
})) }))
].flat(10).filter(n => n), ].flat(10).filter(n => n),
buttons: [{ buttons: [{
key: "ADDBUTTON",
disabled: !values.wordValue, disabled: !values.wordValue,
contents: BDFDB.LanguageUtils.LanguageStrings.ADD, contents: BDFDB.LanguageUtils.LanguageStrings.ADD,
color: "BRAND", color: "BRAND",
close: true, close: true,
onClick: modal => { ref: instance => {if (instance) values.addButton = instance;},
let newConfigs = {}; onClick: _ => {
for (let key in this.defaults.configs) { this.saveWord(values, configs);
let configInput = modal.querySelector(`.input-config${key} ${BDFDB.dotCN.switchinner}`);
if (configInput) newConfigs[key] = configInput.checked;
}
this.saveWord(values, newConfigs);
this.forceUpdateAll(); this.forceUpdateAll();
} }
}] }]
@ -541,25 +538,23 @@ module.exports = (_ => {
} }
createInputs (values) { createInputs (values) {
let wordValueInput;
return [ return [
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormItem, { BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormItem, {
title: "Block/Censor:", title: "Block/Censor:",
className: BDFDB.disCN.marginbottom8, className: BDFDB.disCN.marginbottom8,
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextInput, { children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextInput, {
key: "WORDVALUE",
value: values.wordValue, value: values.wordValue,
placeholder: values.wordValue, placeholder: values.wordValue,
errorMessage: !values.wordValue && "Choose a Word Value" || words[values.choice][values.wordValue] && `Word Value already used, saving will overwrite old ${values.choice} Word`, errorMessage: !values.wordValue && "Choose a Word Value" || words[values.choice][values.wordValue] && `Word Value already used, saving will overwrite old ${values.choice} Word`,
ref: instance => {if (instance) wordValueInput = instance;},
onChange: (value, instance) => { onChange: (value, instance) => {
values.wordValue = value.trim(); values.wordValue = value.trim();
if (!values.wordValue) instance.props.errorMessage = "Choose a Word Value"; if (!values.wordValue) instance.props.errorMessage = "Choose a Word Value";
else if (words[values.choice][values.wordValue]) instance.props.errorMessage = `Word Value already used, saving will overwrite old ${values.choice} word`; else if (words[values.choice][values.wordValue]) instance.props.errorMessage = `Word Value already used, saving will overwrite old ${values.choice} word`;
else delete instance.props.errorMessage; else delete instance.props.errorMessage;
let addButtonIns = BDFDB.ReactUtils.findOwner(BDFDB.ReactUtils.findOwner(instance, {name: ["BDFDB_Modal", "BDFDB_SettingsPanel"], up: true}), {key: "ADDBUTTON"}); values.addButton.props.disabled = !values.wordValue;
if (addButtonIns) { BDFDB.ReactUtils.forceUpdate(values.addButton);
addButtonIns.props.disabled = !values.wordValue;
BDFDB.ReactUtils.forceUpdate(addButtonIns);
}
} }
}) })
}), }),
@ -570,24 +565,19 @@ module.exports = (_ => {
value: values.replaceValue, value: values.replaceValue,
placeholder: values.replaceValue, placeholder: values.replaceValue,
autoFocus: true, autoFocus: true,
onChange: (value, instance) => { onChange: value => {values.replaceValue = value;}
values.replaceValue = value.trim();
}
}) })
}), }),
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.RadioGroup, { BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.RadioGroup, {
className: BDFDB.disCN.marginbottom8, className: BDFDB.disCN.marginbottom8,
value: values.choice, value: values.choice,
options: [{value: "blocked", name: "Block"}, {value: "censored", name: "Censor"}], options: [{value: "blocked", name: "Block"}, {value: "censored", name: "Censor"}],
onChange: (value, instance) => { onChange: valueObj => {
values.choice = value.value; values.choice = valueObj.value;
let wordValueInputIns = BDFDB.ReactUtils.findOwner(BDFDB.ReactUtils.findOwner(instance, {name: ["BDFDB_Modal", "BDFDB_SettingsPanel"], up: true}), {key: "WORDVALUE"}); if (!values.wordValue) wordValueInput.props.errorMessage = "Choose a Word Value";
if (wordValueInputIns) { else if (words[values.choice][values.wordValue]) wordValueInput.props.errorMessage = `Word Value already used, saving will overwrite old ${values.choice} Word`;
if (!values.wordValue) wordValueInputIns.props.errorMessage = "Choose a Word Value"; else delete wordValueInput.props.errorMessage;
else if (words[values.choice][values.wordValue]) wordValueInputIns.props.errorMessage = `Word Value already used, saving will overwrite old ${values.choice} Word`; BDFDB.ReactUtils.forceUpdate(wordValueInput);
else delete wordValueInputIns.props.errorMessage;
BDFDB.ReactUtils.forceUpdate(wordValueInputIns);
}
} }
}) })
]; ];
@ -595,8 +585,6 @@ module.exports = (_ => {
saveWord (values, wordConfigs = configs) { saveWord (values, wordConfigs = configs) {
if (!values.wordValue || !values.choice) return; if (!values.wordValue || !values.choice) return;
values.wordValue = values.wordValue.trim();
values.replaceValue = values.replaceValue.trim();
if (!BDFDB.ObjectUtils.is(words[values.choice])) words[values.choice] = {}; if (!BDFDB.ObjectUtils.is(words[values.choice])) words[values.choice] = {};
words[values.choice][values.wordValue] = { words[values.choice][values.wordValue] = {
replace: values.replaceValue, replace: values.replaceValue,

View File

@ -631,7 +631,7 @@ module.exports = (_ => {
contents: BDFDB.LanguageUtils.LanguageStrings.CONNECT, contents: BDFDB.LanguageUtils.LanguageStrings.CONNECT,
color: "BRAND", color: "BRAND",
close: true, close: true,
onClick: modal => { onClick: _ => {
BDFDB.LibraryModules.UserSettingsUtils.open(BDFDB.DiscordConstants.UserSettingsSections.CONNECTIONS) BDFDB.LibraryModules.UserSettingsUtils.open(BDFDB.DiscordConstants.UserSettingsSections.CONNECTIONS)
} }
}] }]

View File

@ -14,12 +14,12 @@ module.exports = (_ => {
"info": { "info": {
"name": "ThemeSettings", "name": "ThemeSettings",
"author": "DevilBro", "author": "DevilBro",
"version": "1.3.0", "version": "1.3.1",
"description": "Allow you to change Theme Variables within BetterDiscord. Adds a Settings button (similar to Plugins) to customizable Themes in your Themes Page" "description": "Allow you to change Theme Variables within BetterDiscord. Adds a Settings button (similar to Plugins) to customizable Themes in your Themes Page"
}, },
"changeLog": { "changeLog": {
"added": { "improved": {
"Imports": "You can now enable/disable imports in the settings" "Canary Changes": "Preparing Plugins for the changes that are already done on Discord Canary"
} }
} }
}; };
@ -97,6 +97,7 @@ module.exports = (_ => {
let vars = this.getThemeVars(css); let vars = this.getThemeVars(css);
if (imports.length || vars.length) { if (imports.length || vars.length) {
let open = _ => { let open = _ => {
let refs = {imports: {}, inputs: {}};
BDFDB.ModalUtils.open(this, { BDFDB.ModalUtils.open(this, {
header: `${addon.name} ${BDFDB.LanguageUtils.LanguageStrings.SETTINGS}`, header: `${addon.name} ${BDFDB.LanguageUtils.LanguageStrings.SETTINGS}`,
subHeader: "", subHeader: "",
@ -105,18 +106,20 @@ module.exports = (_ => {
contentClassName: BDFDB.disCN._repomodalsettings, contentClassName: BDFDB.disCN._repomodalsettings,
footerClassName: BDFDB.disCN._repomodalfooter, footerClassName: BDFDB.disCN._repomodalfooter,
size: "MEDIUM", size: "MEDIUM",
children: this.createThemeInputs(addon, imports, vars), children: this.createThemeInputs(refs, addon, imports, vars),
buttons: [{contents: BDFDB.LanguageUtils.LanguageStrings.SAVE, color: "BRAND", onClick: modal => {this.updateTheme(modal, addon);}}] buttons: [{
contents: BDFDB.LanguageUtils.LanguageStrings.SAVE,
color: "BRAND",
onClick: _ => {this.updateTheme(refs, addon);}
}]
}); });
console.log(refs);
}; };
if (isBeta) { if (isBeta) {
let controls = card.querySelector("." + BDFDB.disCN._repofooter.split(" ")[0] + " " + BDFDB.dotCN._repocontrols); let controls = card.querySelector("." + BDFDB.disCN._repofooter.split(" ")[0] + " " + BDFDB.dotCN._repocontrols);
let settingsButton = document.createElement("button"); let settingsButton = document.createElement("button");
settingsButton.className = BDFDB.DOMUtils.formatClassName(BDFDB.disCN._repobutton, BDFDB.disCN._repocontrolsbutton, "theme-settings-button"); settingsButton.className = BDFDB.DOMUtils.formatClassName(BDFDB.disCN._repobutton, BDFDB.disCN._repocontrolsbutton, "theme-settings-button");
settingsButton.appendChild(BDFDB.DOMUtils.create(`<svg viewBox="0 0 20 20" style="width: 20px; height: 20px;"> settingsButton.appendChild(BDFDB.DOMUtils.create(`<svg viewBox="0 0 20 20" style="width: 20px; height: 20px;"><path fill="none" d="M0 0h20v20H0V0z"></path><path d="M15.95 10.78c.03-.25.05-.51.05-.78s-.02-.53-.06-.78l1.69-1.32c.15-.12.19-.34.1-.51l-1.6-2.77c-.1-.18-.31-.24-.49-.18l-1.99.8c-.42-.32-.86-.58-1.35-.78L12 2.34c-.03-.2-.2-.34-.4-.34H8.4c-.2 0-.36.14-.39.34l-.3 2.12c-.49.2-.94.47-1.35.78l-1.99-.8c-.18-.07-.39 0-.49.18l-1.6 2.77c-.1.18-.06.39.1.51l1.69 1.32c-.04.25-.07.52-.07.78s.02.53.06.78L2.37 12.1c-.15.12-.19.34-.1.51l1.6 2.77c.1.18.31.24.49.18l1.99-.8c.42.32.86.58 1.35.78l.3 2.12c.04.2.2.34.4.34h3.2c.2 0 .37-.14.39-.34l.3-2.12c.49-.2.94-.47 1.35-.78l1.99.8c.18.07.39 0 .49-.18l1.6-2.77c.1-.18.06-.39-.1-.51l-1.67-1.32zM10 13c-1.65 0-3-1.35-3-3s1.35-3 3-3 3 1.35 3 3-1.35 3-3 3z"></path></svg>`));
<path fill="none" d="M0 0h20v20H0V0z"></path>
<path d="M15.95 10.78c.03-.25.05-.51.05-.78s-.02-.53-.06-.78l1.69-1.32c.15-.12.19-.34.1-.51l-1.6-2.77c-.1-.18-.31-.24-.49-.18l-1.99.8c-.42-.32-.86-.58-1.35-.78L12 2.34c-.03-.2-.2-.34-.4-.34H8.4c-.2 0-.36.14-.39.34l-.3 2.12c-.49.2-.94.47-1.35.78l-1.99-.8c-.18-.07-.39 0-.49.18l-1.6 2.77c-.1.18-.06.39.1.51l1.69 1.32c-.04.25-.07.52-.07.78s.02.53.06.78L2.37 12.1c-.15.12-.19.34-.1.51l1.6 2.77c.1.18.31.24.49.18l1.99-.8c.42.32.86.58 1.35.78l.3 2.12c.04.2.2.34.4.34h3.2c.2 0 .37-.14.39-.34l.3-2.12c.49-.2.94-.47 1.35-.78l1.99.8c.18.07.39 0 .49-.18l1.6-2.77c.1-.18.06-.39-.1-.51l-1.67-1.32zM10 13c-1.65 0-3-1.35-3-3s1.35-3 3-3 3 1.35 3 3-1.35 3-3 3z"></path>
</svg>`));
controls.insertBefore(settingsButton, controls.firstElementChild); controls.insertBefore(settingsButton, controls.firstElementChild);
settingsButton.addEventListener("click", open); settingsButton.addEventListener("click", open);
settingsButton.addEventListener("mouseenter", _ => { settingsButton.addEventListener("mouseenter", _ => {
@ -143,40 +146,45 @@ module.exports = (_ => {
} }
} }
updateTheme (card, addon) { updateTheme (refs, addon) {
let path = BDFDB.LibraryRequires.path.join(dir, addon.filename); let path = BDFDB.LibraryRequires.path.join(dir, addon.filename);
let css = BDFDB.LibraryRequires.fs.readFileSync(path).toString(); let css = BDFDB.LibraryRequires.fs.readFileSync(path).toString();
if (css) { if (css) {
let amount = 0; let amount = 0;
for (let input of card.querySelectorAll(BDFDB.dotCN.switchinner)) { for (let i in refs.imports) {
let oldValue = input.getAttribute("oldvalue"); let input = refs.imports[i];
let newValue = input.checked; let oldValue = input.props.oldValue;
let newValue = input.props.value;
console.log(oldValue, newValue);
if (newValue.toString() != oldValue.toString()) { if (newValue.toString() != oldValue.toString()) {
let importUrl = input.getAttribute("name"); let importUrl = input.props.name;
if (newValue) css = css.replace(new RegExp(`\\n${BDFDB.StringUtils.regEscape("/* @import url(" + importUrl + "); */")}`, "g"), `\n@import url(${importUrl});`); if (newValue) css = css.replace(new RegExp(`\\n${BDFDB.StringUtils.regEscape("/* @import url(" + importUrl + "); */")}`, "g"), `\n@import url(${importUrl});`);
else css = css.replace(new RegExp(`\\n${BDFDB.StringUtils.regEscape("@import url(" + importUrl + ");")}`, "g"), `\n/* @import url(${importUrl}); */`); else css = css.replace(new RegExp(`\\n${BDFDB.StringUtils.regEscape("@import url(" + importUrl + ");")}`, "g"), `\n/* @import url(${importUrl}); */`);
input.setAttribute("oldvalue", newValue); input.props.oldValue = newValue;
amount++; amount++;
} }
} }
for (let input of card.querySelectorAll(BDFDB.dotCN.input)) { for (let i in refs.inputs) {
let oldValue = input.getAttribute("oldvalue"); let input = refs.inputs[i];
let newValue = input.value; let oldValue = input.props.oldValue;
let newValue = input.props.value;
console.log(oldValue, newValue);
if (newValue && newValue.trim() && newValue != oldValue) { if (newValue && newValue.trim() && newValue != oldValue) {
let varName = input.getAttribute("name"); let varName = input.props.name;
css = css.replace(new RegExp(`--${BDFDB.StringUtils.regEscape(varName)}(\\s*):(\\s*)${BDFDB.StringUtils.regEscape(oldValue)}`,"g"), `--${varName}$1: $2${newValue}`); css = css.replace(new RegExp(`--${BDFDB.StringUtils.regEscape(varName)}(\\s*):(\\s*)${BDFDB.StringUtils.regEscape(oldValue)}`,"g"), `--${varName}$1: $2${newValue}`);
input.setAttribute("oldvalue", newValue); input.props.oldValue = newValue;
input.setAttribute("placeholder", newValue); input.props.placeholder = newValue;
amount++; amount++;
} }
} }
if (amount > 0) { if (amount > 0) {
BDFDB.ReactUtils.forceUpdate(BDFDB.ObjectUtils.toArray(refs.imports), BDFDB.ObjectUtils.toArray(refs.inputs));
BDFDB.LibraryRequires.fs.writeFileSync(path, css); BDFDB.LibraryRequires.fs.writeFileSync(path, css);
BDFDB.NotificationUtils.toast(`Updated ${amount} variable${amount == 1 ? "" : "s"} in ${addon.filename}`, {type: "success"}); BDFDB.NotificationUtils.toast(`Updated ${amount} Variable${amount == 1 ? "" : "s"} in '${addon.filename}'`, {type: "success"});
} }
else BDFDB.NotificationUtils.toast(`There are no changed variables to be updated in ${addon.filename}`, {type: "warning"}); else BDFDB.NotificationUtils.toast(`There are no changed Variables to be updated in '${addon.filename}'`, {type: "warning"});
} }
else BDFDB.NotificationUtils.toast(`Could not find themefile: ${addon.filename}`, {type: "danger"}); else BDFDB.NotificationUtils.toast(`Could not find Theme File '${addon.filename}'`, {type: "danger"});
} }
getThemeImports (css) { getThemeImports (css) {
@ -196,27 +204,30 @@ module.exports = (_ => {
return []; return [];
} }
createThemeInputs (theme, imports, vars) { createThemeInputs (refs, theme, imports, vars) {
let settingsItems = []; let settingsItems = [];
if (imports.length) settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsPanelList, { if (imports.length) settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsPanelList, {
title: "Imports:", title: "Imports:",
dividerBottom: vars.length, dividerBottom: vars.length,
children: imports.map(impo => { children: imports.map((impo, i) => {
let name = impo[0].split("/").pop().replace(/"/g, ""); let name = impo[0].split("/").pop().replace(/"/g, "");
return BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, { return BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, {
type: "Switch", type: "Switch",
margin: 8, margin: 8,
childProps: {
ref: instance => {if (instance) refs.imports[i] = instance;}
},
label: name[0].toUpperCase() + name.slice(1), label: name[0].toUpperCase() + name.slice(1),
note: impo[0].replace(/"/g, ""), note: impo[0].replace(/"/g, ""),
name: impo[0], name: impo[0],
value: impo[1], value: impo[1],
oldvalue: impo[1].toString() oldValue: impo[1].toString()
}); });
}) })
})); }));
let varInputs = []; let varInputs = [];
for (let varStr of vars) { for (let i in vars) {
varStr = varStr.split(":"); let varStr = vars[i].split(":");
let varName = varStr.shift().trim(); let varName = varStr.shift().trim();
varStr = varStr.join(":").split(/;[^A-z0-9]|\/\*/); varStr = varStr.join(":").split(/;[^A-z0-9]|\/\*/);
let varValue = varStr.shift().trim(); let varValue = varStr.shift().trim();
@ -243,14 +254,15 @@ module.exports = (_ => {
childProps: { childProps: {
type: childType, type: childType,
mode: childMode, mode: childMode,
filter: childType == "file" && "image" filter: childType == "file" && "image",
ref: instance => {if (instance) refs.inputs[i] = instance;}
}, },
label: varName[0].toUpperCase() + varName.slice(1), label: varName[0].toUpperCase() + varName.slice(1),
note: varDescription && varDescription.indexOf("*") == 0 ? varDescription.slice(1) : varDescription, note: varDescription && varDescription.indexOf("*") == 0 ? varDescription.slice(1) : varDescription,
basis: "70%", basis: "70%",
name: varName, name: varName,
value: varValue, value: varValue,
oldvalue: varValue, oldValue: varValue,
placeholder: varValue placeholder: varValue
})); }));
} }

View File

@ -14,8 +14,13 @@ module.exports = (_ => {
"info": { "info": {
"name": "UserNotes", "name": "UserNotes",
"author": "DevilBro", "author": "DevilBro",
"version": "1.0.5", "version": "1.0.6",
"description": "Allow you to write your own user notes wihtout a character limit" "description": "Allow you to write your own user notes wihtout a character limit"
},
"changeLog": {
"improved": {
"Canary Changes": "Preparing Plugins for the changes that are already done on Discord Canary"
}
} }
}; };
@ -107,6 +112,7 @@ module.exports = (_ => {
openNotesModal (user) { openNotesModal (user) {
let note = BDFDB.DataUtils.load(this, "notes", user.id); let note = BDFDB.DataUtils.load(this, "notes", user.id);
let textarea;
BDFDB.ModalUtils.open(this, { BDFDB.ModalUtils.open(this, {
size: "LARGE", size: "LARGE",
@ -117,15 +123,16 @@ module.exports = (_ => {
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextArea, { BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextArea, {
value: note, value: note,
placeholder: note, placeholder: note,
autoFocus: true autoFocus: true,
ref: instance => {if (instance) textarea = instance;}
}) })
], ],
buttons: [{ buttons: [{
contents: BDFDB.LanguageUtils.LanguageStrings.SAVE, contents: BDFDB.LanguageUtils.LanguageStrings.SAVE,
color: "BRAND", color: "BRAND",
close: true, close: true,
onClick: modal => { onClick: _ => {
note = modal.querySelector("textarea").value; note = textarea.props.value;
if (note) BDFDB.DataUtils.save(note, this, "notes", user.id); if (note) BDFDB.DataUtils.save(note, this, "notes", user.id);
else BDFDB.DataUtils.remove(this, "notes", user.id); else BDFDB.DataUtils.remove(this, "notes", user.id);
} }