aboutsummaryrefslogtreecommitdiff
path: root/src/background/repositories/CompletionsRepository.ts
blob: 7d0434cca74587bdd95fdec136e6fb89d8623fb6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { injectable } from 'tsyringe';

type Tab = browser.tabs.Tab;

@injectable()
export default class CompletionsRepository {
  async queryTabs(keywords: string, excludePinned: boolean): Promise<Tab[]> {
    const tabs = await browser.tabs.query({ currentWindow: true });
    return tabs.filter((t) => {
      return t.url && t.url.toLowerCase().includes(keywords.toLowerCase()) ||
        t.title && t.title.toLowerCase().includes(keywords.toLowerCase());
    }).filter((t) => {
      return !(excludePinned && t.pinned);
    });
  }
}