Add hint kill submode (;k)

This submode deletes the selected hinted item. Useful for removing
overlay blockers or even unwanted/annoying content.
This commit is contained in:
John Beard 2017-11-28 22:51:53 +00:00
parent c2c5d2b5ef
commit 080d6df9a3
4 changed files with 32 additions and 0 deletions

View file

@ -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",

View file

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

View file

@ -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,
}))

View file

@ -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