diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-09-17 18:21:07 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-09-17 19:12:30 +0900 |
commit | 324cf32c5bd5d7e7ce89a9aaa7497454a7dfdbb2 (patch) | |
tree | f228e1d11914fbde98a96f62cd2881088cd22dc8 | |
parent | ba2022c46585a2f365eb4939faff6d1a3c8312f3 (diff) |
focus form items by following
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | src/content/follow.js | 19 | ||||
-rw-r--r-- | src/content/index.js | 31 |
3 files changed, 33 insertions, 19 deletions
@@ -44,7 +44,7 @@ Firefox by WebExtensions API. - [ ] hints - [x] open a link - [x] open a link in new tab - - [ ] activate input form + - [x] activate input form - [ ] misc - [ ] configurable keymaps - [ ] .rc file diff --git a/src/content/follow.js b/src/content/follow.js index 7e1cd01..f9cc380 100644 --- a/src/content/follow.js +++ b/src/content/follow.js @@ -125,20 +125,13 @@ export default class Follow { } static getTargetElements(doc) { - let all = doc.querySelectorAll('a'); - let filtered = Array.prototype.filter.call(all, (e) => { - return Follow.isVisibleElement(e); + let all = doc.querySelectorAll('a,button,input,textarea'); + let filtered = Array.prototype.filter.call(all, (element) => { + let style = window.getComputedStyle(element); + return style.display !== 'none' && + style.visibility !== 'hidden' && + element.type !== 'hidden'; }); return filtered; } - - static isVisibleElement(element) { - let style = window.getComputedStyle(element); - if (style.display === 'none') { - return false; - } else if (style.visibility === 'hidden') { - return false; - } - return true; - } } diff --git a/src/content/index.js b/src/content/index.js index 8848875..159429e 100644 --- a/src/content/index.js +++ b/src/content/index.js @@ -11,11 +11,32 @@ consoleFrames.initialize(window.document); const startFollows = (newTab) => { let follow = new Follow(window.document, newTab); follow.onActivated((element) => { - browser.runtime.sendMessage({ - type: messages.OPEN_URL, - url: element.href, - newTab - }); + switch (element.tagName.toLowerCase()) { + case 'a': + return browser.runtime.sendMessage({ + type: messages.OPEN_URL, + url: element.href, + newTab + }); + case 'input': + switch (element.type) { + case 'file': + case 'checkbox': + case 'radio': + case 'submit': + case 'reset': + case 'button': + case 'image': + case 'color': + return element.click(); + default: + return element.focus(); + } + case 'textarea': + return element.focus(); + case 'button': + return element.click(); + } }); }; |