-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathbackground.ts
More file actions
30 lines (27 loc) · 875 Bytes
/
background.ts
File metadata and controls
30 lines (27 loc) · 875 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
import { defaultSettings, getAllChromeSettings } from './helpers/chromeSettings';
let settings = defaultSettings;
const updateNewestSettings = () => {
getAllChromeSettings().then((chromeSettings: object) => {
settings = {
...defaultSettings, ...chromeSettings
};
// broadcast changes to injected scripts
window.postMessage({
untrustedTypes: true,
type: 'settingsChanged',
value: settings
}, '*');
});
};
chrome.storage.onChanged.addListener(updateNewestSettings);
updateNewestSettings();
// dynamically return current settings
chrome.webRequest.onBeforeRequest.addListener(
() => ({
redirectUrl: 'data:application/json,' + encodeURIComponent(JSON.stringify(settings))
}),
{
urls: [chrome.runtime.getURL('settings.json')]
},
['blocking']
);