Collection of functions used for DOM manipulations in Userscripts.
- Run
npm install
to install the dependencies. - Run
npm run lint-code
to check for errors in the code. - Run
npm run fix-code
to fix errors in the code. - Run
npm run build-code
to update the minified version. - Run
npm run lint-docs
to check for errors in the documentation. - Run
npm run build-docs
to update the documentation. - Run
npm run build
to run all the scripts at the same time, exceptfix-code
andlint-docs
.
- min
- NOT_FOUND
- EMPTY
- FIRST
- FIRST
- dom
- ALL
- getById
- getByClassName
- getByTagName
- getByQuery
- getByXPath
- getByMeta
- create
- style
- style
- removeNode
- removeNodes
- insertBefore
- insertAfter
- addObserver
- onNodeExists
- onNodesExist
- onNodeInserted
- iframe
- gm
- get
- set
- add
- remove
- clear
- contains
- read
- xhr
- concatenate
- toArray
- forEach
- isOnWebsite
- isOnPath
- isOnIframe
Collection of functions used for DOM manipulations in Userscripts.
Type: Object
Constant used for items not found in search operations.
Type: number
Constant used for empty lists.
Type: number
Constant used for accessing the first item in a list.
Type: number
Constant used for nodes getter methods to return the first matching node.
Type: number
Collection of DOM manipulation functions.
Type: Object
Constant used for nodes getter methods to return all the matching nodes.
Type: number
Returns the node by the given id.
id
number The id of the node.
Returns HTMLElement The node with the given id.
Returns the node or the nodes by the given class name.
className
string The class name of the node.index
number Optional position of the node in the array of those found (defaults to the first one). (optional, defaultmin.dom.FIRST
)scope
HTMLElement Optional root node in which to search. (optional, defaultdocument
)rootWindow
Window Optional root window of the scope. (optional, defaultwindow
)
Returns (HTMLElement | HTMLCollection | null) The node or the array of nodes with the given class name or null if scope is not an HTMLElement.
Returns the node or the nodes by the given tag name.
tagName
string The tag name of the node.index
number Optional position of the node in the array of those found (defaults to the first one). (optional, defaultmin.dom.FIRST
)scope
HTMLElement Optional root node in which to search. (optional, defaultdocument
)rootWindow
Window Optional root window of the scope. (optional, defaultwindow
)
Returns (HTMLElement | HTMLCollection | null) The node or the array of nodes with the given tag name or null if scope is not an HTMLElement.
Returns the node or the nodes by the given css query.
query
string The query string for searching the node.index
number Optional position of the node in the array of those found (defaults to the first one). (optional, defaultmin.dom.FIRST
)scope
HTMLElement Optional root node in which to search. (optional, defaultdocument
)rootWindow
Window Optional root window of the scope. (optional, defaultwindow
)
Returns (HTMLElement | Array<HTMLElement> | null) The node or the array of nodes with the given css query or null if scope is not an HTMLElement.
Returns the node or the nodes by the given xPath location.
xPath
string The xPath location the node.index
number Optional position of the node in the array of those found (defaults to the first one). (optional, defaultmin.dom.FIRST
)scope
HTMLElement Optional root node in which to search. (optional, defaultdocument
)rootWindow
Window Optional root window of the scope. (optional, defaultwindow
)
Returns (HTMLElement | Array<HTMLElement> | null) The node or the array of nodes with the given xPath location or null if scope is not an HTMLElement.
Returns the node or the nodes by the given attribute name and value.
Returns HTMLElement The node with the given attribute name and value.
Creates an HTMLElement node.
tagName
string The tag name of the node.attributes
Object Optional attributes for the node. (optional, defaultnull
)
Returns HTMLElement The requested node.
Adds a css style to a node.
node
HTMLElement The node for which to add the style.style
Object An object with css property and value pairs.
Adds a css style.
styles
Object An object with selector and style pairs.
Removes a node.
node
HTMLElement The node to be removed.
Removes a list of nodes.
getterOrNodes
(Function | Array<HTMLElement>) Getter function for the node or a list of nodes to be removed.paramOrParams
(string | Array<string> | HTMLElement)? Parameter or parameters needed for the getter. Optional if a list of nodes is passed forgetterOrNodes
.args
...any
Inserts a node before another existing one.
node
HTMLElement The node to be inserted.reference
HTMLElement The node before which the specified node will be inserted.
Inserts a node after another existing one.
node
HTMLElement The node to be inserted.reference
HTMLElement The node after which the specified node will be inserted.
Creates an observer with a given callback.
callback
Function The callback function.root
HTMLElement Optional root node on which to observe mutations. (optional, defaultdocument.body
)options
Object Optional parameters to pass to the observer. (optional, default{childList:true,subtree:true}
)
Registers a function to be called when a node is first inserted in the DOM.
getter
Function Getter function for the node.paramOrParams
(string | Array<string>) Parameter or parameters needed for the getter.callback
Function The callback function.disconnect
boolean Set to false to prevent the observer to disconnect after the node is found. (optional, defaulttrue
)
Registers a function to be called when some nodes are first inserted in the DOM.
The args
must contains these keys:
{Function}
getter{string[]}
params
or
{string[][]}
rules
args
Object Object containing the rules for retrieving the nodes.callback
Function The callback function.
Registers a function to be called when nodes are inserted in the DOM.
callback
Function The callback function.root
HTMLElement Optional root node on which to observe mutations. (optional, defaultdocument.body
)
Makes an iframe and returns the content document. It also removes it after returning from the callback.
url
string The url for the iframe.callback
Function The callback function.scope
HTMLElement Optional root node in which to append the iframe. (optional, defaultdocument
)
Collection of GreaseMonkey specific functions.
Returns Object The collection of functions.
Retrieves a stored entry value.
entryName
string The name of the entry.
Returns string The entry's value or empty string.
Stores an entry.
Appends an item to the stored entry's value.
Removes an item from the stored entry's value.
Removes all the items from the stored entry's value.
entryName
string The name of the entry.
Checks if the stored entry's value contains an item.
Returns boolean Indicates if the item exists.
Reads content from a resource file.
resourceName
string The resource's name.
Returns string The content of the resource file.
Makes an XMLHttpRequest and returns the response as HTML or raw.
url
string The url of the request.callback
Function The callback function.context
Object Optional object to be passed to the callback function. (optional, defaultnull
)method
string Optional request method (defaults to "GET"). (optional, default"GET"
)headers
Object Optional request headers. (optional, defaultnull
)raw
boolean Indicates if the response should be treated as HTML or not. (optional, defaultfalse
)
Concatenates two collections and returns the result.
first
(Array<HTMLElement> | HTMLCollection) The first collection.second
(Array<HTMLElement> | HTMLCollection) The second collection.
Returns Array<HTMLElement> The resulting array.
Converts an array-like object to an Array.
collection
Object The collection to be converted.
Returns Array<Object> The resulting array.
Executes a function on elements of an array.
Return true
from the callback
to stop the loop.
Checks if current location is on given host.
hostName
string The hostname to test against.
Returns boolean Indicates if the location is on host.
Checks if current location is on given path.
path
(string | RegExp) The path to test against or a regular expression to test it.exact
boolean Passtrue
to match the exact path. (optional, defaultfalse
)
Returns boolean Indicates if the location is on path.
Checks if running from an iframe.
Returns boolean Indicates if the script is running from an iframe.