Updated Module Settings Experiment

This commit is contained in:
フズキ 2021-03-25 14:42:24 +01:00
parent e1667e6865
commit 04e817908e
No known key found for this signature in database
GPG Key ID: AD7750AB4625F1DD
3 changed files with 28 additions and 5 deletions

View File

@ -22,8 +22,7 @@ export function textInputField(text, subtext, placeholder, onApply, initialValue
inputEl.classList.add('inputDefault-_djjkz', 'input-cIJ7To');
inputEl.placeholder = placeholder;
inputEl.type = 'text';
inputEl.value = initialValue ? initialValue : '';
inputWrapEl.appendChild(inputEl);
// Button field
@ -47,6 +46,16 @@ export function textInputField(text, subtext, placeholder, onApply, initialValue
dividerEl.classList.add('divider-3573oO', 'dividerDefault-3rvLe-');
dividerEl.style.marginTop = subtext ? '20px' : '45px';
// Insertion checker
// A bit hacky...
// But works :)
let insertCheckId = setInterval(() => {
if (el.parentNode != null) {
inputEl.value = initialValue != undefined ? initialValue() : '';
clearInterval(insertCheckId);
}
}, 1000);
el.appendChild(textEl);
el.appendChild(buttonEl);
el.appendChild(inputWrapEl);

View File

@ -7,5 +7,5 @@
"authors": ["186496078273708033"],
"version": "1.0.0"
"version": "1.1.0"
}

View File

@ -6,6 +6,7 @@ import { textInputField } from './custom-settings.js';
let settingsPage = "Settings Experiment";
let settings;
let defaultSettings = {
inputText: "Default value"
};
export default {
@ -130,13 +131,26 @@ export default {
{
type: "custom",
element: textInputField(
"Text Input",
"Text Input (static initial value)",
"Prototype",
"Placeholder",
value => {
showToast(`Text Input: ${value}`);
},
"Preset value"
() => "Preset value"
)
},
{
type: "custom",
element: textInputField(
"Text Input (loading from and saving to settings)",
"Prototype",
"Placeholder",
value => {
showToast(`Text Input: ${value}`);
settings.inputText = value;
},
() => settings.inputText
)
}
]);