aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2018-05-08 20:42:31 +0900
committerGitHub <noreply@github.com>2018-05-08 20:42:31 +0900
commitef6bbd117e042fecea85b2dbb8294ad60e4e8d48 (patch)
treea45d82bfe44cf23ca3d93bd202fd29cb8ca19869 /src
parent104a9666ff627b11ce7cf3a5bf096b1bc3437bc1 (diff)
parent11d0bebbc5c95f036304755399d8994be1658330 (diff)
Merge pull request #387 from ueokande/open-from-bookmarks
Open URLs from bookmarks
Diffstat (limited to 'src')
-rw-r--r--src/background/shared/completions/bookmarks.js15
-rw-r--r--src/background/shared/completions/index.js47
2 files changed, 54 insertions, 8 deletions
diff --git a/src/background/shared/completions/bookmarks.js b/src/background/shared/completions/bookmarks.js
new file mode 100644
index 0000000..1adb350
--- /dev/null
+++ b/src/background/shared/completions/bookmarks.js
@@ -0,0 +1,15 @@
+const getCompletions = (keywords) => {
+ return browser.bookmarks.search({ query: keywords }).then((items) => {
+ return items.filter((item) => {
+ let url = undefined;
+ try {
+ url = new URL(item.url);
+ } catch (e) {
+ return false;
+ }
+ return item.type === 'bookmark' && url.protocol !== 'place:';
+ }).slice(0, 10);
+ });
+};
+
+export { getCompletions };
diff --git a/src/background/shared/completions/index.js b/src/background/shared/completions/index.js
index 73b7b27..8ecdcfc 100644
--- a/src/background/shared/completions/index.js
+++ b/src/background/shared/completions/index.js
@@ -1,22 +1,47 @@
import * as tabs from './tabs';
import * as histories from './histories';
+import * as bookmarks from './bookmarks';
-const getOpenCompletions = (command, keywords, searchConfig) => {
+const getSearchCompletions = (command, keywords, searchConfig) => {
+ let engineNames = Object.keys(searchConfig.engines);
+ let engineItems = engineNames.filter(name => name.startsWith(keywords))
+ .map(name => ({
+ caption: name,
+ content: command + ' ' + name
+ }));
+ return Promise.resolve(engineItems);
+};
+
+const getHistoryCompletions = (command, keywords) => {
return histories.getCompletions(keywords).then((pages) => {
- let historyItems = pages.map((page) => {
+ return pages.map((page) => {
return {
caption: page.title,
content: command + ' ' + page.url,
url: page.url
};
});
- let engineNames = Object.keys(searchConfig.engines);
- let engineItems = engineNames.filter(name => name.startsWith(keywords))
- .map(name => ({
- caption: name,
- content: command + ' ' + name
- }));
+ });
+};
+const getBookmarksCompletions = (command, keywords) => {
+ return bookmarks.getCompletions(keywords).then((items) => {
+ return items.map((item) => {
+ return {
+ caption: item.title,
+ content: command + ' ' + item.url,
+ url: item.url,
+ };
+ });
+ });
+};
+
+const getOpenCompletions = (command, keywords, searchConfig) => {
+ return Promise.all([
+ getSearchCompletions(command, keywords, searchConfig),
+ getHistoryCompletions(command, keywords),
+ getBookmarksCompletions(command, keywords),
+ ]).then(([engineItems, historyItems, bookmarkItems]) => {
let completions = [];
if (engineItems.length > 0) {
completions.push({
@@ -30,6 +55,12 @@ const getOpenCompletions = (command, keywords, searchConfig) => {
items: historyItems
});
}
+ if (bookmarkItems.length > 0) {
+ completions.push({
+ name: 'Bookmarks',
+ items: bookmarkItems
+ });
+ }
return completions;
});
};