diff options
Diffstat (limited to 'recipes/google-calendar/webview-unsafe.js')
-rw-r--r-- | recipes/google-calendar/webview-unsafe.js | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/recipes/google-calendar/webview-unsafe.js b/recipes/google-calendar/webview-unsafe.js new file mode 100644 index 0000000..0f4833e --- /dev/null +++ b/recipes/google-calendar/webview-unsafe.js | |||
@@ -0,0 +1,46 @@ | |||
1 | let modal; | ||
2 | let updates = 0; | ||
3 | |||
4 | const waitFor = (condition, callback) => { | ||
5 | if (condition()) { | ||
6 | callback(); | ||
7 | } else { | ||
8 | window.setTimeout(waitFor.bind(null, condition, callback), 100); | ||
9 | } | ||
10 | }; | ||
11 | |||
12 | const showModal = text => { | ||
13 | modal.querySelector('p').textContent = text; | ||
14 | updates += 1; | ||
15 | window.ferdium.setBadge(updates); | ||
16 | modal.classList.add('open'); | ||
17 | }; | ||
18 | |||
19 | const hideModal = () => { | ||
20 | modal.querySelector('p').textContent = ''; | ||
21 | updates -= 1; | ||
22 | window.ferdium.setBadge(updates); | ||
23 | modal.classList.remove('open'); | ||
24 | }; | ||
25 | |||
26 | const createModal = () => { | ||
27 | const modalDialog = document.createElement('div'); | ||
28 | modalDialog.setAttribute('id', 'franz-modal'); | ||
29 | modalDialog.textContent = | ||
30 | '<div class="modal-content"><span class="close">×</span><p></p></div>'; | ||
31 | modalDialog.querySelector('.close').addEventListener('click', hideModal); | ||
32 | |||
33 | return modalDialog; | ||
34 | }; | ||
35 | |||
36 | window.alert = showModal; | ||
37 | |||
38 | modal = createModal(); | ||
39 | waitFor( | ||
40 | () => document.body, | ||
41 | () => document.body.append(modal), | ||
42 | ); | ||
43 | document.addEventListener( | ||
44 | 'keydown', | ||
45 | event => event.key === 'Escape' && hideModal(), | ||
46 | ); | ||