settings-store.user.js

Exalea - Settings Store pour le P.D.O.

2014-08-12 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greasyfork.org/scripts/4099/13111/settings-storeuserjs.js

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

/**
 *  Prototype d'une SettingsStore (Singleton)
 */
{
    /**
     *  Constructeur
     *
     *  @returns {SettingsStore} this Instance courante (permet l'utilisation de méthodes chaînées)
     *  @constructor
     *
     *  @author Exalea
     */
    var SettingsStore = function () {
        /**
         *  Liste des paramètres disponibles (de type SettingEntry)
         *
         *  @returns {SettingsStore} this Instance courante (permet l'utilisation de méthodes chaînées)
         *
         *  @author Exalea
         */
        this.entries = {};
        return this;
    };

    /**
     *  Ajout d'un paramètre de type SettingEntry au store
     *
     *  @param {string} name Nom attribué au paramètre
     *  @param {SettingEntry} entry Paramètre à ajouter
     *  @returns {SettingsStore} this Instance courante (permet l'utilisation de méthodes chaînées)
     *
     *  @author Exalea
     */
    SettingsStore.prototype.addEntry = function (name, entry) {
        this.entries[name] = entry;
        return this;
    };

    /**
     *
     *  Ajout d'un paramètre via un nom, une clef (identifiant unique) de persistence et une valeur par défaut
     *
     *  @param {string} name Nom attribué au paramètre
     *  @param {string} key Clef de persistence du paramètre
     *  @param {string} defaultValue Valeur par défaut du paramètre
     *  @returns {SettingsStore} this Instance courante (permet l'utilisation de méthodes chaînées)
     *
     *  @author Exalea
     */
    SettingsStore.prototype.add = function (name, key, defaultValue) {
        this.addEntry(name, new SettingEntry(key, defaultValue));
        return this;
    };

    /**
     *  Initialisation (à leur valeur persistée si existante, sinon à leur valeur par défaut) de chacun des paramètres ajoutés au SettingsStore
     *
     *  @returns {SettingsStore} this Instance courante (permet l'utilisation de méthodes chaînées)
     *
     *  @author Exalea
     */
    SettingsStore.prototype.init = function () {
        for (var index in this.entries) {
            var entry = this.entries[index];
            if (entry instanceof SettingEntry)
                entry.init();
        }
        return this;
    };

    /**
     *  Implémentation du pattern Singleton
     *
     *  @returns {SettingsStore}
     */
    SettingsStore.getInstance = function () {
        if (SettingsStore.instance == null)
            SettingsStore.instance = new SettingsStore();
        return SettingsStore.instance;
    };

    /**
     *  Sucre syntaxique : ajout d'un accès statique aux méthodes du Singleton
     */
    {
        SettingsStore.addEntry = function (name, entry) {
            return SettingsStore.getInstance().addEntry(name, entry);
        };

        SettingsStore.add = function (name, key, defaultValue) {
            return SettingsStore.getInstance().add(name, key, defaultValue);
        };

        SettingsStore.init = function () {
            return SettingsStore.getInstance().init();
        };
    }
}