This commit is contained in:
Mirco Wittrien 2020-07-02 10:42:56 +02:00
parent 3e6e92df27
commit 5882330cbd
2 changed files with 105 additions and 59 deletions

View File

@ -43,9 +43,9 @@ var ChatAliases = (_ => {
file: {value:false, description:"Handle the replacevalue as a filepath"} file: {value:false, description:"Handle the replacevalue as a filepath"}
}, },
settings: { settings: {
replaceBeforeSend: {value:true, inner:false, description:"Replace words with your Aliases before a message is sent"}, replaceBeforeSend: {value:true, inner:false, description:"Replace words with your aliases before a message is sent"},
addContextMenu: {value:true, inner:false, description:"Add a ContextMenu entry to faster add new Aliases"}, addContextMenu: {value:true, inner:false, description:"Add a contextMenu entry to faster add new aliases"},
addAutoComplete: {value:true, inner:false, description:"Add an Autocomplete-Menu for Non-RegExp Aliases"}, addAutoComplete: {value:true, inner:false, description:"Add an autocomplete-menu for non-RegExp aliases"},
triggerNormal: {value:true, inner:true, description:"Normal Message Textarea"}, triggerNormal: {value:true, inner:true, description:"Normal Message Textarea"},
triggerEdit: {value:true, inner:true, description:"Edit Message Textarea"}, triggerEdit: {value:true, inner:true, description:"Edit Message Textarea"},
triggerUpload: {value:true, inner:true, description:"Upload Message Prompt"} triggerUpload: {value:true, inner:true, description:"Upload Message Prompt"}
@ -85,7 +85,7 @@ var ChatAliases = (_ => {
value: amounts[key] value: amounts[key]
})); }));
innerItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsPanelInner, { innerItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsPanelInner, {
title: "Automatically replace Aliases in:", title: "Automatically replace aliases in:",
first: innerItems.length == 0, first: innerItems.length == 0,
last: true, last: true,
children: subInnerItems children: subInnerItems
@ -97,13 +97,13 @@ var ChatAliases = (_ => {
})); }));
let values = {wordvalue:"", replacevalue:""}; let values = {wordvalue:"", replacevalue:""};
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, { settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, {
title: "Add new Alias", title: "Add new alias",
collapseStates: collapseStates, collapseStates: collapseStates,
dividertop: true, dividertop: true,
children: [ children: [
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, { BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, {
type: "Button", type: "Button",
label: "Pick a Wordvalue and Replacevalue:", label: "Pick a wordvalue and replacevalue:",
key: "ADDBUTTON", 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,
@ -116,7 +116,7 @@ var ChatAliases = (_ => {
].flat(10).filter(n => n) ].flat(10).filter(n => n)
})); }));
if (!BDFDB.ObjectUtils.isEmpty(aliases)) settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, { if (!BDFDB.ObjectUtils.isEmpty(aliases)) settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, {
title: "Added Aliases", title: "Added aliases",
collapseStates: collapseStates, collapseStates: collapseStates,
dividertop: true, dividertop: true,
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsList, { children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsList, {
@ -171,9 +171,9 @@ var ChatAliases = (_ => {
type: "Button", type: "Button",
className: BDFDB.disCN.marginbottom8, className: BDFDB.disCN.marginbottom8,
color: BDFDB.LibraryComponents.Button.Colors.RED, color: BDFDB.LibraryComponents.Button.Colors.RED,
label: "Remove all added Aliases", label: "Remove all added aliases",
onClick: _ => { onClick: _ => {
BDFDB.ModalUtils.confirm(this, "Are you sure you want to remove all added Aliases?", _ => { BDFDB.ModalUtils.confirm(this, "Are you sure you want to remove all added aliases?", _ => {
aliases = {}; aliases = {};
BDFDB.DataUtils.remove(this, "words"); BDFDB.DataUtils.remove(this, "words");
BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates); BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates);
@ -503,20 +503,19 @@ var ChatAliases = (_ => {
} }
createInputs (values) { createInputs (values) {
return [{title:"Replace:", type:"", error:"Choose a Wordvalue", valuename:"wordvalue"}, {title:"With:", type:"file", error:"Choose a Replacevalue", valuename:"replacevalue"}].map(inputdata => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormItem, { return [
title: inputdata.title, BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormItem, {
className: BDFDB.disCN.marginbottom8 + " input-" + inputdata.valuename, title: "Replace:",
className: BDFDB.disCN.marginbottom8 + " input-wordvalue",
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextInput, { children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextInput, {
type: inputdata.type, value: values.wordvalue,
useFilePath: inputdata.type == "file", placeholder: values.wordvalue,
value: values[inputdata.valuename], errorMessage: !values.wordvalue && "Choose a wordvalue" || aliases[values.wordvalue] && "Wordvalue already used, saving will overwrite old alias",
placeholder: values[inputdata.valuename],
autoFocus: inputdata.valuename == "replacevalue",
errorMessage: !values[inputdata.valuename] && inputdata.error,
onChange: (value, instance) => { onChange: (value, instance) => {
values[inputdata.valuename] = value.trim(); values.wordvalue = value.trim();
if (values[inputdata.valuename]) delete instance.props.errorMessage; if (!values.wordvalue) instance.props.errorMessage = "Choose a wordvalue";
else instance.props.errorMessage = inputdata.error; else if (aliases[values.wordvalue]) instance.props.errorMessage = "Wordvalue already used, saving will overwrite old alias";
else delete instance.props.errorMessage;
let addButtonIns = BDFDB.ReactUtils.findOwner(BDFDB.ReactUtils.findOwner(instance, {name:["BDFDB_Modal", "BDFDB_SettingsPanel"], up:true}), {key:"ADDBUTTON"}); let addButtonIns = BDFDB.ReactUtils.findOwner(BDFDB.ReactUtils.findOwner(instance, {name:["BDFDB_Modal", "BDFDB_SettingsPanel"], up:true}), {key:"ADDBUTTON"});
if (addButtonIns) { if (addButtonIns) {
addButtonIns.props.disabled = !Object.keys(values).every(valuename => values[valuename]); addButtonIns.props.disabled = !Object.keys(values).every(valuename => values[valuename]);
@ -524,7 +523,30 @@ var ChatAliases = (_ => {
} }
} }
}) })
})); }),
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormItem, {
title: "With:",
className: BDFDB.disCN.marginbottom8 + " input-replacevalue",
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextInput, {
type: "file",
useFilePath: true,
value: values.replacevalue,
placeholder: values.replacevalue,
autoFocus: true,
errorMessage: !values.replacevalue && "Choose a replacevalue",
onChange: (value, instance) => {
values.replacevalue = value.trim();
if (!values.replacevalue) instance.props.errorMessage = "Choose a replacevalue";
else delete instance.props.errorMessage;
let addButtonIns = BDFDB.ReactUtils.findOwner(BDFDB.ReactUtils.findOwner(instance, {name:["BDFDB_Modal", "BDFDB_SettingsPanel"], up:true}), {key:"ADDBUTTON"});
if (addButtonIns) {
addButtonIns.props.disabled = !Object.keys(values).every(valuename => values[valuename]);
BDFDB.ReactUtils.forceUpdate(addButtonIns);
}
}
})
})
];
} }
saveWord (wordvalue, replacevalue, fileselection, aliasConfigs = configs) { saveWord (wordvalue, replacevalue, fileselection, aliasConfigs = configs) {

View File

@ -41,12 +41,11 @@ var ChatFilter = (_ => {
exact: {value:true, description:"Handle the wordvalue as an exact word and not as part of a word"} exact: {value:true, description:"Handle the wordvalue as an exact word and not as part of a word"}
}, },
replaces: { replaces: {
blocked: {value:"~~BLOCKED~~", description:"Default Replaceword for blocked Messages:"}, blocked: {value:"~~BLOCKED~~", description:"Default replaceword for blocked messages:"},
censored: {value:"$!%&%!&", description:"Default Replaceword for censored Messages:"} censored: {value:"$!%&%!&", description:"Default replaceword for censored messages:"}
}, },
settings: { settings: {
addContextMenu: {value:true, description:"Add a ContextMenu entry to faster add new blocked/censored Words:"}, addContextMenu: {value:true, description:"Add a contextmenu entry to faster add new blocked/censored words:"}
showMessageOnClick: {value:true, description:"Show original Message on Click:"},
} }
}; };
} }
@ -79,13 +78,13 @@ var ChatFilter = (_ => {
})); }));
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,
dividertop: true, dividertop: true,
children: [ children: [
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, { BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, {
type: "Button", type: "Button",
label: "Pick a Wordvalue and Replacevalue:", label: "Pick a wordvalue and replacevalue:",
key: "ADDBUTTON", 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,
@ -98,7 +97,7 @@ var ChatFilter = (_ => {
].flat(10).filter(n => n) ].flat(10).filter(n => n)
})); }));
for (let rtype in replaces) if (!BDFDB.ObjectUtils.isEmpty(words[rtype])) settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, { for (let rtype in replaces) if (!BDFDB.ObjectUtils.isEmpty(words[rtype])) settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, {
title: `Added ${rtype} Words`, title: `Added ${rtype} words`,
collapseStates: collapseStates, collapseStates: collapseStates,
dividertop: true, dividertop: true,
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsList, { children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsList, {
@ -153,9 +152,9 @@ var ChatFilter = (_ => {
type: "Button", type: "Button",
className: BDFDB.disCN.marginbottom8, className: BDFDB.disCN.marginbottom8,
color: BDFDB.LibraryComponents.Button.Colors.RED, color: BDFDB.LibraryComponents.Button.Colors.RED,
label: `Remove all ${rtype} Words`, label: `Remove all ${rtype} words`,
onClick: _ => { onClick: _ => {
BDFDB.ModalUtils.confirm(this, `Are you sure you want to remove all ${rtype} Words?`, _ => { BDFDB.ModalUtils.confirm(this, `Are you sure you want to remove all ${rtype} words?`, _ => {
words[rtype] = {}; words[rtype] = {};
BDFDB.DataUtils.remove(this, "words", rtype); BDFDB.DataUtils.remove(this, "words", rtype);
BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates); BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates);
@ -393,31 +392,56 @@ var ChatFilter = (_ => {
} }
createInputs (values) { createInputs (values) {
return [{title:"Block/Censor:", error:"Choose a Wordvalue", valuename:"wordvalue"}, {title:"With:", valuename:"replacevalue"}].map(inputdata => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormItem, { return [
title: inputdata.title, BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormItem, {
className: BDFDB.disCN.marginbottom8 + " input-" + inputdata.valuename, title: "Block/Censor:",
className: BDFDB.disCN.marginbottom8 + " input-wordvalue",
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextInput, { children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextInput, {
value: values[inputdata.valuename], key: "WORDVALUE",
placeholder: values[inputdata.valuename], value: values.wordvalue,
autoFocus: inputdata.valuename == "replacevalue", placeholder: values.wordvalue,
errorMessage: !values[inputdata.valuename] && inputdata.error, errorMessage: !values.wordvalue && "Choose a wordvalue" || words[values.choice][values.wordvalue] && `Wordvalue already used, saving will overwrite old ${values.choice} word`,
onChange: (value, instance) => { onChange: (value, instance) => {
values[inputdata.valuename] = value.trim(); values.wordvalue = value.trim();
if (values[inputdata.valuename]) delete instance.props.errorMessage; if (!values.wordvalue) instance.props.errorMessage = "Choose a wordvalue";
else instance.props.errorMessage = inputdata.error; else if (words[values.choice][values.wordvalue]) instance.props.errorMessage = `Wordvalue already used, saving will overwrite old ${values.choice} word`;
let addbuttonins = BDFDB.ReactUtils.findOwner(BDFDB.ReactUtils.findOwner(instance, {name:["BDFDB_Modal", "BDFDB_SettingsPanel"], up:true}), {key:"ADDBUTTON"}); else delete instance.props.errorMessage;
if (addbuttonins) { let addButtonIns = BDFDB.ReactUtils.findOwner(BDFDB.ReactUtils.findOwner(instance, {name:["BDFDB_Modal", "BDFDB_SettingsPanel"], up:true}), {key:"ADDBUTTON"});
addbuttonins.props.disabled = !values.wordvalue; if (addButtonIns) {
BDFDB.ReactUtils.forceUpdate(addbuttonins); addButtonIns.props.disabled = !values.wordvalue;
BDFDB.ReactUtils.forceUpdate(addButtonIns);
} }
} }
}) })
})).concat(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.RadioGroup, { }),
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormItem, {
title: "With:",
className: BDFDB.disCN.marginbottom8 + " input-replacevalue",
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextInput, {
value: values.replacevalue,
placeholder: values.replacevalue,
autoFocus: true,
onChange: (value, instance) => {
values.replacevalue = value.trim();
}
})
}),
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 => {values.choice = value.value;} onChange: (value, instance) => {
})); values.choice = value.value;
let wordvalueInputIns = BDFDB.ReactUtils.findOwner(BDFDB.ReactUtils.findOwner(instance, {name:["BDFDB_Modal", "BDFDB_SettingsPanel"], up:true}), {key:"WORDVALUE"});
if (wordvalueInputIns) {
if (!values.wordvalue) wordvalueInputIns.props.errorMessage = "Choose a wordvalue";
else if (words[values.choice][values.wordvalue]) wordvalueInputIns.props.errorMessage = `Wordvalue already used, saving will overwrite old ${values.choice} word`;
else delete wordvalueInputIns.props.errorMessage;
BDFDB.ReactUtils.forceUpdate(wordvalueInputIns);
}
}
})
];
} }
saveWord (values, wordConfigs = configs) { saveWord (values, wordConfigs = configs) {