بۇ قوليازمىنى بىۋاسىتە قاچىلاشقا بولمايدۇ. بۇ باشقا قوليازمىلارنىڭ ئىشلىتىشى ئۈچۈن تەمىنلەنگەن ئامبار بولۇپ، ئىشلىتىش ئۈچۈن مېتا كۆرسەتمىسىگە قىستۇرىدىغان كود: // @require https://update.greasyfork.org/scripts/526417/1683592/USToolkit.js
USToolkit
A simple toolkit to create userscripts (alpha).
Installation
To use this toolkit, you need a userscript manager like Tampermonkey or Violentmonkey.
Add the following metadata to your userscript:
// @require https://update.greasyfork.org/scripts/526417/1683591/USToolkit.js
Usage
After installing the userscript, the UST object will be available in the window scope of any page. You can use it in your own userscripts to simplify common tasks.
// ==UserScript==
// @name My Userscript
// @match https://example.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
UST.onElement('button', (button) => {
console.log('Button found:', button);
});
})();
API Reference
observe(func, options, scope)
Sets up a MutationObserver to watch for DOM changes and executes a callback function.
OnElements({ root, deep, observeOptions })
A class to watch for elements being added to the DOM.
onElement(selector, callback)
Registers a callback to be executed when an element matching a selector is added to the DOM.
getTextNodes(scope)
Returns a generator that iterates over all text nodes in a scope, including those inside Shadow DOMs.
getShadowRoots(scope)
A generator function that finds and yields all shadow roots within the given scope.
queryAll(scope, selector)
A recursive query selector that traverses into Shadow DOMs.
query(scope, selector)
Finds the first element that matches a selector, including inside Shadow DOMs.
closest(element, selector)
Finds the closest ancestor element that matches a selector, traversing up through Shadow DOMs.
injectScriptInline(code)
Injects a script into the document head for execution.
waitElement(selector, timeout)
Waits for an element that matches a given CSS selector to appear in the DOM.
on(events, selector, callback, options, scope)
Attaches a delegated event listener to a scope.
storage()
Provides a simplified, proxied interface for accessing and modifying Greasemonkey's persistent storage.
setNestedValue(obj, path, value)
Sets a value in a nested object based on an array path.
getNestedValue(obj, path)
Gets a value from a nested object based on an array path.
createDeepProxy(target, callback)
Creates a recursive proxy that intercepts property access (get) and modification (set).
safeGet(obj, chain)
Safely retrieves a nested property from an object using a string path.
handleArray(arr, nextProp)
Helper for prop to handle array wildcards. It maps over an array and extracts a property from each item.
handleObject(obj, nextProp)
Helper for prop to handle object wildcards. It maps over an object's values and extracts a property.
checkPropertyEquality(referenceObject, targetObject)
Checks if all properties and their values in the targetObject exist and are equal in the referenceObject.
getProp(obj, prop)
Safely gets an own property from an object.
isObject(val)
Checks if a value is a plain JavaScript object.
containsValue(valueReference, ...values)
Checks if a value reference exists within a list of values.
valType(val)
Gets a more specific type of a value than typeof.
len(target)
Returns the length or size of the given target based on its type.
update(func, time)
Repeatedly calls a function with a delay until it returns true.
loop(func)
Runs a function on every animation frame until the function returns true.
style(css)
Injects a CSS string into the document by adoptedStyleSheets.
createStyleManager(id)
Creates a manager for a dynamic stylesheet, allowing for easy updates.
hook(owner, methodName, handler)
Intercepts calls to an object's method using a Proxy, allowing modification of its behavior.
watchUrl
An object to execute callbacks based on changes in the page URL, useful for Single Page Applications (SPAs).
watchLocation(callback)
Monitors location.href for changes and triggers a callback.
request(options)
A promise-based wrapper for the Greasemonkey GM_xmlhttpRequest function.
extractProps(element, propsArray)
Extracts data from an element based on an array of property path definitions.
scrape(selector, schema, func, scope)
Scrapes structured data from the DOM based on a selector and a schema.
each(selector, func)
Iterates over all elements matching a selector and applies a function to each.
chain(...iterables)
Chains multiple iterables together into a single sequence.
debounce(func, delay)
Creates a debounced version of a function that delays its execution until after a certain time has passed without it being called.
throttle(func, delay)
Creates a throttled version of a function that only executes once per specified delay.
sleep(ms)
Pauses execution for a specified number of milliseconds.
templates()
Factory function to create a new Templates instance.
lazy(iterable)
Factory function to create a new LazySequence.
interceptEvent(target, eventType, callback)
Adds an event listener that runs during the capturing phase.
createElement(tag, options)
Creates and configures a new HTML element.
accessHTML(html)
Processes an HTML string and provides a structured object for easy access to its elements.
createFromFragment(builderCallback)
Creates a DocumentFragment and populates it using a callback.
createFromHTML(html)
Creates a DocumentFragment from an HTML string, providing structured access to its elements.
withDetached(elementOrSelector, callback)
Detaches an element from the DOM, runs a callback to perform modifications, and then re-attaches it.
getDeepActiveElement(doc)
Gets the currently focused element, traversing into Shadow DOMs.
getDeepElementFromPoint(doc, x, y)
Gets the element at a specific coordinate, traversing into Shadow DOMs.
setInputNativeValue(input, value)
Sets the value of an input element and dispatches a native input event.
simulateTyping(inputElement, text)
Simulates a user typing a string into an input element.
createHotkeys(keys, callback)
Registers a global keyboard shortcut (hotkey).
Contributing
Contributions are welcome! Please open an issue or submit a pull request.
License
This project is licensed under the MIT License.