aboutsummaryrefslogtreecommitdiff
path: root/src/background/repositories/completions.js
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2018-07-28 20:05:06 +0900
committerGitHub <noreply@github.com>2018-07-28 20:05:06 +0900
commited2bd7d75ee1e7aa1db7d03c3f908c740ded1983 (patch)
tree6ac3f5ac5126e1a07c958549c782aedd586c6534 /src/background/repositories/completions.js
parent84a9655bb39e5902b417e124a0eb23d80808a6a7 (diff)
parent4bd2084ba7b23327c26a2d8b24dc4169c14bfa17 (diff)
Merge pull request #440 from ueokande/background-clean-architecture
Background clean architecture
Diffstat (limited to 'src/background/repositories/completions.js')
-rw-r--r--src/background/repositories/completions.js31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/background/repositories/completions.js b/src/background/repositories/completions.js
new file mode 100644
index 0000000..1318d36
--- /dev/null
+++ b/src/background/repositories/completions.js
@@ -0,0 +1,31 @@
+export default class CompletionsRepository {
+ async queryBookmarks(keywords) {
+ let items = await browser.bookmarks.search({ query: keywords });
+ return items.filter((item) => {
+ let url = undefined;
+ try {
+ url = new URL(item.url);
+ } catch (e) {
+ return false;
+ }
+ return item.type === 'bookmark' && url.protocol !== 'place:';
+ });
+ }
+
+ queryHistories(keywords) {
+ return browser.history.search({
+ text: keywords,
+ startTime: 0,
+ });
+ }
+
+ async queryTabs(keywords, excludePinned) {
+ let tabs = await browser.tabs.query({ currentWindow: true });
+ return tabs.filter((t) => {
+ return t.url.toLowerCase().includes(keywords.toLowerCase()) ||
+ t.title && t.title.toLowerCase().includes(keywords.toLowerCase());
+ }).filter((t) => {
+ return !(excludePinned && t.pinned);
+ });
+ }
+}