|
|
@ -68,18 +68,12 @@ const isAriaHiddenOrAriaDisabled = (win: Window, element: Element): boolean => { |
|
|
|
export default class Follow { |
|
|
|
export default class Follow { |
|
|
|
private win: Window; |
|
|
|
private win: Window; |
|
|
|
|
|
|
|
|
|
|
|
private newTab: boolean; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private background: boolean; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private hints: {[key: string]: Hint }; |
|
|
|
private hints: {[key: string]: Hint }; |
|
|
|
|
|
|
|
|
|
|
|
private targets: HTMLElement[] = []; |
|
|
|
private targets: HTMLElement[] = []; |
|
|
|
|
|
|
|
|
|
|
|
constructor(win: Window) { |
|
|
|
constructor(win: Window) { |
|
|
|
this.win = win; |
|
|
|
this.win = win; |
|
|
|
this.newTab = false; |
|
|
|
|
|
|
|
this.background = false; |
|
|
|
|
|
|
|
this.hints = {}; |
|
|
|
this.hints = {}; |
|
|
|
this.targets = []; |
|
|
|
this.targets = []; |
|
|
|
|
|
|
|
|
|
|
@ -106,13 +100,11 @@ export default class Follow { |
|
|
|
}), '*'); |
|
|
|
}), '*'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
createHints(keysArray: string[], newTab: boolean, background: boolean) { |
|
|
|
createHints(keysArray: string[]) { |
|
|
|
if (keysArray.length !== this.targets.length) { |
|
|
|
if (keysArray.length !== this.targets.length) { |
|
|
|
throw new Error('illegal hint count'); |
|
|
|
throw new Error('illegal hint count'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.newTab = newTab; |
|
|
|
|
|
|
|
this.background = background; |
|
|
|
|
|
|
|
this.hints = {}; |
|
|
|
this.hints = {}; |
|
|
|
for (let i = 0; i < keysArray.length; ++i) { |
|
|
|
for (let i = 0; i < keysArray.length; ++i) { |
|
|
|
let keys = keysArray[i]; |
|
|
|
let keys = keysArray[i]; |
|
|
@ -141,7 +133,7 @@ export default class Follow { |
|
|
|
this.targets = []; |
|
|
|
this.targets = []; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async activateHints(keys: string): Promise<void> { |
|
|
|
async activateHints(keys: string, newTab: boolean, background: boolean): Promise<void> { |
|
|
|
let hint = this.hints[keys]; |
|
|
|
let hint = this.hints[keys]; |
|
|
|
if (!hint) { |
|
|
|
if (!hint) { |
|
|
|
return; |
|
|
|
return; |
|
|
@ -150,7 +142,7 @@ export default class Follow { |
|
|
|
if (hint instanceof LinkHint) { |
|
|
|
if (hint instanceof LinkHint) { |
|
|
|
let url = hint.getLink(); |
|
|
|
let url = hint.getLink(); |
|
|
|
// ignore taget='_blank'
|
|
|
|
// ignore taget='_blank'
|
|
|
|
if (!this.newTab && hint.getLinkTarget() !== '_blank') { |
|
|
|
if (!newTab && hint.getLinkTarget() !== '_blank') { |
|
|
|
hint.click(); |
|
|
|
hint.click(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
@ -158,7 +150,7 @@ export default class Follow { |
|
|
|
if (!url || url === '#' || url.toLowerCase().startsWith('javascript:')) { |
|
|
|
if (!url || url === '#' || url.toLowerCase().startsWith('javascript:')) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
await tabsClient.openUrl(url, this.newTab, this.background); |
|
|
|
await tabsClient.openUrl(url, newTab, background); |
|
|
|
} else if (hint instanceof InputHint) { |
|
|
|
} else if (hint instanceof InputHint) { |
|
|
|
hint.activate(); |
|
|
|
hint.activate(); |
|
|
|
} |
|
|
|
} |
|
|
@ -169,12 +161,11 @@ export default class Follow { |
|
|
|
case messages.FOLLOW_REQUEST_COUNT_TARGETS: |
|
|
|
case messages.FOLLOW_REQUEST_COUNT_TARGETS: |
|
|
|
return this.countHints(sender, message.viewSize, message.framePosition); |
|
|
|
return this.countHints(sender, message.viewSize, message.framePosition); |
|
|
|
case messages.FOLLOW_CREATE_HINTS: |
|
|
|
case messages.FOLLOW_CREATE_HINTS: |
|
|
|
return this.createHints( |
|
|
|
return this.createHints(message.keysArray); |
|
|
|
message.keysArray, message.newTab, message.background); |
|
|
|
|
|
|
|
case messages.FOLLOW_SHOW_HINTS: |
|
|
|
case messages.FOLLOW_SHOW_HINTS: |
|
|
|
return this.showHints(message.keys); |
|
|
|
return this.showHints(message.keys); |
|
|
|
case messages.FOLLOW_ACTIVATE: |
|
|
|
case messages.FOLLOW_ACTIVATE: |
|
|
|
return this.activateHints(message.keys); |
|
|
|
return this.activateHints(message.keys, message.newTab, message.background); |
|
|
|
case messages.FOLLOW_REMOVE_HINTS: |
|
|
|
case messages.FOLLOW_REMOVE_HINTS: |
|
|
|
return this.removeHints(); |
|
|
|
return this.removeHints(); |
|
|
|
} |
|
|
|
} |
|
|
|