Gathering detailed insights and metrics for @sv443-network/userutils
Gathering detailed insights and metrics for @sv443-network/userutils
Gathering detailed insights and metrics for @sv443-network/userutils
Gathering detailed insights and metrics for @sv443-network/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
npm install @sv443-network/userutils
Typescript
Module System
Node Version
NPM Version
TypeScript (96.17%)
JavaScript (3.34%)
HTML (0.3%)
CSS (0.19%)
Total Downloads
6,531
Last Day
3
Last Week
113
Last Month
230
Last Year
3,531
MIT License
13 Stars
520 Commits
1 Forks
3 Branches
1 Contributors
Updated on Mar 21, 2025
Minified
Minified + Gzipped
Latest Version
9.3.0
Package Id
@sv443-network/userutils@9.3.0
Unpacked Size
345.00 kB
Size
84.68 kB
File Count
24
NPM Version
10.9.2
Node Version
22.14.0
Published on
Mar 21, 2025
Cumulative downloads
Total Downloads
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
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 ❤️
8.0.0, 7.0.0, 6.0.0, 5.0.0, 4.0.0, 3.0.0, 2.0.0, 1.0.0, 0.5.3
SelectorObserver
- class that manages listeners that are called when selectors are found in the DOMgetUnsafeWindow()
- get the unsafeWindow object or fall back to the regular window objectisDomLoaded()
- check if the DOM has finished loading and can be queried and modifiedonDomLoad()
- run a function or pause async execution until the DOM has finished loading (or immediately if DOM is already loaded)addParent()
- add a parent element around another elementaddGlobalStyle()
- add a global style to the pagepreloadImages()
- preload images into the browser cache for faster loading later onopenInNewTab()
- open a link in a new tabinterceptEvent()
- conditionally intercepts events registered by addEventListener()
on any given EventTarget objectinterceptWindowEvent()
- conditionally intercepts events registered by addEventListener()
on the window objectisScrollable()
- check if an element has a horizontal or vertical scroll barobserveElementProp()
- observe changes to an element's property that can't be observed with MutationObservergetSiblingsFrame()
- returns a frame of an element's siblings, with a given alignment and sizesetInnerHtmlUnsafe()
- set the innerHTML of an element using a Trusted Types policy without sanitizing or escaping itprobeElementStyle()
- probe the computed style of a temporary element (get default font size, resolve CSS variables, etc.)clamp()
- constrain a number between a min and max valuemapRange()
- map a number from one range to the same spot in another rangerandRange()
- generate a random number between a min and max boundarydigitCount()
- calculate the amount of digits in a numberroundFixed()
- round a floating-point number at the given amount of decimals, or to the given power of 10bitSetHas()
- check if a bit is set in a bitsetDataStore
- class that manages a hybrid sync & async persistent JSON database, including data migrationDataStoreSerializer
- class for importing & exporting data of multiple DataStore instances, including compression, checksumming and running migrationsDialog
- class for creating custom modal dialogs with a promise-based API and a generic, default styleNanoEmitter
- tiny event emitter class with a focus on performance and simplicity (based on nanoevents)Debouncer
- class for debouncing function calls with a given timeoutdebounce()
- function wrapper for the Debouncer class for easier usageautoPlural()
- automatically pluralize a stringpauseFor()
- pause the execution of a function for a given amount of timefetchAdvanced()
- wrapper around the fetch API with a timeout optioninsertValues()
- insert values into a string at specified placeholderscompress()
- compress a string with Gzip or Deflatedecompress()
- decompress a previously compressed stringcomputeHash()
- compute the hash / checksum of a string or ArrayBufferrandomId()
- generate a random ID of a given length and radixconsumeGen()
- consumes a ValueGen and returns the valueconsumeStringGen()
- consumes a StringGen and returns the stringgetListLength()
- get the length of any object with a numeric length
, count
or size
propertypurifyObj()
- removes the prototype chain (all default properties like toString
, __proto__
, etc.) from an objectrandomItem()
- returns a random item from an arrayrandomItemIndex()
- returns a tuple of a random item and its index from an arraytakeRandomItem()
- returns a random item from an array and mutates it to remove the itemrandomizeArray()
- returns a copy of the array with its items in a random ordertr.for()
- translates a key for the specified languagetr.use()
- creates a translation function for the specified languagetr.hasKey()
- checks if a key exists in the given languagetr.addTranslations()
- add a flat or recursive translation object for a languagetr.getTranslations()
- returns the translation object for a languagetr.deleteTranslations()
- delete the translation object for a languagetr.setFallbackLanguage()
- set the fallback language used when a key is not found in the given languagetr.getFallbackLanguage()
- returns the fallback languagetr.addTransform()
- adds a transform function to the translation system for custom argument insertion and much moretr.deleteTransform()
- removes a transform functiontr.transforms
- predefined transform functions for quickly adding custom argument insertionTrKeys
- generic type that extracts all keys from a flat or recursive translation object into a unionhexToRgb()
- convert a hex color string to an RGB or RGBA value tuplergbToHex()
- convert RGB or RGBA values to a hex color stringlightenColor()
- lighten a CSS color string (hex, rgb or rgba) by a given percentagedarkenColor()
- darken a CSS color string (hex, rgb or rgba) by a given percentageStringifiable
- any value that is a string or can be converted to one (implicitly or explicitly)NonEmptyArray
- any array that should have at least one itemNonEmptyString
- any string that should have at least one characterLooseUnion
- a union that gives autocomplete in the IDE but also allows any other value of the same typePrettify
- expands a complex type into a more readable format while keeping functionality the sameValueGen
- a "generator" value that allows for super flexible value typing and declarationStringGen
- a "generator" string that allows for super flexible string typing and declaration, including enhanced support for unionsListWithLength
- represents an array or object with a numeric length
, count
or size
propertyUUError
- base class for all custom UserUtils errors - has a custom date
prop set to the time of creationChecksumMismatchError
- thrown when a string of data doesn't match its checksumMigrationError
- thrown when a data migration failsPlatformError
- thrown when a function is called in an unsupported environmentShameless 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:
1// on Node: 2import { addGlobalStyle } from "@sv443-network/userutils"; 3 4// on Deno: 5import { addGlobalStyle } from "jsr:@sv443-network/userutils"; 6 7// you can also import the entire library as an object (not recommended because of worse treeshaking support): 8import * as UserUtils from "@sv443-network/userutils";
If you are not using a bundler, want to reduce the size of your script, 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/index.global.js
// @require https://unpkg.com/@sv443-network/userutils@INSERT_VERSION/dist/index.global.js
Non-versioned (not recommended because it auto-updates):
// @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>:
1<script src="https://cdn.jsdelivr.net/npm/@sv443-network/userutils@INSERT_VERSION/dist/index.global.js"></script> 2<script src="https://unpkg.com/@sv443-network/userutils@INSERT_VERSION/dist/index.global.js"></script>
[!NOTE]
In order for your script not to break on a major library update, use one the versioned URLs above after replacingINSERT_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
:
1UserUtils.addGlobalStyle("body { background-color: red; }"); 2 3// or using object destructuring: 4 5const { clamp } = UserUtils; 6console.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:
1declare const UserUtils: typeof import("@sv443-network/userutils"); 2 3declare global { 4 interface Window { 5 UserUtils: typeof UserUtils; 6 } 7}
UserUtils
not being defined. To fix this, add the following to your ESLint configuration file:
1"globals": { 2 "UserUtils": "readonly" 3}
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
No vulnerabilities found.
No security vulnerabilities found.
Last Day
-95.7%
3
Compared to previous day
Last Week
52.7%
113
Compared to previous week
Last Month
-46.1%
230
Compared to previous month
Last Year
17.7%
3,531
Compared to previous year