blob: 1e182660002001c2469007dc2f7a8da65d396d88 (
plain) (
blame)
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
|
import 'webext-dynamic-content-scripts';
import cache from 'webext-storage-cache'; // Also needed to regularly clear the cache
import addDomainPermissionToggle from 'webext-domain-permission-toggle';
import './options-storage';
browser.runtime.onMessage.addListener((message, {tab}) => {
if (Array.isArray(message?.openUrls)) {
for (const [i, url] of (message.openUrls as string[]).entries()) {
void browser.tabs.create({
url,
index: tab!.index + i + 1,
active: false
});
}
}
});
// Give the browserAction a reason to exist other than "Enable RGH on this domain"
browser.browserAction.onClicked.addListener(() => {
void browser.tabs.create({
url: 'https://github.com'
});
});
browser.runtime.onInstalled.addListener(async ({reason}) => {
// Only notify on install
if (reason === 'install') {
const {installType} = await browser.management.getSelf();
if (installType === 'development') {
return;
}
await browser.tabs.create({
url: 'https://github.com/sindresorhus/refined-github/issues/3543',
active: false
});
}
// Hope that the feature was fixed in this version
await cache.delete('hotfix');
});
// GitHub Enterprise support
addDomainPermissionToggle();
// `background` fetch required to avoid avoid CORB introduced in Chrome 73 https://chromestatus.com/feature/5629709824032768
// Don’t turn this into an `async` function https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/runtime/onMessage#addListener_syntax
browser.runtime.onMessage.addListener((message): Promise<string> | void => {
if (message?.request) {
return fetch(message.request).then(async response => response.text());
}
});
|