-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchrome.js
58 lines (48 loc) · 1.25 KB
/
chrome.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
export async function getCurrentTabUrl() {
const tab = await getCurrentTab();
return tab.url;
}
export async function getCurrentTabIndex() {
const tab = await getCurrentTab();
return tab.index;
}
export async function getCurrentTab() {
const tabs = await chrome.tabs.query({
active: true,
currentWindow: true
});
return tabs[0];
}
export async function getTabById(tabId) {
const tab = await chrome.tabs.get(parseInt(tabId));
if (chrome.runtime.lastError) {
console.log(chrome.runtime.lastError);
throw Error(chrome.runtime.lastError);
}
return tab;
}
export async function navigateTo(url) {
const tab = await getCurrentTab();
if (!chrome.runtime.lastError) {
await chrome.tabs.update(tab.id, { url: url });
}
}
export async function searchCache(query) {
return chrome.storage.local.get(query);
}
export async function clearCache() {
await chrome.storage.local.clear();
}
export async function cache(data) {
await chrome.storage.local.set(data);
}
export async function updateOptions(data) {
await chrome.storage.sync.set({ options: data });
}
export async function getOptions(query) {
const data = await chrome.storage.sync.get({ options: query });
return data.options;
}
export function ignoreRejection(...args) {
return Promise.resolve();
}