From 080d6df9a324945aae5c7be52397422d67523a99 Mon Sep 17 00:00:00 2001 From: John Beard Date: Tue, 28 Nov 2017 22:51:53 +0000 Subject: [PATCH] Add hint kill submode (;k) This submode deletes the selected hinted item. Useful for removing overlay blockers or even unwanted/annoying content. --- src/config.ts | 1 + src/excmds.ts | 2 ++ src/hinting.ts | 25 +++++++++++++++++++++++++ src/hinting_background.ts | 4 ++++ 4 files changed, 32 insertions(+) diff --git a/src/config.ts b/src/config.ts index d6008bca..ea62f787 100644 --- a/src/config.ts +++ b/src/config.ts @@ -73,6 +73,7 @@ const DEFAULTS = o({ "F": "hint -b", ";i": "hint -i", ";I": "hint -I", + ";k": "hint -k", ";y": "hint -y", ";p": "hint -p", ";r": "hint -r", diff --git a/src/excmds.ts b/src/excmds.ts index c3367fbd..b18a2136 100644 --- a/src/excmds.ts +++ b/src/excmds.ts @@ -1301,6 +1301,7 @@ import * as hinting from './hinting_background' - -r read an element's text with text-to-speech - -i view an image - -I view an image in a new tab + - -k delete an element from the page - -; focus an element - -# yank an element's anchor URL to clipboard - -c [selector] hint links that match the css selector @@ -1316,6 +1317,7 @@ export function hint(option?: string, selectors="") { else if (option === "-p") hinting.hintPageTextYank() else if (option === "-i") hinting.hintImage(false) else if (option === "-I") hinting.hintImage(true) + else if (option === "-k") hinting.hintKill() else if (option === "-;") hinting.hintFocus() else if (option === "-#") hinting.hintPageAnchorYank() else if (option === "-c") hinting.hintPageSimple(selectors) diff --git a/src/hinting.ts b/src/hinting.ts index e3e69516..5d7822c6 100644 --- a/src/hinting.ts +++ b/src/hinting.ts @@ -234,6 +234,12 @@ function anchors() { return DOM.getElemsBySelector(HINTTAGS_anchor_selectors, [DOM.isVisible]) } +/** Array of items that can be killed with hint kill + */ +function killables() { + return DOM.getElemsBySelector(HINTTAGS_killable_selectors, [DOM.isVisible]) +} + // CSS selectors. More readable for web developers. Not dead. Leaves browser to care about XML. const HINTTAGS_selectors = ` input:not([type=hidden]):not([disabled]), @@ -280,6 +286,16 @@ const HINTTAGS_anchor_selectors = ` [name] ` +const HINTTAGS_killable_selectors = ` +span, +div, +iframe, +img, +button, +article, +summary +` + import {activeTab, browserBg, l, firefoxVersionAtLeast} from './lib/webext' async function openInBackground(url: string) { @@ -387,6 +403,14 @@ function hintRead() { }) } +/** Hint elements and delete the selection from the page + */ +function hintKill() { + hintPage(killables(), hint=>{ + hint.target.remove(); + }) +} + function selectFocusedHint() { console.log("Selecting hint.", state.mode) const focused = modeState.focusedHint @@ -407,4 +431,5 @@ addListener('hinting_content', attributeCaller({ hintImage, hintFocus, hintRead, + hintKill, })) diff --git a/src/hinting_background.ts b/src/hinting_background.ts index fe624688..1e4e69fe 100644 --- a/src/hinting_background.ts +++ b/src/hinting_background.ts @@ -44,6 +44,10 @@ export async function hintRead() { return await messageActiveTab('hinting_content', 'hintRead') } +export async function hintKill() { + return await messageActiveTab('hinting_content', 'hintKill') +} + import {MsgSafeKeyboardEvent} from './msgsafe' /** At some point, this might be turned into a real keyseq parser