Revert "Update ChatFilter.plugin.js"

This reverts commit a374ecf763.
This commit is contained in:
Mirco Wittrien 2021-02-19 11:47:32 +01:00
parent a374ecf763
commit dc000da297
1 changed files with 122 additions and 131 deletions

View File

@ -14,15 +14,12 @@ module.exports = (_ => {
"info": { "info": {
"name": "ChatFilter", "name": "ChatFilter",
"author": "DevilBro", "author": "DevilBro",
"version": "3.5.1", "version": "3.5.0",
"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": {
"added": { "added": {
"Ignore own Messages/Status": "Added option to ignore your own Messages/Status" "Ignore own Messages/Status": "Added option to ignore your own Messages/Status"
},
"fixed": {
"Settings Update": "Fixed issue where the settings panel wouldn't show new words without having to close it first"
} }
} }
}; };
@ -130,137 +127,131 @@ module.exports = (_ => {
} }
getSettingsPanel (collapseStates = {}) { getSettingsPanel (collapseStates = {}) {
let settingsPanel; let settingsPanel, settingsItems = [];
return settingsPanel = BDFDB.PluginUtils.createSettingsPanel(this, {
collapseStates: collapseStates,
children: _ => {
let settingsItems = [];
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, { settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, {
title: "Settings", title: "Settings",
collapseStates: collapseStates, collapseStates: collapseStates,
children: Object.keys(settings).map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, { children: Object.keys(settings).map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
type: "Switch", type: "Switch",
plugin: this, plugin: this,
keys: ["settings", key], keys: ["settings", key],
label: this.defaults.settings[key].description, label: this.defaults.settings[key].description,
value: settings[key] value: settings[key]
})).concat(Object.keys(replaces).map(rType => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, { })).concat(Object.keys(replaces).map(rType => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
type: "TextInput", type: "TextInput",
plugin: this, plugin: this,
keys: ["replaces", rType], keys: ["replaces", rType],
label: this.defaults.replaces[rType].description, label: this.defaults.replaces[rType].description,
value: replaces[rType], value: replaces[rType],
placeholder: this.defaults.replaces[rType].value placeholder: this.defaults.replaces[rType].value
}))) })))
})); }));
let values = {wordValue: "", replaceValue: "", choice: "blocked"}; let values = {wordValue: "", replaceValue: "", choice: "blocked"};
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, { settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, {
title: `Add new blocked/censored word`, title: `Add new blocked/censored word`,
collapseStates: collapseStates, collapseStates: collapseStates,
children: [
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, {
type: "Button",
label: "Pick a Word Value and Replacement Value:",
disabled: !Object.keys(values).every(valuename => values[valuename]),
children: BDFDB.LanguageUtils.LanguageStrings.ADD,
ref: instance => {if (instance) values.addButton = instance;},
onClick: _ => {
this.saveWord(values);
BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates);
}
}),
this.createInputs(values)
].flat(10).filter(n => n)
}));
for (let rType in replaces) if (!BDFDB.ObjectUtils.isEmpty(words[rType])) settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, {
title: `Added ${rType} Words`,
collapseStates: collapseStates,
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsList, {
settings: Object.keys(this.defaults.configs).filter(n => !this.defaults.configs[n]["no" + BDFDB.LibraryModules.StringUtils.upperCaseFirstChar(rType)]),
data: Object.keys(words[rType]).map(wordValue => Object.assign({}, words[rType][wordValue], {
key: wordValue,
label: wordValue
})),
renderLabel: data => BDFDB.ReactUtils.createElement("div", {
style: {width: "100%"},
children: [ children: [
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, { BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextInput, {
type: "Button", value: data.label,
label: "Pick a Word Value and Replacement Value", placeholder: data.label,
disabled: !Object.keys(values).every(valuename => values[valuename]), size: BDFDB.LibraryComponents.TextInput.Sizes.MINI,
children: BDFDB.LanguageUtils.LanguageStrings.ADD, maxLength: 100000000000000000000,
ref: instance => {if (instance) values.addButton = instance;}, onChange: value => {
onClick: _ => { words[rType][value] = words[rType][data.label];
this.saveWord(values); delete words[rType][data.label];
BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates); data.label = value;
BDFDB.DataUtils.save(words, this, "words");
} }
}), }),
this.createInputs(values) BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextInput, {
].flat(10).filter(n => n) value: data.replace,
})); placeholder: data.replace,
for (let rType in replaces) if (!BDFDB.ObjectUtils.isEmpty(words[rType])) settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, { size: BDFDB.LibraryComponents.TextInput.Sizes.MINI,
title: `Added ${rType} Words`, maxLength: 100000000000000000000,
collapseStates: collapseStates, onChange: value => {
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsList, { words[rType][data.label].replace = value;
settings: Object.keys(this.defaults.configs).filter(n => !this.defaults.configs[n]["no" + BDFDB.LibraryModules.StringUtils.upperCaseFirstChar(rType)]), BDFDB.DataUtils.save(words, this, "words");
data: Object.keys(words[rType]).map(wordValue => Object.assign({}, words[rType][wordValue], { }
key: wordValue, })
label: wordValue ]
})), }),
renderLabel: data => BDFDB.ReactUtils.createElement("div", { onCheckboxChange: (value, instance) => {
style: {width: "100%"}, words[rType][instance.props.cardId][instance.props.settingId] = value;
children: [ BDFDB.DataUtils.save(words, this, "words");
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextInput, { },
value: data.label, onRemove: (e, instance) => {
placeholder: data.label, delete words[rType][instance.props.cardId];
size: BDFDB.LibraryComponents.TextInput.Sizes.MINI, BDFDB.DataUtils.save(words, this, "words");
maxLength: 100000000000000000000, BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates);
onChange: value => { }
words[rType][value] = words[rType][data.label]; })
delete words[rType][data.label]; }));
data.label = value; settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, {
BDFDB.DataUtils.save(words, this, "words"); title: "Remove All",
} collapseStates: collapseStates,
}), children: Object.keys(replaces).map(rType => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, {
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextInput, { type: "Button",
value: data.replace, color: BDFDB.LibraryComponents.Button.Colors.RED,
placeholder: data.replace, label: `Remove all ${rType} Words`,
size: BDFDB.LibraryComponents.TextInput.Sizes.MINI, onClick: _ => {
maxLength: 100000000000000000000, BDFDB.ModalUtils.confirm(this, `Are you sure you want to remove all ${rType} Words?`, _ => {
onChange: value => { words[rType] = {};
words[rType][data.label].replace = value; BDFDB.DataUtils.remove(this, "words", rType);
BDFDB.DataUtils.save(words, this, "words"); BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates);
} });
}) },
] children: BDFDB.LanguageUtils.LanguageStrings.REMOVE
}), }))
onCheckboxChange: (value, instance) => { }));
words[rType][instance.props.cardId][instance.props.settingId] = value; settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, {
BDFDB.DataUtils.save(words, this, "words"); title: "Config Guide",
}, collapseStates: collapseStates,
onRemove: (e, instance) => { children: [
delete words[rType][instance.props.cardId]; "Case: Will block/censor Words while comparing lowercase/uppercase. apple => apple, not APPLE or AppLe",
BDFDB.DataUtils.save(words, this, "words"); "Not Case: Will block/censor Words while ignoring lowercase/uppercase. apple => apple, APPLE and AppLe",
BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates); "Exact: Will block/censor Words that are exactly the selected Word. apple => apple, not applepie or pineapple",
} "Not Exact: Will block/censor all Words containing the selected Word. apple => apple, applepie and pineapple",
}) "Segment: Will only replace the caught segment in the censored Word. apple with peach => applepie => peachpie",
})); "Not Segment: Will replae the whole censored Word. apple with peach => applepie => peach",
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, { "Empty: Ignores the default/choosen Replacement Value and removes the Word/Message instead.",
title: "Remove All", [
collapseStates: collapseStates, "Regex: Will treat the entered Word Value as a Regular Expression. ",
children: Object.keys(replaces).map(rType => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, { BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Anchor, {href: "https://regexr.com/", children: BDFDB.LanguageUtils.LanguageStrings.HELP + "?"})
type: "Button", ],
color: BDFDB.LibraryComponents.Button.Colors.RED, ].map(string => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormText, {
label: `Remove all ${rType} Words`, type: BDFDB.LibraryComponents.FormComponents.FormTextTypes.DESCRIPTION,
onClick: _ => { children: string
BDFDB.ModalUtils.confirm(this, `Are you sure you want to remove all ${rType} Words?`, _ => { }))
words[rType] = {}; }));
BDFDB.DataUtils.remove(this, "words", rType);
BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates); return settingsPanel = BDFDB.PluginUtils.createSettingsPanel(this, settingsItems);
});
},
children: BDFDB.LanguageUtils.LanguageStrings.REMOVE
}))
}));
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, {
title: "Config Guide",
collapseStates: collapseStates,
children: [
"Case: Will block/censor Words while comparing lowercase/uppercase. apple => apple, not APPLE or AppLe",
"Not Case: Will block/censor Words while ignoring lowercase/uppercase. apple => apple, APPLE and AppLe",
"Exact: Will block/censor Words that are exactly the selected Word. apple => apple, not applepie or pineapple",
"Not Exact: Will block/censor all Words containing the selected Word. apple => apple, applepie and pineapple",
"Segment: Will only replace the caught segment in the censored Word. apple with peach => applepie => peachpie",
"Not Segment: Will replae the whole censored Word. apple with peach => applepie => peach",
"Empty: Ignores the default/choosen Replacement Value and removes the Word/Message instead.",
[
"Regex: Will treat the entered Word Value as a Regular Expression. ",
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Anchor, {href: "https://regexr.com/", children: BDFDB.LanguageUtils.LanguageStrings.HELP + "?"})
],
].map(string => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormText, {
type: BDFDB.LibraryComponents.FormComponents.FormTextTypes.DESCRIPTION,
children: string
}))
}));
return settingsItems;
}
});
} }
onSettingsClosed () { onSettingsClosed () {