addbookmark command
This commit is contained in:
parent
ef6bbd117e
commit
d0eba2546a
3 changed files with 22 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
||||||
import actions from '../actions';
|
import actions from '../actions';
|
||||||
import * as tabs from '../shared/tabs';
|
import * as tabs from '../shared/tabs';
|
||||||
|
import * as bookmarks from '../shared/bookmarks';
|
||||||
import * as parsers from 'shared/commands/parsers';
|
import * as parsers from 'shared/commands/parsers';
|
||||||
import * as properties from 'shared/settings/properties';
|
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) => {
|
const setCommand = (args) => {
|
||||||
if (!args[0]) {
|
if (!args[0]) {
|
||||||
return Promise.resolve();
|
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);
|
let [name, args] = parsers.parseCommandLine(line);
|
||||||
|
|
||||||
switch (name) {
|
switch (name) {
|
||||||
|
@ -68,6 +77,8 @@ const exec = (line, settings) => {
|
||||||
case 'b':
|
case 'b':
|
||||||
case 'buffer':
|
case 'buffer':
|
||||||
return bufferCommand(args);
|
return bufferCommand(args);
|
||||||
|
case 'addbookmark':
|
||||||
|
return addBookmarkCommand(tab, args);
|
||||||
case 'set':
|
case 'set':
|
||||||
return setCommand(args);
|
return setCommand(args);
|
||||||
case '':
|
case '':
|
||||||
|
|
|
@ -37,7 +37,7 @@ export default class BackgroundComponent {
|
||||||
tabActions.openToTab(message.url, sender.tab), sender);
|
tabActions.openToTab(message.url, sender.tab), sender);
|
||||||
case messages.CONSOLE_ENTER_COMMAND:
|
case messages.CONSOLE_ENTER_COMMAND:
|
||||||
this.store.dispatch(
|
this.store.dispatch(
|
||||||
commandActions.exec(message.text, settings.value),
|
commandActions.exec(sender.tab, message.text, settings.value),
|
||||||
sender
|
sender
|
||||||
);
|
);
|
||||||
return this.broadcastSettingsChanged();
|
return this.broadcastSettingsChanged();
|
||||||
|
|
9
src/background/shared/bookmarks.js
Normal file
9
src/background/shared/bookmarks.js
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
const create = (title, url) => {
|
||||||
|
return browser.bookmarks.create({
|
||||||
|
type: 'bookmark',
|
||||||
|
title,
|
||||||
|
url,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export { create };
|
Reference in a new issue