blob: c47f572814f80b64958a7763970181a803da9017 (
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
|
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').innerHTML = text;
updates += 1;
window.ferdi.setBadge(updates);
modal.classList.add('open');
};
const hideModal = () => {
modal.querySelector('p').innerHTML = '';
updates -= 1;
window.ferdi.setBadge(updates);
modal.classList.remove('open');
};
const createModal = () => {
const modalDialog = document.createElement('div');
modalDialog.setAttribute('id', 'franz-modal');
modalDialog.innerHTML = '<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.appendChild(modal));
document.addEventListener('keydown', event => event.keyCode === 27 && hideModal());
|