tridactyl/src/hinting_background.ts

91 lines
2.5 KiB
TypeScript
Raw Normal View History

2017-11-08 23:20:41 +00:00
import {messageActiveTab} from './messaging'
async function pushKey(key) {
return await messageActiveTab('hinting_content', 'pushKey', [key])
}
async function selectFocusedHint() {
return await messageActiveTab('hinting_content', 'selectFocusedHint')
}
async function reset() {
return await messageActiveTab('hinting_content', 'reset')
}
export async function hintPageYank() {
return await messageActiveTab('hinting_content', 'hintPageYank')
}
2017-11-22 20:47:35 +00:00
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])
}
2017-11-18 01:51:46 +00:00
export async function hintPageOpenInBackground() {
return await messageActiveTab('hinting_content', 'hintPageOpenInBackground')
}
2018-03-11 12:53:02 +00:00
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() {
return await messageActiveTab('hinting_content', 'hintFocus')
}
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
* links to pages/files) - the link target is saved
* - "img": image elements
*/
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'
2017-11-08 23:20:41 +00:00
/** At some point, this might be turned into a real keyseq parser
2017-11-19 07:57:30 +00:00
reset and selectFocusedHints are OK candidates for map targets in the
future. pushKey less so, I think.
2017-11-08 23:20:41 +00:00
*/
export function parser(keys: MsgSafeKeyboardEvent[]) {
2017-11-08 23:20:41 +00:00
const key = keys[0].key
2017-11-19 07:57:30 +00:00
if (key === 'Escape') {
2017-11-08 23:20:41 +00:00
reset()
} else if (['Enter', ' '].includes(key)) {
2017-11-19 07:57:30 +00:00
selectFocusedHint()
2017-11-08 23:20:41 +00:00
} else {
pushKey(keys[0])
}
2017-11-19 07:57:30 +00:00
return {keys: [], ex_str: ''}
2017-11-08 23:20:41 +00:00
}