forked from johnpantini/ppp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
44 lines (36 loc) · 1.12 KB
/
main.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
function appendMainScript() {
const script = document.createElement('script');
script.src = 'ppp.js';
script.type = 'module';
document.body.append(script);
}
window.addEventListener('load', async () => {
const globalProxyUrlInput = document.body.querySelector('.global-proxy-url');
globalProxyUrlInput.value =
localStorage.getItem('ppp-global-proxy-url') ?? '';
globalProxyUrlInput.addEventListener('input', (e) => {
localStorage.setItem('ppp-global-proxy-url', e.target.value.trim());
});
const registration = await navigator.serviceWorker.register('ppp-sw.js');
if (navigator.serviceWorker.controller === null) {
await navigator.serviceWorker.ready;
registration.active.postMessage('reclaim');
navigator.serviceWorker.addEventListener(
'controllerchange',
appendMainScript
);
} else {
appendMainScript();
}
});
window.customElements.define(
'ppp-loader',
class extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' }).appendChild(
document.getElementById('ppp-loader').content.cloneNode(true)
);
}
}
);