allow to open link in new tab

jh-changes
Shin'ya Ueoka 7 years ago
parent 655ac16f38
commit ba2022c465
  1. 2
      README.md
  2. 9
      src/actions/tab.js
  3. 8
      src/background/index.js
  4. 6
      src/content/index.js
  5. 4
      src/messages/index.js

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

@ -0,0 +1,9 @@
const openNewTab = (url) => {
return browser.tabs.create({ url: url });
};
const openToTab = (url, tab) => {
return browser.tabs.update(tab.id, { url: url });
};
export { openToTab, openNewTab };

@ -3,6 +3,7 @@ import * as inputActions from '../actions/input';
import * as operationActions from '../actions/operation';
import * as commandActions from '../actions/command';
import * as consoleActions from '../actions/console';
import * as tabActions from '../actions/tab';
import reducers from '../reducers';
import messages from '../messages';
import * as store from '../store';
@ -60,6 +61,13 @@ const handleMessage = (message, sender) => {
case messages.KEYDOWN:
return backgroundStore.dispatch(
inputActions.keyPress(message.code, message.ctrl), sender);
case messages.OPEN_URL:
if (message.newTab) {
return backgroundStore.dispatch(
tabActions.openNewTab(message.url), sender);
}
return backgroundStore.dispatch(
tabActions.openToTab(message.url, sender.tab), sender);
case messages.CONSOLE_BLURRED:
return backgroundStore.dispatch(
consoleActions.hide(), sender);

@ -11,7 +11,11 @@ consoleFrames.initialize(window.document);
const startFollows = (newTab) => {
let follow = new Follow(window.document, newTab);
follow.onActivated((element) => {
element.click();
browser.runtime.sendMessage({
type: messages.OPEN_URL,
url: element.href,
newTab
});
});
};

@ -6,5 +6,7 @@ export default {
CONSOLE_ENTERED: 'console.entered',
CONSOLE_CHANGEED: 'console.changed',
KEYDOWN: 'keydown'
KEYDOWN: 'keydown',
OPEN_URL: 'open.url'
};