From a26d8a8a1bed48a77e062914c120a23ace7bb8cf Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 24 Feb 2019 20:54:35 +0900 Subject: Capitalize background scripts --- .../repositories/CompletionsRepository.js | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/background/repositories/CompletionsRepository.js (limited to 'src/background/repositories/CompletionsRepository.js') diff --git a/src/background/repositories/CompletionsRepository.js b/src/background/repositories/CompletionsRepository.js new file mode 100644 index 0000000..1318d36 --- /dev/null +++ b/src/background/repositories/CompletionsRepository.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); + }); + } +} -- cgit v1.2.3