-
Notifications
You must be signed in to change notification settings - Fork 1
/
chrome.js
62 lines (52 loc) · 1.31 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
59
60
61
62
export async function getCurrentTabUrl() {
const tab = await getCurrentTab();
return tab.url;
}
export function getCurrentTab() {
const query = {
active: true,
currentWindow: true
};
return new Promise((resolve, reject) => {
chrome.tabs.query(query, tabs => resolve(tabs[0]));
});
}
export function getTabById(tabId) {
return new Promise((resolve, reject) => {
chrome.tabs.get(tabId, resolve);
});
}
export async function navigateTo(url) {
const tab = await getCurrentTab();
if (!chrome.runtime.lastError) {
chrome.tabs.update(tab.id, { url: url });
}
}
export function searchCache(query) {
return new Promise((resolve, reject) => {
chrome.storage.local.get(query, resolve);
});
}
export function clearCache() {
return new Promise((resolve, reject) => {
chrome.storage.local.clear(resolve);
});
}
export function cache(data) {
return new Promise((resolve, reject) => {
chrome.storage.local.set(data, resolve);
});
}
export function updateOptions(data) {
return new Promise((resolve, reject) => {
chrome.storage.sync.set({ options: data }, resolve);
});
}
export function getOptions(query) {
return new Promise((resolve, reject) => {
chrome.storage.sync.get({ options: query }, data => resolve(data.options));
});
}
export function ignoreRejection(...args) {
return Promise.resolve();
}