$Config

Allows users to configure scripts.

이 스크립트는 직접 설치해서 쓰는 게 아닙니다. 다른 스크립트가 메타 명령 // @require https://update.greasyfork.org/scripts/446506/1424453/%24Config.js(으)로 포함하여 쓰는 라이브러리입니다.

질문, 리뷰하거나, 이 스크립트를 신고하세요.
개발자
ctl2
버전
0.0.1.20240808174852
생성
2022-06-15
갱신
2024-08-08
라이선스
없음

Example instance hosted here. Source code available here.

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();
});

Constructor arguments (* = optional):

  1. [string] An identifier used to store data
  2. [Root] A schema for user config data
  3. [ParentCallback] The function used to convert tree data into a convenient format for your script
  4. [string] The config modal's title
  5. [DefaultStyle*] Instructions for customizing the UI's appearance
  6. [object*] CSS to apply to the UI's root element

See the following scripts for practical examples: