Greasy Fork is available in English.

$Config

Allows end users to configure scripts.

Dieses Skript sollte nicht direkt installiert werden. Es handelt sich hier um eine Bibliothek für andere Skripte, welche über folgenden Befehl in den Metadaten eines Skriptes eingebunden wird // @require https://update.greasyfork.org/scripts/446506/1308987/%24Config.js

Autor
ctl2
Version
0.0.1.20240109135412
Erstellt am
15.06.2022
Letzte Aktualisierung
09.01.2024
Lizenz
n/a

Config editor hosted here. Editor code available here.

Images are attached below to describe constructor parameters.

Usage

// Request a config

const $config = new $Config(
    'STORAGE_KEY',
    {
        'children': [
            {'label': 'node0'},
            {'label': 'node1'},
            {'label': 'node2'}
        ]
    },
    ([node0, node1, node2]) => {
        const config = {};
        // ...
        return config;
    },
    'Example Title'
);

// Await config load & handle problems

try {
    await $config.ready;
} catch (error) {
    if (!$config.reset) {
        // There's a problem with the arguments passed to the $Config constructor
        throw error;
    }

    // There's a problem with the user's data (could be from manual editing or a script update)
    if (!window.confirm(`${error.message}\n\nWould you like to erase your data?`)) {
        return;
    }

    $config.reset();
}

// Apply the user's config

function useConfig() {
    const config = $config.get();

    // Use the config...
}

useConfig();

// Set up config editing

const button = document.createElement('button');

button.addEventListener('click', async () => {
    await $config.edit();

    useConfig();
});