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. 31
      src/content/index.js

@ -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

@ -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;
}
}

@ -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();
}
});
};