aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2017-09-17 17:13:48 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2017-09-17 17:15:14 +0900
commitba2022c46585a2f365eb4939faff6d1a3c8312f3 (patch)
treef6683de2a86ac3dccbeaa3cfd5b862b5b23d1025
parent655ac16f3835ea34d87d952817053ec0d8ee797f (diff)
allow to open link in new tab
-rw-r--r--README.md2
-rw-r--r--src/actions/tab.js9
-rw-r--r--src/background/index.js8
-rw-r--r--src/content/index.js6
-rw-r--r--src/messages/index.js4
5 files changed, 26 insertions, 3 deletions
diff --git a/README.md b/README.md
index bc17cf6..28ff1a9 100644
--- a/README.md
+++ b/README.md
@@ -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
diff --git a/src/actions/tab.js b/src/actions/tab.js
new file mode 100644
index 0000000..e512b6f
--- /dev/null
+++ b/src/actions/tab.js
@@ -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 };
diff --git a/src/background/index.js b/src/background/index.js
index a4217c1..9df22fd 100644
--- a/src/background/index.js
+++ b/src/background/index.js
@@ -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);
diff --git a/src/content/index.js b/src/content/index.js
index fc79f6c..8848875 100644
--- a/src/content/index.js
+++ b/src/content/index.js
@@ -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
+ });
});
};
diff --git a/src/messages/index.js b/src/messages/index.js
index 3bdecca..4e34436 100644
--- a/src/messages/index.js
+++ b/src/messages/index.js
@@ -6,5 +6,7 @@ export default {
CONSOLE_ENTERED: 'console.entered',
CONSOLE_CHANGEED: 'console.changed',
- KEYDOWN: 'keydown'
+ KEYDOWN: 'keydown',
+
+ OPEN_URL: 'open.url'
};