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