focus form items by following

jh-changes
Shin'ya Ueoka 7 years ago
parent ba2022c465
commit 324cf32c5b
  1. 2
      README.md
  2. 19
      src/content/follow.js
  3. 23
      src/content/index.js

@ -44,7 +44,7 @@ Firefox by WebExtensions API.
- [ ] hints - [ ] hints
- [x] open a link - [x] open a link
- [x] open a link in new tab - [x] open a link in new tab
- [ ] activate input form - [x] activate input form
- [ ] misc - [ ] misc
- [ ] configurable keymaps - [ ] configurable keymaps
- [ ] .rc file - [ ] .rc file

@ -125,20 +125,13 @@ export default class Follow {
} }
static getTargetElements(doc) { static getTargetElements(doc) {
let all = doc.querySelectorAll('a'); let all = doc.querySelectorAll('a,button,input,textarea');
let filtered = Array.prototype.filter.call(all, (e) => { let filtered = Array.prototype.filter.call(all, (element) => {
return Follow.isVisibleElement(e); let style = window.getComputedStyle(element);
return style.display !== 'none' &&
style.visibility !== 'hidden' &&
element.type !== 'hidden';
}); });
return filtered; 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;
}
} }

@ -11,11 +11,32 @@ consoleFrames.initialize(window.document);
const startFollows = (newTab) => { const startFollows = (newTab) => {
let follow = new Follow(window.document, newTab); let follow = new Follow(window.document, newTab);
follow.onActivated((element) => { follow.onActivated((element) => {
browser.runtime.sendMessage({ switch (element.tagName.toLowerCase()) {
case 'a':
return browser.runtime.sendMessage({
type: messages.OPEN_URL, type: messages.OPEN_URL,
url: element.href, url: element.href,
newTab 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();
}
}); });
}; };