Index

Variables

HINTTAGS_anchor_selectors

HINTTAGS_anchor_selectors: string = `[id],[name]`

HINTTAGS_img_selectors

HINTTAGS_img_selectors: string = `img,[src]`

HINTTAGS_killable_selectors

HINTTAGS_killable_selectors: string = `header,footer,nav,span,div,iframe,img,button,article,summary`

HINTTAGS_saveable

HINTTAGS_saveable: string = `[href]:not([href='#'])`

CSS selector for elements which point to a saveable resource

HINTTAGS_selectors

HINTTAGS_selectors: string = `input:not([type=hidden]):not([disabled]),a,area,iframe,textarea,button,select,summary,[onclick],[onmouseover],[onmousedown],[onmouseup],[oncommand],[role='link'],[role='button'],[role='checkbox'],[role='combobox'],[role='listbox'],[role='listitem'],[role='menuitem'],[role='menuitemcheckbox'],[role='menuitemradio'],[role='option'],[role='radio'],[role='scrollbar'],[role='slider'],[role='spinbutton'],[role='tab'],[role='textbox'],[role='treeitem'],[class*='button'],[tabindex]`

LAST_USED_INPUT

LAST_USED_INPUT: HTMLElement = null

DOM reference to the last used Input field

hintworthy_js_elems

hintworthy_js_elems: any[] = []

logger

logger: Logger = new Logging.Logger("dom")

Functions

anchors

  • anchors(): Element[]
  • Get array of "anchors": elements which have id or name and can be addressed with the hash/fragment in the URL

    Returns Element[]

compareElementArea

  • compareElementArea(a: HTMLElement, b: HTMLElement): number
  • Comparison function by offsetWidth/Height, used for sorting elements by their area on the page

    Parameters

    • a: HTMLElement
    • b: HTMLElement

    Returns number

elementsByXPath

  • elementsByXPath(xpath: any, parent?: any): IterableIterator<Node>
  • Iterable of elements that match xpath.

    Adapted from stackoverflow

    Parameters

    • xpath: any
    • Optional parent: any

    Returns IterableIterator<Node>

elementsWithText

  • elementsWithText(): Element[]

focus

  • focus(e: HTMLElement): void
  • Focuses an input element and makes sure the cursor is put at the end of the input

    Parameters

    • e: HTMLElement

    Returns void

getAllDocumentFrames

  • getAllDocumentFrames(doc?: Document): HTMLFrameElement[]
  • Return all frames that belong to the document (frames that belong to extensions are ignored).

    Parameters

    • Default value doc: Document = document

      The document the frames should be fetched from

    Returns HTMLFrameElement[]

getElemsBySelector

  • getElemsBySelector(selector: string, filters: Array<ElementFilter>): Element[]
  • Get all elements that match the given selector

    Parameters

    • selector: string

      `the CSS selector to choose elements with

    • filters: Array<ElementFilter>

      filter to use (in thre given order) to further chose items, or [] for all

    Returns Element[]

getLastUsedInput

  • getLastUsedInput(): HTMLElement

getNthElement

  • getNthElement(selectors: string, nth: number, filters: Array<ElementFilter>): HTMLElement
  • Get the nth input element on a page

    Parameters

    • selectors: string
    • nth: number

      the element index, can be negative to start at the end

    • filters: Array<ElementFilter>

      filter to use (in thre given order) to further chose items, or [] for all

    Returns HTMLElement

getSelector

  • getSelector(e: HTMLElement): any
  • Computes the unique CSS selector of a specific HTMLElement

    Parameters

    • e: HTMLElement

    Returns any

heightMatters

  • heightMatters(style: CSSStyleDeclaration): boolean
  • This function decides whether the height attribute contained in a ComputedStyle matters. For example, the height attribute doesn't matter for elements that have "display: inline" because their height is overriden by the height of the node they are in.

    Parameters

    • style: CSSStyleDeclaration

    Returns boolean

hijackPageFocusFunction

  • hijackPageFocusFunction(): void
  • Replaces the page's HTMLElement.prototype.focus with our own, onPageFocus

    Returns void

hijackPageListenerFunctions

  • hijackPageListenerFunctions(): void
  • Replace the page's addEventListener with a closure containing a reference to the original addEventListener and registerEvListenerAction. Do the same with removeEventListener.

    Returns void

isEditableHTMLInput

  • Returns whether the passed HTML input element is editable

    Parameters

    Returns boolean

isSubstantial

  • isSubstantial(element: Element): boolean
  • Is the element of "substantial" size and shown on the page. The element doesn't need to be in the viewport. This is useful when you want to scroll to something, but still want to exclude tiny and useless items

    Parameters

    • element: Element

    Returns boolean

isTextEditable

  • Given a DOM element, returns true if you can edit it with key presses or if the element is of a type that should handle its own keypresses (e.g. role=application for google docs/sheets) TODO: work on case sensitivity consider all the possible cases

    Parameters

    Returns boolean

isVisible

  • isVisible(element: Element): boolean

mouseEvent

  • mouseEvent(element: Element, type: "hover" | "unhover" | "click", modifierKeys?: object): void
  • Dispatch a mouse event to the target element based on cVim's implementation

    Parameters

    • element: Element
    • type: "hover" | "unhover" | "click"
    • Default value modifierKeys: object = {}

    Returns void

onPageFocus

  • onPageFocus(elem: HTMLElement, args: any[]): boolean

registerEvListenerAction

  • registerEvListenerAction(elem: EventTarget, add: boolean, event: string): void
  • Adds or removes an element from the hintworthy_js_elems array of the current tab.

    @param {EventTarget} elem The element add/removeEventListener is called on @param {boolean} add true when called from addEventListener, false from removeEventListener @param {string} event The event name given to add/removeEventListener

    This function must be security reviewed when Custom Elements land in Firefox https://bugzilla.mozilla.org/show_bug.cgi?id=1406825

    This function is exported to the web content window but should only be callable from our modified add/removeEventListener because we remove the reference to it before web content runs (if added afterwards a mutationobserver on the window object would probably capture a reference to this function).

    Just in case web content does get a direct reference or the built-in add/removeEventListener code doesn't validate elem correctly, this function must assume that its inputs are potentially malicious.

    Parameters

    • elem: EventTarget
    • add: boolean
    • event: string

    Returns void

setInput

  • setInput(el: any): Promise<void>

setupFocusHandler

  • setupFocusHandler(): void

simulateClick

  • simulateClick(target: HTMLElement): void
  • if target === _blank clicking the link is treated as opening a popup and is blocked. Use webext API to avoid that.

    Parameters

    • target: HTMLElement

    Returns void

widthMatters

  • widthMatters(style: CSSStyleDeclaration): boolean
  • Parameters

    • style: CSSStyleDeclaration

    Returns boolean