route.user.js

Exalea - Route générique pour le P.D.O.

Tätä skriptiä ei tulisi asentaa suoraan. Se on kirjasto muita skriptejä varten sisällytettäväksi metadirektiivillä // @require https://update.greasyfork.org/scripts/4096/13109/routeuserjs.js.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

/**
 *  Prototype d'une route générique
 *
 *  @author Exalea
 */
{
    /**
     *  Constructeur
     *
     *  @param {string} regex Expression régulière permettant de déterminer si le callback doit s'appliquer à la page/URL courante
     *  @param {function} callback Méthode de callback contenant les modifications à effectuer
     *  @returns {Route} this Instance courante (permet l'utilisation de méthodes chaînées)
     *  @constructor
     *
     *  @author Exalea
     */
    var Route = function(regex, callback) {
        this.regex = regex;
        this.callback = callback;
        return this;
    };

    /**
     *  Méthode d'application/test d'une route à une URL donnée
     *
     *  @param {string} url URL à tester
     *  @returns {boolean} true si l'URL passée en paramètre correspond à cette route, false sinon
     *
     *  @author Exalea
     */
    Route.prototype.apply = function(url) {
        if(new RegExp(this.regex).test(url)) {
            this.callback();
            return true;
        }
        return false;
    };
}