Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Instance

A class for constructing the CRM API

class

Hierarchy

  • Instance

Index

Constructors

constructor

Properties

GM

GM: GM_Fns

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

background: object

Background-page specific APIs

type

Object

Type declaration

  • addKeyboardListener: function
    • addKeyboardListener(key: string, callback: function): void
    • Adds a listener for a keyboard event Not supported in Edge (as of Edge 41)

      Parameters

      • key: string

        The keyboard shortcut to listen for

      • callback: function

        The function to call when a keyboard event occurs

          • (): void
          • Returns void

      Returns void

  • runScript: function
  • runSelf: function

browser

browser: crmbrowser | object

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"

permission

chrome

permission

browser

returns
  • An object on which you can call .args, .fn and .send
      (and their first-letter-only versions)

comm

comm: object

The communications API used to communicate with other scripts and other instances

type

Object

Type declaration

  • addListener: function
    • Adds a listener for any comm-messages sent from other instances of this script

      Parameters

      Returns number

      An id that can be used to remove the listener

  • getInstances: function
    • getInstances(callback?: function): Promise<CommInstance[]>
    • 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

      Parameters

      • Optional callback: function
          • (instances: CommInstance[]): void
          • Parameters

            • instances: CommInstance[]

            Returns void

      Returns Promise<CommInstance[]>

      A promise that resolves with the instances

  • listenAsBackgroundPage: function
    • Listen for any messages to the background page

      Parameters

      • callback: RespondableInstanceListener

        The function to call on message. Contains the message and the respond params respectively. Calling the respond param with data sends a message back.

      Returns void

  • messageBackgroundPage: function
  • removeListener: function
    • removeListener(listener: number): void
    • removeListener(listener: InstanceListener): void
  • sendMessage: function
    • Sends a message to given instance

      Parameters

      • instance: number

        The ID of the instance to send it to

      • message: any

        The message to send

      • Optional callback: InstanceCallback

      Returns Promise<InstanceCallback>

      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

      Parameters

      Returns Promise<InstanceCallback>

      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")

contextData

contextData: ContextData

Data about the click on the page

contextMenuItem

contextMenuItem: object

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.

Type declaration

  • resetName: function
    • resetName(allTabs?: boolean): Promise<void>
    • Resets the name to the original node name.

      Parameters

      • Optional allTabs: boolean

      Returns Promise<void>

      A promise that resolves with nothing and throws if something went wrong

  • setChecked: function
    • setChecked(checked: boolean, allTabs?: boolean): Promise<void>
    • 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.

      Parameters

      • checked: boolean

        Whether it should be checked

      • Optional allTabs: boolean

      Returns Promise<void>

      A promise that resolves with nothing and throws if something went wrong

  • setContentTypes: function
    • setContentTypes(contentTypes: ContentTypeString[], allTabs?: boolean): Promise<void>
    • 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.

      Parameters

      • contentTypes: ContentTypeString[]

        The content types it should appear on

      • Optional allTabs: boolean

      Returns Promise<void>

      A promise that resolves with nothing and throws if something went wrong

  • setDisabled: function
    • setDisabled(isDisabled: boolean, allTabs?: boolean): Promise<void>
    • 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.

      Parameters

      • isDisabled: boolean

        Whether it should be disabled

      • Optional allTabs: boolean

      Returns Promise<void>

      A promise that resolves with nothing and throws if something went wrong

  • setName: function
    • setName(name: string, allTabs?: boolean): Promise<void>
    • 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.

      permission

      crmContextmenu

      Parameters

      • name: string

        The new name

      • Optional allTabs: boolean

      Returns Promise<void>

      A promise that resolves with nothing and throws if something went wrong

  • setType: function
    • 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.

      Parameters

      Returns Promise<void>

      A promise that resolves with nothing and throws if something went wrong

  • setVisibility: function
    • setVisibility(isVisible: boolean, allTabs?: boolean): Promise<void>
    • 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.

      Parameters

      • isVisible: boolean

        Whether it should be visible

      • Optional allTabs: boolean

      Returns Promise<void>

      A promise that resolves with nothing and throws if something went wrong

crm

crm: object

The crm API, used to make changes to the crm, some API calls may require permissions crmGet and crmWrite

type

Object

Type declaration

  • link: object

    All functions related specifically to the link type

    • getLinks: function
      • Gets the links of the node with ID nodeId

        permission

        crmGet

        Parameters

        • nodeId: NodeIdAssignable

          The id of the node to get the links from

        • Optional callback: function
            • (result: LinkNodeLink[]): void
            • Parameters

              • result: LinkNodeLink[]

              Returns void

        Returns Promise<LinkNodeLink[]>

        A promise that resolves with the links

    • push: function
      • Pushes given items into the array of URLs of node with ID nodeId

        permission

        crmGet

        permission

        crmWrite

        Parameters

        • nodeId: NodeIdAssignable

          The node to push the items to

        • items: LinkNodeLink

          One item to push

        • Optional callback: function
            • (arr: LinkNodeLink[]): void
            • Parameters

              • arr: LinkNodeLink[]

              Returns void

        Returns Promise<LinkNodeLink[]>

        A promise that resolves with the new links array

      • Pushes given items into the array of URLs of node with ID nodeId

        permission

        crmGet

        permission

        crmWrite

        Parameters

        • nodeId: NodeIdAssignable

          The node to push the items to

        • items: LinkNodeLink[]

          An array of items to push

        • Optional callback: function
            • (arr: LinkNodeLink[]): void
            • Parameters

              • arr: LinkNodeLink[]

              Returns void

        Returns Promise<LinkNodeLink[]>

        A promise that resolves with the new links array

    • setLinks: function
      • Gets the links of the node with ID nodeId

        permission

        crmGet

        permission

        crmWrite

        Parameters

        • nodeId: NodeIdAssignable

          The id of the node to get the links from

        • item: LinkNodeLink

          The item to push

        • Optional callback: function
            • (arr: LinkNodeLink[]): void
            • Parameters

              • arr: LinkNodeLink[]

              Returns void

        Returns Promise<LinkNodeLink[]>

        A promise that resolves with the links

      • Gets the links of the node with ID nodeId

        permission

        crmGet

        permission

        crmWrite

        Parameters

        • nodeId: NodeIdAssignable

          The id of the node to get the links from

        • items: LinkNodeLink[]

          The items to push

        • Optional callback: function
            • (arr: LinkNodeLink[]): void
            • Parameters

              • arr: LinkNodeLink[]

              Returns void

        Returns Promise<LinkNodeLink[]>

        A promise that resolves with the links

    • splice: function
      • 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

        permission

        crmGet

        permission

        crmWrite

        Parameters

        • nodeId: NodeIdAssignable

          The node to splice

        • start: number

          The index of the array at which to start splicing

        • amount: number

          The amount of items to splice

        • Optional callback: function
            • (spliced: LinkNodeLink[], newArr: LinkNodeLink[]): void
            • Parameters

              • spliced: LinkNodeLink[]
              • newArr: LinkNodeLink[]

              Returns void

        Returns Promise<object>

        } A promise that resolves with an object containing a spliced property, which holds the spliced items, and a newArr property, holding the new array

  • menu: object

    All functions related specifically to the menu type

    • getChildren: function
      • Gets the children of the node with ID nodeId, only works for menu type nodes

        permission

        crmGet

        Parameters

        • nodeId: NodeIdAssignable

          The id of the node of which to get the children

        • Optional callback: function
            • (nodes: SafeNode[]): void
            • Parameters

              • nodes: SafeNode[]

              Returns void

        Returns Promise<SafeNode[]>

        A promise that resolves with the children

    • push: function
      • Pushes the nodes with IDs childrenIds to the node with ID nodeId only works for menu type nodes

        permission

        crmGet

        permission

        crmWrite

        Type parameters

        Parameters

        • nodeId: NodeId<T>

          The id of the node of which to push the children

        • childrenIds: NodeIdAssignable[]

          Each number in the array represents a node that will be a new child

        • Optional callback: function
            • (node: T): void
            • Parameters

              • node: T

              Returns void

        Returns Promise<T>

        A promise that resolves with the menu

      • Parameters

        Returns Promise<SafeNode>

    • setChildren: function
      • Sets the children of node with ID nodeId to the nodes with IDs childrenIds only works for menu type nodes

        permission

        crmGet

        permission

        crmWrite

        Type parameters

        Parameters

        • nodeId: NodeId<T>

          The id of the node of which to set the children

        • childrenIds: NodeIdAssignable[]

          Each number in the array represents a node that will be a new child

        • Optional callback: function
            • (node: T): void
            • Parameters

              • node: T

              Returns void

        Returns Promise<T>

        A promise that resolves with the menu node

      • Parameters

        Returns Promise<SafeNode>

    • splice: function
      • 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

        permission

        crmGet

        permission

        crmWrite

        Parameters

        • nodeId: NodeIdAssignable

          The id of the node of which to splice the children

        • start: number

          The index at which to start

        • amount: number

          The amount to splice

        • Optional callback: function
            • (spliced: SafeNode[], newArr: SafeNode[]): void
            • Parameters

              • spliced: SafeNode[]
              • newArr: SafeNode[]

              Returns void

        Returns Promise<object>

        } A promise that resolves with an object that contains a spliced property, which contains the spliced children and a newArr property containing the new children array

  • script: object
    • backgroundLibraries: object

      All functions related specifically to the background script's libraries

      • push: function
        • 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

          permission

          crmGet

          permission

          crmWrite

          Parameters

          • nodeId: NodeIdAssignable

            The node to edit

          • libraries: object

            One library to push

            • name: string

              The name of the library

          • Optional callback: function
              • (libs: Library[]): void
              • Parameters

                • libs: Library[]

                Returns void

          Returns Promise<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

          permission

          crmGet

          permission

          crmWrite

          Parameters

          • nodeId: NodeIdAssignable

            The node to edit

          • libraries: object[]

            An array of libraries to push

          • Optional callback: function
              • (libs: Library[]): void
              • Parameters

                • libs: Library[]

                Returns void

          Returns Promise<Library[]>

          A promise that resolves with the new libraries

      • splice: function
        • 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

          permission

          crmGet

          permission

          crmWrite

          Parameters

          • nodeId: NodeIdAssignable

            The node to splice

          • start: number

            The index of the array at which to start splicing

          • amount: number

            The amount of items to splice

          • Optional callback: function
              • (spliced: Library[], newArr: Library[]): void
              • Parameters

                • spliced: Library[]
                • newArr: Library[]

                Returns void

          Returns Promise<object>

          } A promise that resolves with an object that contains a spliced property, which contains the spliced items and a newArr property containing the new array

    • libraries: object
      • push: function
        • 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

          permission

          crmGet

          permission

          crmWrite

          Parameters

          • nodeId: NodeIdAssignable

            The node to edit

          • libraries: object

            One library to push

            • name: string

              The name of the library

          • Optional callback: function
              • (libs: Library[]): void
              • Parameters

                • libs: Library[]

                Returns void

          Returns Promise<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

          permission

          crmGet

          permission

          crmWrite

          Parameters

          • nodeId: NodeIdAssignable

            The node to edit

          • libraries: object[]

            An array of libraries to push

          • Optional callback: function
              • (libs: Library[]): void
              • Parameters

                • libs: Library[]

                Returns void

          Returns Promise<Library[]>

          A promise that resolves with the new libraries

      • splice: function
        • 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

          permission

          crmGet

          permission

          crmWrite

          Parameters

          • nodeId: NodeIdAssignable

            The node to splice

          • start: number

            The index of the array at which to start splicing

          • amount: number

            The amount of items to splice

          • Optional callback: function
              • (spliced: Library[], newArr: Library[]): void
              • Parameters

                • spliced: Library[]
                • newArr: Library[]

                Returns void

          Returns Promise<object>

          } A promise that resolves with an object that contains a spliced property, which contains the spliced items and a newArr property containing the new array

    • getBackgroundScript: function
      • Gets the value of the backgroundScript

        permission

        crmGet

        Parameters

        • nodeId: NodeIdAssignable

          The id of the node of which to get the backgroundScript

        • Optional callback: function
            • (backgroundScript: string): void
            • Parameters

              • backgroundScript: string

              Returns void

        Returns Promise<string>

        A promise that resolves with the backgroundScript

    • getScript: function
      • Gets the value of the script

        permission

        crmGet

        Parameters

        • nodeId: NodeIdAssignable

          The id of the node of which to get the script

        • Optional callback: function
            • (script: string): void
            • Parameters

              • script: string

              Returns void

        Returns Promise<string>

        A promise that resolves with the script

    • setBackgroundScript: function
    • setScript: function
  • stylesheet: object

    All functions related specifically to the stylesheet type

    • getStylesheet: function
      • Gets the value of the stylesheet

        permission

        crmGet

        Parameters

        • nodeId: NodeIdAssignable

          The id of the node of which to get the stylesheet

        • Optional callback: function
            • (stylesheet: string): void
            • Parameters

              • stylesheet: string

              Returns void

        Returns Promise<string>

        A promise that resolves with the stylesheet

    • setStylesheet: function
  • copyNode: function
    • 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

      permission

      crmGet

      permission

      crmWrite

      Type parameters

      Parameters

      • nodeId: NodeId<T>

        The id of the node to copy

      • options: object

        An object containing all the options for the node

        • Optional name?: U

          The name of the new node (defaults to "name")

        • Optional position?: Relation

          The position to copy it to

      • Optional callback: function
          • (node: T | object): void
          • Parameters

            • node: T | object

            Returns void

      Returns Promise<T | object>

      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

      permission

      crmGet

      permission

      crmWrite

      Parameters

      • nodeId: NodeIdAssignable

        The id of the node to copy

      • options: object

        An object containing all the options for the node

        • Optional name?: string

          The name of the new node (defaults to "name")

        • Optional position?: Relation

          The position to copy it to

      • Optional callback: function

      Returns Promise<SafeNode>

      A promise that resolves with the copied node

  • createNode: function
  • deleteNode: function
    • Deletes given node

      permission

      crmGet

      permission

      crmWrite

      Parameters

      • nodeId: NodeIdAssignable

        The id of the node to delete

      • Optional callback: function
          • (errorMessage: string): void
          • Parameters

            • errorMessage: string

            Returns void

      Returns Promise<string>

      A promise that resolves with an error message or the success status

    • Parameters

      • nodeId: NodeIdAssignable
      • Optional callback: function
          • (successStatus: boolean): void
          • Parameters

            • successStatus: boolean

            Returns void

      Returns Promise<boolean>

  • editNode: function
    • Edits given settings of the node

      permission

      crmGet

      permission

      crmWrite

      Type parameters

      Parameters

      • nodeId: NodeId<T>

        The id of the node to edit

      • options: object

        An object containing the settings for what to edit

        • Optional name?: U

          The new name of the node

        • Optional type?: NT

          The new type of the node

      • Optional callback: function
          • (node: T | object): void
          • Parameters

            • node: T | object

            Returns void

      Returns Promise<T | object>

      A promise that resolves with the edited node

    • Edits given settings of the node

      permission

      crmGet

      permission

      crmWrite

      Parameters

      • nodeId: NodeIdAssignable

        The id of the node to edit

      • options: object

        An object containing the settings for what to edit

        • Optional name?: string

          The new name of the node

        • Optional type?: NodeType

          The new type of the node

      • Optional callback: function

      Returns Promise<SafeNode>

      A promise that resolves with the edited node

  • getContentTypes: function
  • getLaunchMode: function
  • getNode: function
  • getNodeIdFromPath: function
    • Gets a node's ID from a path to the node

      permission

      crmGet

      Parameters

      • path: number[]

        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)

      • Optional callback: function

      Returns Promise<NodeIdAssignable>

      A promise that resolves with the ID

  • getNodeType: function
  • getNodeValue: function
  • getParentNode: function
    • Gets the parent of the node with ID nodeId

      permission

      crmGet

      Parameters

      • nodeId: NodeIdAssignable

        The node of which to get the parent

      • Optional callback: function

        A callback with the parent of the given node as an argument

          • Parameters

            Returns void

      Returns Promise<SafeNode | SafeNode[]>

      A promise that resolves with the parent of given node

  • getRootContextMenuId: function
    • getRootContextMenuId(callback?: function): Promise<string | number>
  • getSubTree: function
    • Gets the CRM's tree from either the root or from the node with ID nodeId

      permission

      crmGet

      Parameters

      • nodeId: NodeIdAssignable

        The ID of the subtree's root node

      • Optional callback: function

        A function that is called when done with the data as an argument

          • (data: SafeNode[]): void
          • Parameters

            • data: SafeNode[]

            Returns void

      Returns Promise<SafeNode[]>

      A promise that resolves with the subtree

  • getTree: function
    • getTree(callback?: function): Promise<SafeNode[]>
    • Gets the CRM tree from the tree's root

      permission

      crmGet

      Parameters

      • Optional callback: function
          • (data: SafeNode[]): void
          • Parameters

            • data: SafeNode[]

            Returns void

      Returns Promise<SafeNode[]>

      A promise that resolves with the tree

  • getTriggerUsage: function
    • Gets the trigger' usage for given node (true - it's being used, or false), only works on link, menu and divider

      permission

      crmGet

      Parameters

      • nodeId: NodeIdAssignable

        The node of which to get the triggers

      • Optional callback: function
          • (usage: boolean): void
          • Parameters

            • usage: boolean

            Returns void

      Returns Promise<boolean>

      A promise that resolves with a boolean indicating whether triggers are used

  • getTriggers: function
    • Gets the triggers for given node

      permission

      crmGet

      Parameters

      • nodeId: NodeIdAssignable

        The node of which to get the triggers

      • Optional callback: function
          • (triggers: Trigger[]): void
          • Parameters

            • triggers: Trigger[]

            Returns void

      Returns Promise<Trigger[]>

      A promise that resolves with the triggers

  • moveNode: function
  • queryCrm: function
    • Queries the CRM for any items matching your query

      permission

      crmGet

      Parameters

      • query: CRMQuery

        The query to look for

      • Optional callback: function

        The function to call when done, returns one array of results

          • (results: SafeNode[]): void
          • Parameters

            • results: SafeNode[]

            Returns void

      Returns Promise<SafeNode[]>

      A promise that resolves with the resulting nodes

  • setContentType: function
  • setContentTypes: function
  • setLaunchMode: function
  • setTriggerUsage: function
  • setTriggers: function

currentTabIndex

currentTabIndex: TabIndex

The tabIndex of this instance

debugOnerror

debugOnerror: boolean

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.

errors

errors: boolean

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.

id

The ID of this node

instanceId

instanceId: number

The ID of this instance of this script. Can be used to filter it from all instances or to send to another instance.

isBackground

isBackground: boolean

Whether this script is running on the backgroundpage

lastError

lastError: Error

Is set if a chrome call triggered an error, otherwise unset

libraries

libraries: object

The libraries API used to register libraries

Type declaration

  • register: function
    • Registers a library with name name

      permission

      crmWrite

      Parameters

      • name: string

        The name to give the library

      • options: object

        The options related to the library (fill at least one)

        • Optional code?: string

          The code to use

        • Optional ts?: boolean

          Whether the library uses the typescript language

        • Optional url?: string

          The URL to fetch the code from

      • Optional callback: function

      Returns Promise<InstalledLibrary>

      A promise that resolves with the new library

onError

onError: Function

If set, calls this function when an error occurs

permissions

permissions: Permission[]

All permissions that are allowed on this script

stackTraces

stackTraces: boolean

When true, shows stacktraces on error in the console of the page the script runs on, true by default.

storage

storage: object

The storage API used to store and retrieve data for this script

Type declaration

  • onChange: object

    Functions related to the onChange event of the storage API

    • addListener: function
      • addListener(listener: function, key?: string): number
      • Adds an onchange listener for the storage, listens for a key if given

        Parameters

        • listener: function

          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

            • (key: string, oldValue: any, newValue: any, remote: boolean): void
            • Parameters

              • key: string
              • oldValue: any
              • newValue: any
              • remote: boolean

              Returns void

        • Optional key: string

        Returns number

        A number that can be used to remove the listener

    • removeListener: function
      • removeListener(listener: number, key?: string): void
      • removeListener(listener: function, key?: string): void
      • Removes ALL listeners with given listener (function) as the listener, if key is given also checks that they have that key

        Parameters

        • listener: number

          The number of the listener to remove (given by addListener)

        • Optional key: string

        Returns void

      • Removes ALL listeners with given listener (function) as the listener, if key is given also checks that they have that key

        Parameters

        • listener: function

          The listener to remove

            • (key: string, oldValue: any, newValue: any, remote: boolean): void
            • Parameters

              • key: string
              • oldValue: any
              • newValue: any
              • remote: boolean

              Returns void

        • Optional key: string

        Returns void

  • get: function
    • get(keyPath?: string): any
    • get(keyPath?: (string | number)[]): any
    • Gets the value at given key, if no key is given returns the entire storage object

      Parameters

      • Optional keyPath: string

      Returns any

    • Gets the value at given key, if no key is given returns the entire storage object

      Parameters

      • Optional keyPath: (string | number)[]

      Returns any

  • remove: function
    • remove(keyPath: string): void
    • remove(keyPath: (string | number)[]): void
    • Deletes the data at given key given value

      Parameters

      • keyPath: string

        The path at which to look, a string separated with dots

      Returns void

    • Deletes the data at given key given value

      Parameters

      • keyPath: (string | number)[]

        The path at which to look, an array of strings and numbers representing keys

      Returns void

  • set: function
    • set(keyPath: string, value?: any): void
    • set(keyPath: (string | number)[], value?: any): void
    • Sets the data at given key given value

      Parameters

      • keyPath: string

        The path at which to look, a string separated with dots

      • Optional value: any

      Returns void

    • Sets the data at given key given value

      Parameters

      • keyPath: (string | number)[]

        The path at which to look, an array of strings and numbers representing keys

      • Optional value: any

      Returns void

storageSync

storageSync: object

The storage API used to store and retrieve data for this script

Type declaration

  • onChange: object

    Functions related to the onChange event of the storage API

    • addListener: function
      • addListener(listener: function, key?: string): number
      • Adds an onchange listener for the storage, listens for a key if given

        Parameters

        • listener: function

          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

            • (key: string, oldValue: any, newValue: any, remote: boolean): void
            • Parameters

              • key: string
              • oldValue: any
              • newValue: any
              • remote: boolean

              Returns void

        • Optional key: string

        Returns number

        A number that can be used to remove the listener

    • removeListener: function
      • removeListener(listener: number, key?: string): void
      • removeListener(listener: function, key?: string): void
      • Removes ALL listeners with given listener (function) as the listener, if key is given also checks that they have that key

        Parameters

        • listener: number

          The number of the listener to remove (given by addListener)

        • Optional key: string

        Returns void

      • Removes ALL listeners with given listener (function) as the listener, if key is given also checks that they have that key

        Parameters

        • listener: function

          The listener to remove

            • (key: string, oldValue: any, newValue: any, remote: boolean): void
            • Parameters

              • key: string
              • oldValue: any
              • newValue: any
              • remote: boolean

              Returns void

        • Optional key: string

        Returns void

  • get: function
    • get(keyPath?: string): any
    • get(keyPath?: (string | number)[]): any
    • Gets the value at given key, if no key is given returns the entire storage object

      Parameters

      • Optional keyPath: string

      Returns any

    • Gets the value at given key, if no key is given returns the entire storage object

      Parameters

      • Optional keyPath: (string | number)[]

      Returns any

  • remove: function
    • remove(keyPath: string): void
    • remove(keyPath: (string | number)[]): void
    • Deletes the data at given key given value

      Parameters

      • keyPath: string

        The path at which to look, a string separated with dots

      Returns void

    • Deletes the data at given key given value

      Parameters

      • keyPath: (string | number)[]

        The path at which to look, an array of strings and numbers representing keys

      Returns void

  • set: function
    • set(keyPath: string, value?: any): void
    • set(keyPath: (string | number)[], value?: any): void
    • Sets the data at given key given value

      Parameters

      • keyPath: string

        The path at which to look, a string separated with dots

      • Optional value: any

      Returns void

    • Sets the data at given key given value

      Parameters

      • keyPath: (string | number)[]

        The path at which to look, an array of strings and numbers representing keys

      • Optional value: any

      Returns void

tabId

tabId: TabId

The ID of the the tab this script is running on

warnOnChromeFunctionNotSent

warnOnChromeFunctionNotSent: boolean

When true, warns you after 5 seconds of not sending a chrome function that you probably forgot to send it

Methods

$

  • $(selector: string): HTMLElement[]
  • $(selector: string): void[]
  • $(selector: string, context: HTMLElement): HTMLElement[]
  • $(selector: string, context: HTMLElement): void[]
  • $(selector: string, context: Document): HTMLElement[]
  • $(selector: string, context: Document): void[]

$crmAPI

  • $crmAPI(selector: string): HTMLElement[]
  • $crmAPI(selector: string): void[]
  • $crmAPI(selector: string, context: HTMLElement): HTMLElement[]
  • $crmAPI(selector: string, context: HTMLElement): void[]
  • $crmAPI(selector: string, context: Document): HTMLElement[]
  • $crmAPI(selector: string, context: Document): void[]

chrome

  • 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

    permission

    chrome

    Parameters

    • api: string

      The API to use

    Returns ChromeRequestReturn

    • An object on which you can call .args, .fn, .return and .send and their first-letter-only versions (.a, .f, .r and .s)

fetch

  • fetch(url: string): Promise<string>
  • Fetches resource at given url. If this keeps failing with a CORB error, try crmAPI.fetchBackground

    Parameters

    • url: string

      The url to fetch the data from

    Returns Promise<string>

    A promise that resolves to the content

fetchBackground

  • fetchBackground(url: string): Promise<string>
  • Fetches resource at given url through the background-page, bypassing any CORS or CORB-like blocking

    Parameters

    • url: string

      The url to fetch the data from

    Returns Promise<string>

    A promise that resolves to the content

getClickInfo

getNode

getSelection

  • getSelection(): string
  • getSelection(): string

getTabInfo

log

  • log(...args: any[]): void

options

  • options<T, O>(defaults?: T): T | O
  • Returns the options for this script/stylesheet. Any missing values are filled in with the corresponding field in the 'defaults' param

    Type parameters

    • T: Object

    • O: Object

    Parameters

    • Optional defaults: T

    Returns T | O

Generated using TypeDoc