diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/content/follow.js | 19 | ||||
-rw-r--r-- | src/content/index.js | 31 |
2 files changed, 32 insertions, 18 deletions
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(); + } }); }; |