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