user-scripts

A collection of user scripts I've made.

View the Project on GitHub

Range type for GM_config

This library provides the a “range” type (like the <range> element; a slider representing a numeric value) suitable for use with GM_config as a custom type. The result will look something like the following:

range type example

The range type is exposed as a global named GM_config_range_type. It supports all standard field settings, plus a few of its own (see the Settings section below) and includes a text representation of the slider’s current value (which can optionally be labeled or formatted).

Usage

There are two steps to using this type: adding a @require line to your script’s metadata block, and specifying it as a custom type when initializing GM_config.

Note the version number in the library’s URL on the @require line. Including it allows you to get a newer version of the library (by changing the version number to the latest) even if the user script extension doesn’t support updating libraries. (The version number is ignore by GitHub Pages and exists solely for your script’s benefit.)

Example:

// ==UserScript==
// @name      My Cool Script
// @namespace https://example.com/
// @match     https://*.example.com/*
// @require   https://benblank.github.io/user-scripts/libraries/gm-config-range-type.lib.js?v=1.0.1
// @grant     GM_getValue
// @grant     GM_registerMenuCommand
// @grant     GM_setValue
// ==/UserScript==

// Add the "@require" line above to your own script.

GM_registerMenuCommand('Configure my cool script', () => GM_config.open());

GM_config.init({
  id: 'myCoolScript',
  title: "My cool script's settings",

  fields: {
    volume: {
      label: 'Volume',
      type: 'range',
      default: 80,
      min: 0,
      max: 100,
      step: 10,
      unitLabels: '%',
    },
  },

  types: {
    // Point the "range" type to the global "GM_config_range_type".
    range: GM_config_range_type,
  },
});

The resulting fields can be styled via CSS in the same manner as any other GM_config field.

Settings

The range type supports the following settings in addition to those common to all types: