UserscriptSettings

none

29.04.2025 itibariyledir. En son verisyonu görün.

Bu script direkt olarak kurulamaz. Başka scriptler için bir kütüphanedir ve meta yönergeleri içerir // @require https://update.greatest.deepsurf.us/scripts/534380/1580029/UserscriptSettings.js

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name        UserscriptSettings
// @description none
// @version     1.0.0
// @grant       GM_registerMenuCommand
// @grant       GM_getValue
// @grant       GM_setValue
// ==/UserScript==

const UserscriptSettings = (function () {
    const settingsDefinition = {};

    function get(settingKey) {
        const storedSettings = GM_getValue("settings", {});
        if (settingKey in storedSettings) return storedSettings[settingKey];
        return settingsDefinition[settingKey]?.default;
    }

    function set(settingKey, rawValue) {
        const def = settingsDefinition[settingKey];
        let value = rawValue;

        // Apply formatter if defined
        if (def?.formatter && typeof def.formatter === "function") {
            try {
                value = def.formatter(rawValue);
            } catch (e) {
                console.warn(`Formatter error for setting "${settingKey}":`, e);
                return;
            }
        }

        const storedSettings = GM_getValue("settings", {});
        storedSettings[settingKey] = value;
        GM_setValue("settings", storedSettings);
    }

    function define(settingsObj) {
        for (const [key, def] of Object.entries(settingsObj)) {
            if (def && def.default !== undefined) {
                settingsDefinition[key] = def;
            }
        }
    }

    function createMenu() {
        const storedSettings = GM_getValue("settings", {});
        for (const [key, setting] of Object.entries(settingsDefinition)) {
            const currentValue = key in storedSettings ? storedSettings[key] : setting.default;

            if (typeof setting.default === "boolean") {
                const menuTitle = () => `${get(key) ? "✔️" : "❌"} ${setting.name}`;
                GM_registerMenuCommand(menuTitle(), () => {
                    const newValue = !get(key);
                    set(key, newValue);
                    location.reload();
                });
            } else {
                GM_registerMenuCommand(setting.name, () => {
                    // Use display function if available
                    const rawValue = get(key);
                    const shownValue = setting.display ? setting.display(rawValue) : String(rawValue);
                    const input = prompt(setting.name, shownValue);
                    if (input !== null) {
                        const parsedValue = typeof setting.default === "number" ? Number(input) : input;
                        set(key, parsedValue);
                    }
                });
            }
        }
    }

    return {
        define,
        get,
        set,
        createMenu,
    };
})();