Example #1
0
    request,
    state,
    webext,
    l: prom => prom.then(console.log).catch(console.error),
    contentLocation: window.location,
    perf,
})

import { HintingCmds } from "@src/background/hinting"
// Set up our controller to execute background-mode excmds. All code
// running from this entry point, which is to say, everything in the
// background script, will use the excmds that we give to the module
// here.
controller.setExCmds({
    "": excmds_background,
    "ex": CmdlineCmds,
    "text": EditorCmds,
    "hint": HintingCmds
})
messaging.addListener("excmd_background", messaging.attributeCaller(excmds_background))
messaging.addListener("controller_background", messaging.attributeCaller(controller))

// {{{ tri.contentLocation
// When loading the background, use the active tab to know what the current content url is
browser.tabs.query({ currentWindow: true, active: true }).then(t => {
    (window as any).tri.contentLocation = new URL(t[0].url)
})
// After that, on every tab change, update the current url
let contentLocationCount = 0
browser.tabs.onActivated.addListener(ev => {
    const myId = contentLocationCount + 1
    contentLocationCount = myId
Example #2
0
    contentState,
    addContentStateChangedListener,
} from "@src/content/state_content"

// Set up our controller to execute content-mode excmds. All code
// running from this entry point, which is to say, everything in the
// content script, will use the excmds that we give to the module
// here.
import * as controller from "@src/lib/controller"
import * as excmds_content from "@src/.excmds_content.generated"
import { CmdlineCmds } from "@src/content/commandline_cmds"
import { EditorCmds } from "@src/content/editor"
import * as hinting_content from "@src/content/hinting"
controller.setExCmds({
    "": excmds_content,
    "ex": CmdlineCmds,
    "text": EditorCmds,
    "hint": hinting_content.getHintCommands()
})
messaging.addListener("excmd_content", messaging.attributeCaller(excmds_content))
messaging.addListener("controller_content", messaging.attributeCaller(controller))

// Hook the keyboard up to the controller
import * as ContentController from "@src/content/controller_content"
import { getAllDocumentFrames } from "@src/lib/dom"
function listen(elem) {
    elem.removeEventListener("keydown", ContentController.acceptKey, true)
    elem.removeEventListener(
        "keypress",
        ContentController.canceller.cancelKeyPress,
        true,
    )