mirror of
https://github.com/vale981/tridactyl
synced 2025-03-05 09:31:41 -05:00
Move most of hinting to content
This commit is contained in:
parent
247fc05d1c
commit
7ec89f9d32
4 changed files with 41 additions and 89 deletions
20
package-lock.json
generated
20
package-lock.json
generated
|
@ -4711,7 +4711,8 @@
|
|||
"code-point-at": {
|
||||
"version": "1.1.0",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"concat-map": {
|
||||
"version": "0.0.1",
|
||||
|
@ -4722,7 +4723,8 @@
|
|||
"console-control-strings": {
|
||||
"version": "1.1.0",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"core-util-is": {
|
||||
"version": "1.0.2",
|
||||
|
@ -4839,7 +4841,8 @@
|
|||
"inherits": {
|
||||
"version": "2.0.3",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"ini": {
|
||||
"version": "1.3.5",
|
||||
|
@ -4851,6 +4854,7 @@
|
|||
"version": "1.0.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"number-is-nan": "^1.0.0"
|
||||
}
|
||||
|
@ -4873,12 +4877,14 @@
|
|||
"minimist": {
|
||||
"version": "0.0.8",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"minipass": {
|
||||
"version": "2.2.4",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"safe-buffer": "^5.1.1",
|
||||
"yallist": "^3.0.0"
|
||||
|
@ -4897,6 +4903,7 @@
|
|||
"version": "0.5.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"minimist": "0.0.8"
|
||||
}
|
||||
|
@ -4977,7 +4984,8 @@
|
|||
"number-is-nan": {
|
||||
"version": "1.0.1",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"object-assign": {
|
||||
"version": "4.1.1",
|
||||
|
@ -4989,6 +4997,7 @@
|
|||
"version": "1.4.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"wrappy": "1"
|
||||
}
|
||||
|
@ -5110,6 +5119,7 @@
|
|||
"version": "1.0.2",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"code-point-at": "^1.0.0",
|
||||
"is-fullwidth-code-point": "^1.0.0",
|
||||
|
|
|
@ -2781,8 +2781,8 @@ export function unset(...keys: string[]) {
|
|||
|
||||
// {{{ HINTMODE
|
||||
|
||||
//#background_helper
|
||||
import * as hinting from "./hinting_background"
|
||||
//#content_helper
|
||||
import * as hinting from "./hinting"
|
||||
|
||||
/** Hint a page.
|
||||
|
||||
|
@ -2833,8 +2833,8 @@ import * as hinting from "./hinting_background"
|
|||
boilerplate each time you visit it, even if the number of
|
||||
links in the main body changes).
|
||||
*/
|
||||
//#background
|
||||
export function hint(option?: string, selectors?: string, ...rest: string[]) {
|
||||
//#content
|
||||
export async function hint(option?: string, selectors?: string, ...rest: string[]) {
|
||||
if (option === "-b") hinting.hintPageOpenInBackground()
|
||||
else if (option === "-y") hinting.hintPageYank()
|
||||
else if (option === "-p") hinting.hintPageTextYank()
|
||||
|
|
|
@ -24,7 +24,6 @@ import state from "./state"
|
|||
import { messageActiveTab, message } from "./messaging"
|
||||
import * as config from "./config"
|
||||
import * as TTS from "./text_to_speech"
|
||||
import { HintSaveType } from "./hinting_background"
|
||||
import Logger from "./logging"
|
||||
import * as Messaging from "./messaging"
|
||||
const logger = new Logger("hinting")
|
||||
|
@ -436,7 +435,6 @@ function pushKey(ke) {
|
|||
} else if (ke.key.length > 1) {
|
||||
return
|
||||
} else if (modeState.hintchars.includes(ke.key)) {
|
||||
console.log(ke.key)
|
||||
modeState.filter += ke.key
|
||||
modeState.filterFunc(modeState.filter)
|
||||
}
|
||||
|
@ -594,7 +592,7 @@ function simulateClick(target: HTMLElement) {
|
|||
}
|
||||
}
|
||||
|
||||
function hintPageOpenInBackground(selectors = HINTTAGS_selectors) {
|
||||
export function hintPageOpenInBackground(selectors = HINTTAGS_selectors) {
|
||||
hintPage(hintables(selectors, true), hint => {
|
||||
hint.target.focus()
|
||||
if (hint.target.href) {
|
||||
|
@ -623,7 +621,7 @@ function hintPageOpenInBackground(selectors = HINTTAGS_selectors) {
|
|||
|
||||
import { openInNewWindow } from "./lib/webext"
|
||||
|
||||
function hintPageWindow() {
|
||||
export function hintPageWindow() {
|
||||
hintPage(hintables(), hint => {
|
||||
hint.target.focus()
|
||||
if (hint.target.href) {
|
||||
|
@ -635,7 +633,7 @@ function hintPageWindow() {
|
|||
})
|
||||
}
|
||||
|
||||
function hintPageWindowPrivate() {
|
||||
export function hintPageWindowPrivate() {
|
||||
hintPage(hintables(), hint => {
|
||||
hint.target.focus()
|
||||
if (hint.target.href) {
|
||||
|
@ -644,13 +642,13 @@ function hintPageWindowPrivate() {
|
|||
})
|
||||
}
|
||||
|
||||
function hintPageSimple(selectors = HINTTAGS_selectors) {
|
||||
export function hintPageSimple(selectors = HINTTAGS_selectors) {
|
||||
hintPage(hintables(selectors, true), hint => {
|
||||
simulateClick(hint.target)
|
||||
})
|
||||
}
|
||||
|
||||
function hintPageExStr(...exStr: string[]) {
|
||||
export function hintPageExStr(...exStr: string[]) {
|
||||
let selectors = HINTTAGS_selectors
|
||||
hintPage(hintables(selectors, true), hint => {
|
||||
Messaging.message("commandline_background", "recvExStr", [
|
||||
|
@ -659,7 +657,8 @@ function hintPageExStr(...exStr: string[]) {
|
|||
})
|
||||
}
|
||||
|
||||
function hintPageTextYank() {
|
||||
|
||||
export function hintPageTextYank() {
|
||||
hintPage(elementswithtext(), hint => {
|
||||
messageActiveTab("commandline_frame", "setClipboard", [
|
||||
hint.target.textContent,
|
||||
|
@ -667,7 +666,7 @@ function hintPageTextYank() {
|
|||
})
|
||||
}
|
||||
|
||||
function hintPageTitleAltTextYank() {
|
||||
export function hintPageTitleAltTextYank() {
|
||||
hintPage(titleAltTextElements(), hint => {
|
||||
messageActiveTab("commandline_frame", "setClipboard", [
|
||||
hint.target.title ? hint.target.title : hint.target.alt,
|
||||
|
@ -675,7 +674,7 @@ function hintPageTitleAltTextYank() {
|
|||
})
|
||||
}
|
||||
|
||||
function hintPageYank() {
|
||||
export function hintPageYank() {
|
||||
hintPage(hintables(), hint => {
|
||||
messageActiveTab("commandline_frame", "setClipboard", [
|
||||
hint.target.href,
|
||||
|
@ -685,7 +684,7 @@ function hintPageYank() {
|
|||
|
||||
/** Hint anchors and yank the URL on selection
|
||||
*/
|
||||
function hintPageAnchorYank() {
|
||||
export function hintPageAnchorYank() {
|
||||
hintPage(anchors(), hint => {
|
||||
let anchorUrl = new URL(window.location.href)
|
||||
|
||||
|
@ -700,7 +699,7 @@ function hintPageAnchorYank() {
|
|||
* @param inBackground opens the image source URL in a background tab,
|
||||
* as opposed to the current tab
|
||||
*/
|
||||
function hintImage(inBackground) {
|
||||
export function hintImage(inBackground) {
|
||||
hintPage(hintableImages(), hint => {
|
||||
let img_src = hint.target.getAttribute("src")
|
||||
|
||||
|
@ -716,14 +715,14 @@ function hintImage(inBackground) {
|
|||
}
|
||||
|
||||
/** Hint elements to focus */
|
||||
function hintFocus(selectors?) {
|
||||
export function hintFocus(selectors?) {
|
||||
hintPage(hintables(selectors), hint => {
|
||||
hint.target.focus()
|
||||
})
|
||||
}
|
||||
|
||||
/** Hint items and read out the content of the selection */
|
||||
function hintRead() {
|
||||
export function hintRead() {
|
||||
hintPage(elementswithtext(), hint => {
|
||||
TTS.readText(hint.target.textContent)
|
||||
})
|
||||
|
@ -731,12 +730,19 @@ function hintRead() {
|
|||
|
||||
/** Hint elements and delete the selection from the page
|
||||
*/
|
||||
function hintKill() {
|
||||
export function hintKill() {
|
||||
hintPage(killables(), hint => {
|
||||
hint.target.remove()
|
||||
})
|
||||
}
|
||||
|
||||
/** Type for "hint save" actions:
|
||||
* - "link": elements that point to another resource (eg
|
||||
* links to pages/files) - the link target is saved
|
||||
* - "img": image elements
|
||||
*/
|
||||
export type HintSaveType = "link" | "img"
|
||||
|
||||
/** Hint link elements to save
|
||||
*
|
||||
* @param hintType the type of elements to hint and save:
|
||||
|
@ -745,7 +751,7 @@ function hintKill() {
|
|||
* - "img": image elements
|
||||
* @param saveAs prompt for save location
|
||||
*/
|
||||
function hintSave(hintType: HintSaveType, saveAs: boolean) {
|
||||
export function hintSave(hintType: HintSaveType, saveAs: boolean) {
|
||||
function saveHintElems(hintType) {
|
||||
return hintType === "link" ? saveableElements() : hintableImages()
|
||||
}
|
||||
|
|
|
@ -12,63 +12,6 @@ async function reset() {
|
|||
return await messageActiveTab("hinting_content", "reset")
|
||||
}
|
||||
|
||||
export async function hintPageYank() {
|
||||
return await messageActiveTab("hinting_content", "hintPageYank")
|
||||
}
|
||||
|
||||
export async function hintPageTitleAltTextYank() {
|
||||
return await messageActiveTab("hinting_content", "hintPageTitleAltTextYank")
|
||||
}
|
||||
|
||||
export async function hintPageTextYank() {
|
||||
return await messageActiveTab("hinting_content", "hintPageTextYank")
|
||||
}
|
||||
|
||||
export async function hintPageAnchorYank() {
|
||||
return await messageActiveTab("hinting_content", "hintPageAnchorYank")
|
||||
}
|
||||
|
||||
export async function hintPageSimple(selectors?) {
|
||||
return await messageActiveTab("hinting_content", "hintPageSimple", [
|
||||
selectors,
|
||||
])
|
||||
}
|
||||
|
||||
export async function hintPageExStr(...exstr: string[]) {
|
||||
return await messageActiveTab("hinting_content", "hintPageExStr", [
|
||||
...exstr,
|
||||
])
|
||||
}
|
||||
|
||||
export async function hintPageOpenInBackground() {
|
||||
return await messageActiveTab("hinting_content", "hintPageOpenInBackground")
|
||||
}
|
||||
|
||||
export async function hintPageWindow() {
|
||||
return await messageActiveTab("hinting_content", "hintPageWindow")
|
||||
}
|
||||
|
||||
export async function hintPageWindowPrivate() {
|
||||
return await messageActiveTab("hinting_content", "hintPageWindowPrivate")
|
||||
}
|
||||
|
||||
export async function hintImage(inBackground) {
|
||||
return await messageActiveTab("hinting_content", "hintImage", [
|
||||
inBackground,
|
||||
])
|
||||
}
|
||||
|
||||
export async function hintFocus(selectors?) {
|
||||
return await messageActiveTab("hinting_content", "hintFocus", [selectors])
|
||||
}
|
||||
|
||||
export async function hintRead() {
|
||||
return await messageActiveTab("hinting_content", "hintRead")
|
||||
}
|
||||
|
||||
export async function hintKill() {
|
||||
return await messageActiveTab("hinting_content", "hintKill")
|
||||
}
|
||||
|
||||
/** Type for "hint save" actions:
|
||||
* - "link": elements that point to another resource (eg
|
||||
|
@ -77,13 +20,6 @@ export async function hintKill() {
|
|||
*/
|
||||
export type HintSaveType = "link" | "img"
|
||||
|
||||
export async function hintSave(hintType: HintSaveType, saveAs: boolean) {
|
||||
return await messageActiveTab("hinting_content", "hintSave", [
|
||||
hintType,
|
||||
saveAs,
|
||||
])
|
||||
}
|
||||
|
||||
import { MsgSafeKeyboardEvent } from "./msgsafe"
|
||||
|
||||
/** At some point, this might be turned into a real keyseq parser
|
||||
|
|
Loading…
Add table
Reference in a new issue