From d0eba2546a559922a53b59de44e7946b9d6b7c84 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Mon, 7 May 2018 22:00:30 +0900 Subject: [PATCH] addbookmark command --- src/background/actions/command.js | 13 ++++++++++++- src/background/components/background.js | 2 +- src/background/shared/bookmarks.js | 9 +++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 src/background/shared/bookmarks.js diff --git a/src/background/actions/command.js b/src/background/actions/command.js index 2f7305a..e46a97e 100644 --- a/src/background/actions/command.js +++ b/src/background/actions/command.js @@ -1,5 +1,6 @@ import actions from '../actions'; import * as tabs from '../shared/tabs'; +import * as bookmarks from '../shared/bookmarks'; import * as parsers from 'shared/commands/parsers'; import * as properties from 'shared/settings/properties'; @@ -39,6 +40,14 @@ const bufferCommand = (keywords) => { }); }; +const addBookmarkCommand = (tab, args) => { + if (!args[0]) { + return Promise.resolve(); + } + + return bookmarks.create(args[0], tab.url); +}; + const setCommand = (args) => { if (!args[0]) { return Promise.resolve(); @@ -52,7 +61,7 @@ const setCommand = (args) => { }; }; -const exec = (line, settings) => { +const exec = (tab, line, settings) => { let [name, args] = parsers.parseCommandLine(line); switch (name) { @@ -68,6 +77,8 @@ const exec = (line, settings) => { case 'b': case 'buffer': return bufferCommand(args); + case 'addbookmark': + return addBookmarkCommand(tab, args); case 'set': return setCommand(args); case '': diff --git a/src/background/components/background.js b/src/background/components/background.js index e13424b..29124a6 100644 --- a/src/background/components/background.js +++ b/src/background/components/background.js @@ -37,7 +37,7 @@ export default class BackgroundComponent { tabActions.openToTab(message.url, sender.tab), sender); case messages.CONSOLE_ENTER_COMMAND: this.store.dispatch( - commandActions.exec(message.text, settings.value), + commandActions.exec(sender.tab, message.text, settings.value), sender ); return this.broadcastSettingsChanged(); diff --git a/src/background/shared/bookmarks.js b/src/background/shared/bookmarks.js new file mode 100644 index 0000000..5e7927b --- /dev/null +++ b/src/background/shared/bookmarks.js @@ -0,0 +1,9 @@ +const create = (title, url) => { + return browser.bookmarks.create({ + type: 'bookmark', + title, + url, + }); +}; + +export { create };