The GM API that fills in any APIs that GreaseMonkey uses and points them to their CRM counterparts Documentation can be found here http://wiki.greasespot.net/Greasemonkey_Manual:API and here http://tampermonkey.net/documentation.php
Background-page specific APIs
Adds a listener for a keyboard event Not supported in Edge (as of Edge 41)
The keyboard shortcut to listen for
The function to call when a keyboard event occurs
Runs given script on given tab(s)
The id of the script to run
The options for the tab to run it on
Runs this script on given tab(s)
The options for the tab to run it on
An object closely resembling the browser API object. Access the function you want to run through the object and then call it like the chrome API by calling a set of functions on it. You can either call functions by finding them through their respective objects (like crmAPI.browser.alarms.create) or by calling crmAPI.browser.any(api) where api is a string where the apis are separated by dots (for example: crmAPI.browser.any('alarms.create')) There are a few types of functions you can chain-call on the crmAPI.browser.{api} object: a or args or (): uses given arguments as arguments for the API in order specified. When passing a function, it will be converted to a placeholder function that will be called on return with the arguments chrome passed to it. This means the function is never executed on the background page and is always executed here to preserve scope. The arguments are however passed on as they should. You can call this function by calling .args or by just using the parentheses as below. Keep in mind that this function will not work after it has been called once, meaning that if your API calls callbacks multiple times (like chrome.tabs.onCreated) you should use persistent callbacks (see below). p or persistent: a function that is a persistent callback that will not be removed when called. This can be used on APIs like chrome.tabs.onCreated where multiple calls can occurring contrary to chrome.tabs.get where only one callback will occur. s or send: executes the request Examples: - For a function that returns a promise: crmAPI.browser.alarms.get('name').send().then((alarm) => { //Do something with the result here }); - - Or the async version const alarm = await crmAPI.browser.alarms.get('name').send(); - - For a function that returns a value it works the same: crmAPI.browser.runtime.getURL(path).send().then((result) => { //Do something with the result }); - - For a function that uses neither: crmAPI.browser.alarms.create('name', {}).send(); - - Or you can still await it to know when it's done executing crmAPI.browser.alarms.create('name', {}).send(); - - For a function that uses a persistent callback crmAPI.browser.tabs.onCreated.addListener.persistent(function(tab) { //Do something with the tab }).send(); - - A compacter version: const { url } = await crmAPI.browser.tabs.create('name').s(); - Requires permission "chrome" (or "browser", they're the same) and the permission of the the API, so browser.bookmarks requires permission "bookmarks", browser.alarms requires "alarms"
The communications API used to communicate with other scripts and other instances
Adds a listener for any comm-messages sent from other instances of this script
The listener that gets called with the message
An id that can be used to remove the listener
Returns all instances running in other tabs, these instances can be passed to the .comm.sendMessage function to send a message to them, you can also call instance.sendMessage on them
A promise that resolves with the instances
Listen for any messages to the background page
The function to call on message. Contains the message and the respond params respectively. Calling the respond param with data sends a message back.
Sends a message to the background page for this script
The message to send
A promise that resolves with the response
Removes a listener currently added by using comm.addListener
The index of the listener (given by addListener)
Removes a listener currently added by using comm.addListener
The listener to remove
Sends a message to given instance
The ID of the instance to send it to
The message to send
A promise that resolves with the result,
an object that contains the two boolean
values error
and success
indicating whether the message
succeeded. If it did not succeed and an error occurred,
the message key of that object will be filled with the reason
it failed ("instance no longer exists" or "no listener exists")
Sends a message to given instance
The instance to send the message to
The message to send
A promise that resolves with the result,
an object that contains the two boolean
values error
and success
indicating whether the message
succeeded. If it did not succeed and an error occurred,
the message key of that object will be filled with the reason
it failed ("instance no longer exists" or "no listener exists")
Data about the click on the page
The contextMenuItem API which controls the look of this contextmenu item None of these changes are persisted to the source node and only affect the properties of the contextmenu item this session.
Resets the name to the original node name.
A promise that resolves with nothing and throws if something went wrong
Sets whether this item should be checked or not. If the contextmenu item type is either "normal" or "separator", the type is first changed to "checkbox". Is not saved across sessions.
Whether it should be checked
A promise that resolves with nothing and throws if something went wrong
Sets the content types on which this item should appear. This is an array containing the types it should appear on. It will not appear on types that are not in the array. Possible values are "page", "link", "selection", "image", "video" and "audio". Is not saved across sessions.
The content types it should appear on
A promise that resolves with nothing and throws if something went wrong
Sets whether this item should be disabled or not. A disabled node is simply greyed out and can not be clicked. Is not saved across sessions.
Whether it should be disabled
A promise that resolves with nothing and throws if something went wrong
Changes the display name of this item (can't be empty). Requires the "crmContextmenu" permission in order to prevent nodes from pretending to be other nodes. Can be reset to the default name by calling crmAPI.contextMenuItem.resetName. Is not saved across sessions.
The new name
A promise that resolves with nothing and throws if something went wrong
Set the type of this contextmenu item. Options are "normal" for a regular one, "checkbox" for one that can be checked, "radio" for one of many that can be checked and "separator" for a divider line. Is not saved across sessions.
The type to set it to
A promise that resolves with nothing and throws if something went wrong
Sets whether this item should be visible or not. This is only available in chrome 62 and above (no other browsers), won't throw an error if executed on a different browser/version. If this node is invisible by default (for example run on specified), this won't do anything and throw an error. Is not saved across sessions.
Whether it should be visible
A promise that resolves with nothing and throws if something went wrong
The crm API, used to make changes to the crm, some API calls may require permissions crmGet and crmWrite
All functions related specifically to the link type
Gets the links of the node with ID nodeId
The id of the node to get the links from
A promise that resolves with the links
Pushes given items into the array of URLs of node with ID nodeId
The node to push the items to
One item to push
A promise that resolves with the new links array
Pushes given items into the array of URLs of node with ID nodeId
The node to push the items to
An array of items to push
A promise that resolves with the new links array
Gets the links of the node with ID nodeId
The id of the node to get the links from
The item to push
A promise that resolves with the links
Gets the links of the node with ID nodeId
The id of the node to get the links from
The items to push
A promise that resolves with the links
Splices the array of URLs of node with ID nodeId. Start at start
and splices amount
items (just like array.splice)
and returns them as an array in the callback function
The node to splice
The index of the array at which to start splicing
The amount of items to splice
} A promise that resolves with an object containing a
spliced
property, which holds the spliced items, and anewArr
property, holding the new array
All functions related specifically to the menu type
Gets the children of the node with ID nodeId, only works for menu type nodes
The id of the node of which to get the children
A promise that resolves with the children
Pushes the nodes with IDs childrenIds to the node with ID nodeId only works for menu type nodes
The id of the node of which to push the children
Each number in the array represents a node that will be a new child
A promise that resolves with the menu
Sets the children of node with ID nodeId to the nodes with IDs childrenIds only works for menu type nodes
The id of the node of which to set the children
Each number in the array represents a node that will be a new child
A promise that resolves with the menu node
Splices the children of the node with ID nodeId, starting at start
and splicing amount
items,
the removed items will be put in the root of the tree instead
only works for menu type nodes
The id of the node of which to splice the children
The index at which to start
The amount to splice
} A promise that resolves with an object that contains a
spliced
property, which contains the spliced children and anewArr
property containing the new children array
All functions related specifically to the background script's libraries
Pushes given libraries to the node with ID nodeId's libraries array, make sure to register them first or an error is thrown, only works on script nodes
The node to edit
One library to push
The name of the library
A promise that resolves with the new libraries
Pushes given libraries to the node with ID nodeId's libraries array, make sure to register them first or an error is thrown, only works on script nodes
The node to edit
An array of libraries to push
A promise that resolves with the new libraries
Splices the array of libraries of node with ID nodeId. Start at start
and splices amount
items (just like array.splice)
and returns them as an array in the callback function, only works on script nodes
The node to splice
The index of the array at which to start splicing
The amount of items to splice
} A promise that resolves with an object that contains a
spliced
property, which contains the spliced items and anewArr
property containing the new array
Pushes given libraries to the node with ID nodeId's libraries array, make sure to register them first or an error is thrown, only works on script nodes
The node to edit
One library to push
The name of the library
A promise that resolves with the new libraries
Pushes given libraries to the node with ID nodeId's libraries array, make sure to register them first or an error is thrown, only works on script nodes
The node to edit
An array of libraries to push
A promise that resolves with the new libraries
Splices the array of libraries of node with ID nodeId. Start at start
and splices amount
items (just like array.splice)
and returns them as an array in the callback function, only works on script nodes
The node to splice
The index of the array at which to start splicing
The amount of items to splice
} A promise that resolves with an object that contains a
spliced
property, which contains the spliced items and anewArr
property containing the new array
Gets the value of the backgroundScript
The id of the node of which to get the backgroundScript
A promise that resolves with the backgroundScript
Gets the value of the script
The id of the node of which to get the script
A promise that resolves with the script
Sets the backgroundScript of node with ID nodeId to value script
The node of which to change the script
The code to change to
A promise that resolves with the node
Sets the script of node with ID nodeId to value script
The node of which to change the script
The code to change to
A promise that resolves with the new node
All functions related specifically to the stylesheet type
Gets the value of the stylesheet
The id of the node of which to get the stylesheet
A promise that resolves with the stylesheet
Sets the stylesheet of node with ID nodeId to value stylesheet
The node of which to change the stylesheet
The code to change to
A promise that resolves with the node
Copies given node including children, WARNING: following properties are not copied: file, storage, id, permissions, nodeInfo Full permissions rights only if both the to be cloned and the script executing this have full rights
The id of the node to copy
An object containing all the options for the node
The name of the new node (defaults to "name")
The position to copy it to
A promise that resolves with the copied node
Copies given node including children, WARNING: following properties are not copied: file, storage, id, permissions, nodeInfo Full permissions rights only if both the to be cloned and the script executing this have full rights
The id of the node to copy
An object containing all the options for the node
The name of the new node (defaults to "name")
The position to copy it to
A promise that resolves with the copied node
Deletes given node
The id of the node to delete
A promise that resolves with an error message or the success status
Edits given settings of the node
The id of the node to edit
An object containing the settings for what to edit
The new name of the node
The new type of the node
A promise that resolves with the edited node
Edits given settings of the node
The id of the node to edit
An object containing the settings for what to edit
The new name of the node
The new type of the node
A promise that resolves with the edited node
Gets the content types for given node
The node of which to get the content types
A promise that resolves with the content types
Gets the launchMode of the node with ID nodeId
The id of the node to get the launchMode of
A promise that resolves with the launchMode
Gets the node with ID nodeId
A promise that resolves with the node
Gets a node's ID from a path to the node
An array of numbers representing the path, each number represents the n-th child of the current node, so [1,2] represents the 2nd item(0,>1<,2)'s third child (0,1,>2<,3)
A promise that resolves with the ID
Gets the type of node with ID nodeId
The id of the node whose type to get
A promise that resolves with the type of the node
Gets the value of node with ID nodeId
The id of the node whose value to get
A promise that resolves with the value of the node
Gets the parent of the node with ID nodeId
The node of which to get the parent
A callback with the parent of the given node as an argument
A promise that resolves with the parent of given node
Gets the root contextmenu ID (used by browser.contextMenus). Keep in mind that this is not a node id. See: https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/menus
A promise that resolves with the ID
Gets the CRM's tree from either the root or from the node with ID nodeId
The ID of the subtree's root node
A function that is called when done with the data as an argument
A promise that resolves with the subtree
Gets the CRM tree from the tree's root
A promise that resolves with the tree
Gets the trigger' usage for given node (true - it's being used, or false), only works on link, menu and divider
The node of which to get the triggers
A promise that resolves with a boolean indicating whether triggers are used
Gets the triggers for given node
The node of which to get the triggers
A promise that resolves with the triggers
Moves given node to position specified in position
The id of the node to move
A promise that resolves with the moved node
Queries the CRM for any items matching your query
The query to look for
The function to call when done, returns one array of results
A promise that resolves with the resulting nodes
Sets the content type at index index
to given value value
The node whose content types to set
The index of the array to set, 0-5, ordered this way: page, link, selection, image, video, audio. Can also be the name of the index (one of those words)
The new value at index index
A promise that resolves with the new content types
Sets the content types to given contentTypes array
The node whose content types to set
An array of number, if an index is true, it's displayed at that index's value
A promise that resolves with the node
Sets the launch mode of node with ID nodeId to launchMode
The node to edit
The new launchMode, which is the time at which this script/stylesheet runs 0 = run on clicking 1 = always run 2 = run on specified pages 3 = only show on specified pages 4 = disabled
A promise that resolves with the node
Sets the usage of triggers for given node, only works on link, menu and divider
The node of which to get the triggers
Whether the triggers should be used or not
A promise that resolves with the node
Sets the triggers for given node
The node of which to get the triggers
The triggers that launch this node, automatically turns triggers on
A promise that resolves with the node
The tabIndex of this instance
If true, when an error occurs anywhere in the script, opens the
chrome debugger by calling the debugger command. This does
not preserve the stack or values. If you want that, use the
catchErrors
option on the options page.
If true, throws an error when one of your crmAPI calls is incorrect (such as a type mismatch or any other fail). True by default.
The ID of this node
The ID of this instance of this script. Can be used to filter it from all instances or to send to another instance.
Whether this script is running on the backgroundpage
Is set if a chrome call triggered an error, otherwise unset
The libraries API used to register libraries
Registers a library with name name
The name to give the library
The options related to the library (fill at least one)
The code to use
Whether the library uses the typescript language
The URL to fetch the code from
A promise that resolves with the new library
If set, calls this function when an error occurs
All permissions that are allowed on this script
When true, shows stacktraces on error in the console of the page the script runs on, true by default.
The storage API used to store and retrieve data for this script
Functions related to the onChange event of the storage API
Adds an onchange listener for the storage, listens for a key if given
The function to run, gets called gets called with the first argument being the key, the second being the old value, the third being the new value and the fourth a boolean indicating if the change was on a remote tab
A number that can be used to remove the listener
Removes ALL listeners with given listener (function) as the listener, if key is given also checks that they have that key
The number of the listener to remove (given by addListener)
Removes ALL listeners with given listener (function) as the listener, if key is given also checks that they have that key
The listener to remove
Gets the value at given key, if no key is given returns the entire storage object
Gets the value at given key, if no key is given returns the entire storage object
Deletes the data at given key given value
The path at which to look, a string separated with dots
Deletes the data at given key given value
The path at which to look, an array of strings and numbers representing keys
Sets the data at given key given value
The path at which to look, a string separated with dots
Sets the data at given key given value
The path at which to look, an array of strings and numbers representing keys
The storage API used to store and retrieve data for this script
Functions related to the onChange event of the storage API
Adds an onchange listener for the storage, listens for a key if given
The function to run, gets called gets called with the first argument being the key, the second being the old value, the third being the new value and the fourth a boolean indicating if the change was on a remote tab
A number that can be used to remove the listener
Removes ALL listeners with given listener (function) as the listener, if key is given also checks that they have that key
The number of the listener to remove (given by addListener)
Removes ALL listeners with given listener (function) as the listener, if key is given also checks that they have that key
The listener to remove
Gets the value at given key, if no key is given returns the entire storage object
Gets the value at given key, if no key is given returns the entire storage object
Deletes the data at given key given value
The path at which to look, a string separated with dots
Deletes the data at given key given value
The path at which to look, an array of strings and numbers representing keys
Sets the data at given key given value
The path at which to look, a string separated with dots
Sets the data at given key given value
The path at which to look, an array of strings and numbers representing keys
The ID of the the tab this script is running on
When true, warns you after 5 seconds of not sending a chrome function that you probably forgot to send it
Returns the elements matching given selector within given context
A css selector string to find elements with
An array of the matching HTML elements
Returns the elements matching given selector within given context
A css selector string to find elements with
An array of the matching HTML elements
Calls the chrome API given in the API
parameter. Due to some issues with the chrome message passing
API it is not possible to pass messages and preserve scope. This could be fixed in other ways but
unfortunately chrome.tabs.executeScript (what is used to execute scripts on the page) runs in a
sandbox and does not allow you to access a lot. As a solution to this there are a few types of
functions you can chain-call on the crmAPI.chrome(API) object:
a or args or (): uses given arguments as arguments for the API in order specified. When passing a function, it will be converted to a placeholder function that will be called on return with the arguments chrome passed to it. This means the function is never executed on the background page and is always executed here to preserve scope. The arguments are however passed on as they should. You can call this function by calling .args or by just using the parentheses as below. Keep in mind that this function will not work after it has been called once, meaning that if your API calls callbacks multiple times (like chrome.tabs.onCreated) you should use persistent callbacks (see below).
r or return: a function that is called with the value that the chrome API returned. This can be used for APIs that don't use callbacks and instead just return values such as chrome.runtime.getURL().
p or persistent: a function that is a persistent callback that will not be removed when called. This can be used on APIs like chrome.tabs.onCreated where multiple calls can occurring contrary to chrome.tabs.get where only one callback will occur.
s or send: executes the request Examples:
// For a function that uses a callback:
crmAPI.chrome('alarms.get')('name', function(alarm) {
//Do something with the result here
}).send();
// For a function that returns a value:
crmAPI.chrome('runtime.getUrl')(path).return(function(result) {
//Do something with the result
}).send();
// For a function that uses neither:
crmAPI.chrome('alarms.create')('name', {}).send();
// For a function that uses a persistent callback
crmAPI.chrome('tabs.onCreated.addListener').persistent(function(tab) {
//Do something with the tab
}).send();
// A compacter version:
crmAPI.chrome('runtime.getUrl')(path).r(function(result) {
//Do something with the result
}).s();
Requires permission chrome
and the permission of the the API, so chrome.bookmarks requires
permission bookmarks
, chrome.alarms requires alarms
The API to use
.args
, .fn
, .return
and
.send
and their first-letter-only versions (.a
, .f
, .r
and .s
)Fetches resource at given url. If this keeps failing with a CORB error, try crmAPI.fetchBackground
The url to fetch the data from
A promise that resolves to the content
Fetches resource at given url through the background-page, bypassing any CORS or CORB-like blocking
The url to fetch the data from
A promise that resolves to the content
Returns any data about the click on the page, check (https://developer.chrome.com/extensions/contextMenus#method-create) for more info of what can be returned.
Gets the current node
Gets the current text selection
Gets the current text selection
Gets any info about the current tab/window
Logs given arguments to the background page and logger page
Returns the options for this script/stylesheet. Any missing values are filled in with the corresponding field in the 'defaults' param
Generated using TypeDoc
A class for constructing the CRM API