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 ❤️
View the documentation of previous major versions:
v9.4.4 • v8.4.0 • v7.3.0 • v6.3.0 • v5.0.1 • v4.2.1 • v3.0.0 • v2.0.1 • v1.2.0 • v0.5.3
[!NOTE]
In version 10.0.0, many of the platform-agnostic features were moved to the CoreUtils library.
Everything in CoreUtils is re-exported by UserUtils for backwards compatibility, so installing both at the same time isn't usually necessary.
Beware that when both are installed, class inheritance between the two libraries will only work if the installed version of CoreUtils matches the version of CoreUtils that is included in UserUtils (refer topackage.json), so that the final bundler is able to deduplicate them correctly. See alsoconst versions
class Dialog - class for creating custom modal dialogs with a promise-based API and a generic, default styleclass SelectorObserver - class that manages listeners that are called when selectors are found in the DOMfunction getUnsafeWindow() - get the unsafeWindow object or fall back to the regular window objectfunction isDomLoaded() - check if the DOM has finished loading and can be queried and modifiedfunction onDomLoad() - run a function or pause async execution until the DOM has finished loading (or immediately if DOM is already loaded)function addParent() - add a parent element around another elementfunction addGlobalStyle() - add a global style to the pagefunction preloadImages() - preload images into the browser cache for faster loading later onfunction openInNewTab() - open a link in a new tabfunction interceptEvent() - conditionally intercepts events registered by addEventListener() on any given EventTarget objectfunction interceptWindowEvent() - conditionally intercepts events registered by addEventListener() on the window objectfunction isScrollable() - check if an element has a horizontal or vertical scroll barfunction observeElementProp() - observe changes to an element's property that can't be observed with MutationObserverfunction getSiblingsFrame() - returns a frame of an element's siblings, with a given alignment and sizefunction setInnerHtmlUnsafe() - set the innerHTML of an element using a Trusted Types policy without sanitizing or escaping itfunction probeElementStyle() - probe the computed style of a temporary element (get default font size, resolve CSS variables, etc.)class GMStorageEngine - storage engine class for DataStores using the GreaseMonkey APIclass Mixins - class for creating mixin functions that allow multiple sources to modify a target value in a highly flexible wayconst versions - contains version information for UserUtils and CoreUtilsfunction tr.for() - translates a key for the specified languagefunction tr.use() - creates a translation function for the specified languagefunction tr.hasKey() - checks if a key exists in the given languagefunction tr.addTranslations() - add a flat or recursive translation object for a languagefunction tr.getTranslations() - returns the translation object for a languagefunction tr.getAllTranslations() - returns all registered translationsfunction tr.deleteTranslations() - delete the translation object for a languagefunction tr.setFallbackLanguage() - set the fallback language used when a key is not found in the given languagefunction tr.getFallbackLanguage() - returns the fallback languagefunction tr.addTransform() - adds a transform function to the translation system for custom argument insertion and much morefunction tr.deleteTransform() - removes a transform functionconst tr.transforms - predefined transform functions for quickly adding custom argument insertiontype TrKeys - generic type that extracts all keys from a flat or recursive translation object into a unionclass PlatformError - thrown when the current platform doesn't support a certain feature, like calling a DOM function in a non-DOM environmentfunction randomItem() - Returns a random item from the given arrayfunction randomItemIndex() - Returns a random array item and index as a tuplefunction randomizeArray() - Returns a new array with the items in random orderfunction takeRandomItem() - Returns a random array item and mutates the array to remove itfunction takeRandomItemIndex() - Returns a random array item and index as a tuple and mutates the array to remove ittype NonEmptyArray - Non-empty array typefunction darkenColor() - Darkens the given color by the given percentagefunction hexToRgb() - Converts a hex color string to an RGB objectfunction lightenColor() - Lightens the given color by the given percentagefunction rgbToHex() - Converts an RGB object to a hex color stringfunction abtoa() - Converts an ArrayBuffer to a stringfunction atoab() - Converts a string to an ArrayBufferfunction compress() - Compresses the given string u$ claude mcp add UserUtils \
-- python -m otcore.mcp_server <graph>