-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathshared.js
More file actions
31 lines (25 loc) · 740 Bytes
/
shared.js
File metadata and controls
31 lines (25 loc) · 740 Bytes
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
if (typeof globalThis.browser === 'undefined') {
globalThis.browser = chrome
}
export function saveProxies(proxies) {
return browser.storage.sync.set({ proxies })
}
export async function loadProxies() {
const items = await browser.storage.sync.get('proxies')
return items.proxies || []
}
export function transformURL(url, proxy) {
if (proxy.indexOf('$@') === -1) {
throw new Error('proxy missing replacement token')
}
if (!url.startsWith('http://') && !url.startsWith('https://')) {
throw new Error('not proxying http or https')
}
return proxy.replace('$@', url)
}
export async function openNewTab(url) {
browser.tabs.create({ url })
}
export async function reloadTab(tab, url) {
browser.tabs.update(tab.id, { url })
}