Add hint -W [exstr] to execute exstr on hint's href

This commit is contained in:
Oliver Blanthorn 2018-04-20 19:32:09 +01:00
parent 73ab23152f
commit 6088ebff6c
No known key found for this signature in database
GPG key ID: 2BB8C36BB504BFF3
4 changed files with 26 additions and 1 deletions

View file

@ -155,6 +155,7 @@ const DEFAULTS = o({
bdelete: "tabclose", bdelete: "tabclose",
sanitize: "sanitise", sanitize: "sanitise",
tutorial: "tutor", tutorial: "tutor",
openwith: "hint -W",
}), }),
followpagepatterns: o({ followpagepatterns: o({
next: "^(next|newer)\\b|»|>>|more", next: "^(next|newer)\\b|»|>>|more",

View file

@ -171,6 +171,11 @@ export async function editor() {
// to everything written using editor // to everything written using editor
} }
//#background
export async function exclaim(...str: string[]) {
fillcmdline((await Native.run(str.join(" "))).content)
}
//#background //#background
export async function native() { export async function native() {
const version = await Native.getNativeMessengerVersion() const version = await Native.getNativeMessengerVersion()
@ -1864,6 +1869,7 @@ import * as hinting from "./hinting_background"
- `bind ;c hint -c [class*="expand"],[class="togg"]` works particularly well on reddit and HN - `bind ;c hint -c [class*="expand"],[class="togg"]` works particularly well on reddit and HN
- -w open in new window - -w open in new window
-wp open in new private window -wp open in new private window
- `-W excmd...` append hint href to excmd and execute, e.g, `hint -W open` and other such bad ideas.
Excepting the custom selector mode and background hint mode, each of these Excepting the custom selector mode and background hint mode, each of these
hint modes is available by default as `;<option character>`, so e.g. `;y` hint modes is available by default as `;<option character>`, so e.g. `;y`
@ -1877,7 +1883,7 @@ import * as hinting from "./hinting_background"
"relatedopenpos": "related" | "next" | "last" "relatedopenpos": "related" | "next" | "last"
*/ */
//#background //#background
export function hint(option?: string, selectors = "") { export function hint(option?: string, selectors = "", ...rest: string[]) {
if (option === "-b") hinting.hintPageOpenInBackground() if (option === "-b") hinting.hintPageOpenInBackground()
else if (option === "-y") hinting.hintPageYank() else if (option === "-y") hinting.hintPageYank()
else if (option === "-p") hinting.hintPageTextYank() else if (option === "-p") hinting.hintPageTextYank()
@ -1893,6 +1899,7 @@ export function hint(option?: string, selectors = "") {
else if (option === "-c") hinting.hintPageSimple(selectors) else if (option === "-c") hinting.hintPageSimple(selectors)
else if (option === "-r") hinting.hintRead() else if (option === "-r") hinting.hintRead()
else if (option === "-w") hinting.hintPageWindow() else if (option === "-w") hinting.hintPageWindow()
else if (option === "-W") hinting.hintPageExStr([selectors, ...rest].join(" "))
else if (option === "-wp") hinting.hintPageWindowPrivate() else if (option === "-wp") hinting.hintPageWindowPrivate()
else hinting.hintPageSimple() else hinting.hintPageSimple()
} }

View file

@ -26,6 +26,7 @@ import * as config from "./config"
import * as TTS from "./text_to_speech" import * as TTS from "./text_to_speech"
import { HintSaveType } from "./hinting_background" import { HintSaveType } from "./hinting_background"
import Logger from "./logging" import Logger from "./logging"
import * as Messaging from "./messaging"
const logger = new Logger("hinting") const logger = new Logger("hinting")
/** Simple container for the state of a single frame's hints. */ /** Simple container for the state of a single frame's hints. */
@ -602,6 +603,15 @@ function hintPageSimple(selectors = HINTTAGS_selectors) {
}) })
} }
function hintPageExStr(...exStr: string[]) {
let selectors = HINTTAGS_selectors
hintPage(hintables(selectors, true), hint => {
Messaging.message("commandline_background", "recvExStr", [
exStr.join(" ") + " " + hint.target.href,
])
})
}
function hintPageTextYank() { function hintPageTextYank() {
hintPage(elementswithtext(), hint => { hintPage(elementswithtext(), hint => {
messageActiveTab("commandline_frame", "setClipboard", [ messageActiveTab("commandline_frame", "setClipboard", [
@ -716,6 +726,7 @@ addListener(
selectFocusedHint, selectFocusedHint,
reset, reset,
hintPageSimple, hintPageSimple,
hintPageExStr,
hintPageYank, hintPageYank,
hintPageTextYank, hintPageTextYank,
hintPageAnchorYank, hintPageAnchorYank,

View file

@ -30,6 +30,12 @@ export async function hintPageSimple(selectors?) {
]) ])
} }
export async function hintPageExStr(...exstr: string[]) {
return await messageActiveTab("hinting_content", "hintPageExStr", [
...exstr,
])
}
export async function hintPageOpenInBackground() { export async function hintPageOpenInBackground() {
return await messageActiveTab("hinting_content", "hintPageOpenInBackground") return await messageActiveTab("hinting_content", "hintPageOpenInBackground")
} }