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