Open URLs from bookmarks
This commit is contained in:
parent
76e09c7512
commit
582cc9a25a
3 changed files with 38 additions and 2 deletions
|
@ -32,7 +32,8 @@
|
||||||
"storage",
|
"storage",
|
||||||
"tabs",
|
"tabs",
|
||||||
"clipboardRead",
|
"clipboardRead",
|
||||||
"notifications"
|
"notifications",
|
||||||
|
"bookmarks"
|
||||||
],
|
],
|
||||||
"web_accessible_resources": [
|
"web_accessible_resources": [
|
||||||
"build/console.html",
|
"build/console.html",
|
||||||
|
|
15
src/background/shared/completions/bookmarks.js
Normal file
15
src/background/shared/completions/bookmarks.js
Normal file
|
@ -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:';
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export { getCompletions };
|
|
@ -1,5 +1,6 @@
|
||||||
import * as tabs from './tabs';
|
import * as tabs from './tabs';
|
||||||
import * as histories from './histories';
|
import * as histories from './histories';
|
||||||
|
import * as bookmarks from './bookmarks';
|
||||||
|
|
||||||
const getSearchCompletions = (command, keywords, searchConfig) => {
|
const getSearchCompletions = (command, keywords, searchConfig) => {
|
||||||
let engineNames = Object.keys(searchConfig.engines);
|
let engineNames = Object.keys(searchConfig.engines);
|
||||||
|
@ -23,11 +24,24 @@ const getHistoryCompletions = (command, keywords) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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) => {
|
const getOpenCompletions = (command, keywords, searchConfig) => {
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
getSearchCompletions(command, keywords, searchConfig),
|
getSearchCompletions(command, keywords, searchConfig),
|
||||||
getHistoryCompletions(command, keywords),
|
getHistoryCompletions(command, keywords),
|
||||||
]).then(([engineItems, historyItems]) => {
|
getBookmarksCompletions(command, keywords),
|
||||||
|
]).then(([engineItems, historyItems, bookmarkItems]) => {
|
||||||
let completions = [];
|
let completions = [];
|
||||||
if (engineItems.length > 0) {
|
if (engineItems.length > 0) {
|
||||||
completions.push({
|
completions.push({
|
||||||
|
@ -41,6 +55,12 @@ const getOpenCompletions = (command, keywords, searchConfig) => {
|
||||||
items: historyItems
|
items: historyItems
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (bookmarkItems.length > 0) {
|
||||||
|
completions.push({
|
||||||
|
name: 'Bookmarks',
|
||||||
|
items: bookmarkItems
|
||||||
|
});
|
||||||
|
}
|
||||||
return completions;
|
return completions;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
Reference in a new issue