UserUtils

General purpose DOM/GreaseMonkey library: register listeners for when CSS selectors exist, intercept events, create persistent & synchronous data stores, modify the DOM more easily and much more

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/472956/1752000/UserUtils.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 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!)

Autor
Sv443
Verzija
10.0.6
Napravljeno
12. 08. 2023
Ažurirano
09. 02. 2026
Size
107 КБ
Licenca
MIT

UserUtils

General purpose DOM/GreaseMonkey library that allows you to register listeners for when CSS selectors exist, intercept events, create persistent & synchronous data stores, modify the DOM more easily and much more.
Contains builtin TypeScript declarations. Supports ESM and CJS imports via a bundler and global declaration via @require or <script>
The library works in any DOM environment with or without the GreaseMonkey API, but some features will be unavailable or limited.

You may want to check out my template for userscripts in TypeScript that you can use to get started quickly. It also includes this library by default.

If you like using this library, please consider supporting the development ❤️


Code coverage percentage badge Bundle size badge

Discord server badge Github stargazers badge Support development on Github Sponsors badge


> Full documentation on GitHub <


View the documentation of previous major versions:

v9.4.4v8.4.0v7.3.0v6.3.0v5.0.1v4.2.1v3.0.0v2.0.1v1.2.0v0.5.3


Feature Summary:



Installation:

Shameless plug: I made a template for userscripts in TypeScript that you can use to get started quickly. It also includes this library by default.

  • If you are using a bundler (like webpack, rollup, vite, etc.), you can install this package in one of the following ways:

    npm i @sv443-network/userutils
    pnpm i @sv443-network/userutils
    yarn add @sv443-network/userutils
    npx jsr install @sv443-network/userutils
    deno add jsr:@sv443-network/userutils
    

    Then import it in your script as usual:

    // on Node:
    import { addGlobalStyle } from "@sv443-network/userutils";
    
    // on Deno:
    import { addGlobalStyle } from "jsr:@sv443-network/userutils";
    
    // you can also import the entire library as an object (not recommended because of worse treeshaking support):
    import * as UserUtils from "@sv443-network/userutils";
    


  • If you are not using a bundler, want to reduce the size of your userscript, or declared the package as external in your bundler, you can include the latest release by adding one of these directives to the userscript header, depending on your preferred CDN:
    Versioned (recommended):

    // @require https://cdn.jsdelivr.net/npm/@sv443-network/userutils@INSERT_VERSION/dist/UserUtils.umd.js
    // @require https://unpkg.com/@sv443-network/userutils@INSERT_VERSION/dist/UserUtils.umd.js
    

    Non-versioned (not recommended because auto-updating):

    // @require https://update.greasyfork.org/scripts/472956/UserUtils.js
    // @require https://openuserjs.org/src/libs/Sv443/UserUtils.js
    
  • If you are using this library in a generic DOM environment without access to the GreaseMonkey API, either download the latest release from the releases page to include in your project or add one of the following tags to the <head>:

    <script src="https://cdn.jsdelivr.net/npm/@sv443-network/userutils@INSERT_VERSION/dist/UserUtils.umd.js"></script>
    <script src="https://unpkg.com/@sv443-network/userutils@INSERT_VERSION/dist/UserUtils.umd.js"></script>
    

Note:
In order for your userscript not to break on a major library update, use one the versioned URLs above after replacing INSERT_VERSION with the desired version (e.g. 8.3.2) or the versioned URL that's shown at the top of the GreasyFork page.


  • Then, access the functions on the global variable UserUtils:

    UserUtils.addGlobalStyle("body { background-color: red; }");
    
    // or using object destructuring:
    
    const { clamp } = UserUtils;
    console.log(clamp(1, 5, 10)); // 5
    


  • If you're using TypeScript and it complains about the missing global variable UserUtils, install the library using the package manager of your choice and add the following inside any .ts file that is included in the final build:

    declare const UserUtils: typeof import("@sv443-network/userutils");
    
    declare global {
        interface Window {
            UserUtils: typeof UserUtils;
        }
    }
    


  • If you're using a linter like ESLint, it might complain about the global variable UserUtils not being defined. To fix this, add the following to your ESLint configuration file:

    "globals": {
        "UserUtils": "readonly"
    }
    



License:

This library is licensed under the MIT License.
See the license file for details.




Made with ❤️ by Sv443
If you like this library, please consider supporting the development