blob: 7840600124859f4429dcd2c06ef84bece136b8ba (
plain) (
blame)
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
45
46
|
let modal;
let updates = 0;
const waitFor = (condition, callback) => {
if (!condition()) {
window.setTimeout(waitFor.bind(null, condition, callback), 100);
} else {
callback();
}
};
const showModal = text => {
modal.querySelector('p').textContent = text;
updates += 1;
window.ferdium.setBadge(updates);
modal.classList.add('open');
};
const hideModal = () => {
modal.querySelector('p').textContent = '';
updates -= 1;
window.ferdium.setBadge(updates);
modal.classList.remove('open');
};
const createModal = () => {
const modalDialog = document.createElement('div');
modalDialog.setAttribute('id', 'franz-modal');
modalDialog.textContent =
'<div class="modal-content"><span class="close">×</span><p></p></div>';
modalDialog.querySelector('.close').addEventListener('click', hideModal);
return modalDialog;
};
window.alert = showModal;
modal = createModal();
waitFor(
() => document.body,
() => document.body.append(modal),
);
document.addEventListener(
'keydown',
event => event.key === 'Escape' && hideModal(),
);
|