Skip to content

revolter/min

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

min

Collection of functions used for DOM manipulations in Userscripts.

Development

  • 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, except fix-code and lint-docs.

Documentation

Table of Contents

min

Collection of functions used for DOM manipulations in Userscripts.

Type: Object

NOT_FOUND

Constant used for items not found in search operations.

Type: number

EMPTY

Constant used for empty lists.

Type: number

FIRST

Constant used for accessing the first item in a list.

Type: number

FIRST

Constant used for nodes getter methods to return the first matching node.

Type: number

dom

Collection of DOM manipulation functions.

Type: Object

ALL

Constant used for nodes getter methods to return all the matching nodes.

Type: number

getById

Returns the node by the given id.

Parameters

  • id number The id of the node.

Returns HTMLElement The node with the given id.

getByClassName

Returns the node or the nodes by the given class name.

Parameters

  • 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, default min.dom.FIRST)
  • scope HTMLElement Optional root node in which to search. (optional, default document)
  • rootWindow Window Optional root window of the scope. (optional, default window)

Returns (HTMLElement | HTMLCollection | null) The node or the array of nodes with the given class name or null if scope is not an HTMLElement.

getByTagName

Returns the node or the nodes by the given tag name.

Parameters

  • 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, default min.dom.FIRST)
  • scope HTMLElement Optional root node in which to search. (optional, default document)
  • rootWindow Window Optional root window of the scope. (optional, default window)

Returns (HTMLElement | HTMLCollection | null) The node or the array of nodes with the given tag name or null if scope is not an HTMLElement.

getByQuery

Returns the node or the nodes by the given css query.

Parameters

  • 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, default min.dom.FIRST)
  • scope HTMLElement Optional root node in which to search. (optional, default document)
  • rootWindow Window Optional root window of the scope. (optional, default window)

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.

getByXPath

Returns the node or the nodes by the given xPath location.

Parameters

  • 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, default min.dom.FIRST)
  • scope HTMLElement Optional root node in which to search. (optional, default document)
  • rootWindow Window Optional root window of the scope. (optional, default window)

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.

getByMeta

Returns the node or the nodes by the given attribute name and value.

Parameters

  • propertyName string The attribute name of the node.
  • value string The value of the attribute.

Returns HTMLElement The node with the given attribute name and value.

create

Creates an HTMLElement node.

Parameters

  • tagName string The tag name of the node.
  • attributes Object Optional attributes for the node. (optional, default null)

Returns HTMLElement The requested node.

style

Adds a css style to a node.

Parameters

  • node HTMLElement The node for which to add the style.
  • style Object An object with css property and value pairs.

style

Adds a css style.

Parameters

  • styles Object An object with selector and style pairs.

removeNode

Removes a node.

Parameters

removeNodes

Removes a list of nodes.

Parameters

  • 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 for getterOrNodes.
  • args ...any

insertBefore

Inserts a node before another existing one.

Parameters

  • node HTMLElement The node to be inserted.
  • reference HTMLElement The node before which the specified node will be inserted.

insertAfter

Inserts a node after another existing one.

Parameters

  • node HTMLElement The node to be inserted.
  • reference HTMLElement The node after which the specified node will be inserted.

addObserver

Creates an observer with a given callback.

Parameters

  • callback Function The callback function.
  • root HTMLElement Optional root node on which to observe mutations. (optional, default document.body)
  • options Object Optional parameters to pass to the observer. (optional, default {childList:true,subtree:true})

onNodeExists

Registers a function to be called when a node is first inserted in the DOM.

Parameters

  • 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, default true)

onNodesExist

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

Parameters

  • args Object Object containing the rules for retrieving the nodes.
  • callback Function The callback function.

onNodeInserted

Registers a function to be called when nodes are inserted in the DOM.

Parameters

  • callback Function The callback function.
  • root HTMLElement Optional root node on which to observe mutations. (optional, default document.body)

iframe

Makes an iframe and returns the content document. It also removes it after returning from the callback.

Parameters

  • url string The url for the iframe.
  • callback Function The callback function.
  • scope HTMLElement Optional root node in which to append the iframe. (optional, default document)

gm

Collection of GreaseMonkey specific functions.

Returns Object The collection of functions.

get

Retrieves a stored entry value.

Parameters

  • entryName string The name of the entry.

Returns string The entry's value or empty string.

set

Stores an entry.

Parameters

  • entryName string The name of the entry.
  • value string The value of the entry.

add

Appends an item to the stored entry's value.

Parameters

  • entryName string The name of the entry.
  • item string The item to be appended.

remove

Removes an item from the stored entry's value.

Parameters

  • entryName string The name of the entry.
  • item string The item to be removed.

clear

Removes all the items from the stored entry's value.

Parameters

  • entryName string The name of the entry.

contains

Checks if the stored entry's value contains an item.

Parameters

  • entryName string The name of the entry.
  • item string The item to be searched.

Returns boolean Indicates if the item exists.

read

Reads content from a resource file.

Parameters

  • resourceName string The resource's name.

Returns string The content of the resource file.

xhr

Makes an XMLHttpRequest and returns the response as HTML or raw.

Parameters

  • url string The url of the request.
  • callback Function The callback function.
  • context Object Optional object to be passed to the callback function. (optional, default null)
  • method string Optional request method (defaults to "GET"). (optional, default "GET")
  • headers Object Optional request headers. (optional, default null)
  • raw boolean Indicates if the response should be treated as HTML or not. (optional, default false)

concatenate

Concatenates two collections and returns the result.

Parameters

Returns Array<HTMLElement> The resulting array.

toArray

Converts an array-like object to an Array.

Parameters

  • collection Object The collection to be converted.

Returns Array<Object> The resulting array.

forEach

Executes a function on elements of an array. Return true from the callback to stop the loop.

Parameters

isOnWebsite

Checks if current location is on given host.

Parameters

  • hostName string The hostname to test against.

Returns boolean Indicates if the location is on host.

isOnPath

Checks if current location is on given path.

Parameters

  • path (string | RegExp) The path to test against or a regular expression to test it.
  • exact boolean Pass true to match the exact path. (optional, default false)

Returns boolean Indicates if the location is on path.

isOnIframe

Checks if running from an iframe.

Returns boolean Indicates if the script is running from an iframe.

About

Collection of functions used for DOM manipulations in Userscripts

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published