$Config

Allows users to configure scripts

目前为 2024-07-08 提交的版本。查看 最新版本

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.gf.qytechs.cn/scripts/446506/1407437/%24Config.js

作者
ctl2
版本
0.0.1.20240708162508
创建于
2022-06-15
更新于
2024-07-08
大小
282.2 KB
许可证
暂无

Source code available here. Example instance hosted 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();
});

See the following scripts for practical examples:

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址