您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Library with various utilities for userscripts - register listeners for when CSS selectors exist, intercept events, manage persistent user configurations, modify the DOM more easily and more
当前为
此脚本不应直接安装,它是供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.greasyforks.org/scripts/472956/1328360/UserUtils.js
Library with various utilities for userscripts - register listeners for when CSS selectors exist, intercept events, manage persistent user configurations, modify the DOM more easily and more.
Contains builtin TypeScript declarations. Fully web compatible and supports ESM and CJS imports and global declaration.
Licensed under the MIT license.
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 ❤️
Or view the documentation of previous major releases: 3.0.0, 2.0.1, 1.2.0, 0.5.3
addEventListener()
on any given EventTarget objectaddEventListener()
on the window objectIf you are using a bundler like webpack, you can install this package using npm:
npm i @sv443-network/userutils
Then, import it in your script as usual:
import { addGlobalStyle } from "@sv443-network/userutils";
// or just import everything (not recommended because this doesn't allow for treeshaking):
import * as UserUtils from "@sv443-network/userutils";
Shameless plug: I made a webpack-based template for userscripts in TypeScript that you can use to get started quickly. It also includes this library by default.
If you are not using a bundler, you can include the latest release by adding one of these directives to the userscript header, depending on your preferred CDN:
// @require https://greasyforks.org/scripts/472956-userutils/code/UserUtils.js
// @require https://openuserjs.org/src/libs/Sv443/UserUtils.js
(in order for your userscript not to break on a major library update, use the versioned URL 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