aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/background/actions/command.js25
-rw-r--r--src/background/components/background.js2
-rw-r--r--src/background/components/operation.js5
-rw-r--r--src/background/shared/bookmarks.js9
-rw-r--r--src/shared/operations.js1
-rw-r--r--src/shared/settings/default.js1
6 files changed, 41 insertions, 2 deletions
diff --git a/src/background/actions/command.js b/src/background/actions/command.js
index 2f7305a..be742cd 100644
--- a/src/background/actions/command.js
+++ b/src/background/actions/command.js
@@ -1,5 +1,7 @@
+import messages from 'shared/messages';
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 +41,14 @@ const bufferCommand = (keywords) => {
});
};
+const addBookmarkCommand = (tab, args) => {
+ if (!args[0]) {
+ return Promise.resolve();
+ }
+
+ return bookmarks.create(args.join(' '), tab.url);
+};
+
const setCommand = (args) => {
if (!args[0]) {
return Promise.resolve();
@@ -52,7 +62,7 @@ const setCommand = (args) => {
};
};
-const exec = (line, settings) => {
+const exec = (tab, line, settings) => {
let [name, args] = parsers.parseCommandLine(line);
switch (name) {
@@ -68,6 +78,19 @@ const exec = (line, settings) => {
case 'b':
case 'buffer':
return bufferCommand(args);
+ case 'addbookmark':
+ return addBookmarkCommand(tab, args).then((item) => {
+ if (!item) {
+ return browser.tabs.sendMessage(tab.id, {
+ type: messages.CONSOLE_SHOW_ERROR,
+ text: 'Could not create a bookmark',
+ });
+ }
+ return browser.tabs.sendMessage(tab.id, {
+ type: messages.CONSOLE_SHOW_INFO,
+ text: 'Saved current page: ' + item.url,
+ });
+ });
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/components/operation.js b/src/background/components/operation.js
index 9a0b4e1..58edb8c 100644
--- a/src/background/components/operation.js
+++ b/src/background/components/operation.js
@@ -90,6 +90,11 @@ export default class BackgroundComponent {
return this.sendConsoleShowCommand(tab, 'winopen ');
case operations.COMMAND_SHOW_BUFFER:
return this.sendConsoleShowCommand(tab, 'buffer ');
+ case operations.COMMAND_SHOW_ADDBOOKMARK:
+ if (operation.alter) {
+ return this.sendConsoleShowCommand(tab, 'addbookmark ' + tab.title);
+ }
+ return this.sendConsoleShowCommand(tab, 'addbookmark ');
case operations.FIND_START:
return browser.tabs.sendMessage(tab.id, {
type: messages.CONSOLE_SHOW_FIND
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 };
diff --git a/src/shared/operations.js b/src/shared/operations.js
index e8cc8cf..b022537 100644
--- a/src/shared/operations.js
+++ b/src/shared/operations.js
@@ -13,6 +13,7 @@ export default {
COMMAND_SHOW_TABOPEN: 'command.show.tabopen',
COMMAND_SHOW_WINOPEN: 'command.show.winopen',
COMMAND_SHOW_BUFFER: 'command.show.buffer',
+ COMMAND_SHOW_ADDBOOKMARK: 'command.show.addbookmark',
// Scrolls
SCROLL_VERTICALLY: 'scroll.vertically',
diff --git a/src/shared/settings/default.js b/src/shared/settings/default.js
index 9e1c202..a435099 100644
--- a/src/shared/settings/default.js
+++ b/src/shared/settings/default.js
@@ -11,6 +11,7 @@ export default {
"w": { "type": "command.show.winopen", "alter": false },
"W": { "type": "command.show.winopen", "alter": true },
"b": { "type": "command.show.buffer" },
+ "a": { "type": "command.show.addbookmark", "alter": true },
"k": { "type": "scroll.vertically", "count": -1 },
"j": { "type": "scroll.vertically", "count": 1 },
"h": { "type": "scroll.horizonally", "count": -1 },