blob: 7d137515079d75c5e59c7c40a9a6e93e04ed0b85 (
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
const _path = _interopRequireDefault(require('path'));
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : { default: obj };
}
function show(element) {
element.style.display = 'inherit';
}
function hide(element) {
element.style.display = 'none';
}
module.exports = Ferdium => {
const modal = document.createElement('div');
const waitFor = (condition, callback) => {
if (!condition()) {
window.setTimeout(waitFor.bind(null, condition, callback), 100);
} else {
callback();
}
};
function showModal(text) {
show(modal);
let p = modal.querySelector('p');
if (p) {
p.textContent = text;
}
}
function hideModal() {
hide(modal);
let p = modal.querySelector('p');
if (p) {
p.textContent = '';
}
}
// Replace window.alert to hide alerts in Ferdium
const oldAlert = window.alert;
window.alert = function () {
// when Google Calendar displays an alert notify the user
showModal.apply(oldAlert, arguments);
};
modal.id = 'franz-modal';
modal.textContent =
'<div class="modal-content"><span class="close">×</span><p></p></div>';
let close = modal.querySelector('.close');
if (close) {
close.addEventListener('click', hideModal);
}
waitFor(
() => document.body,
() => document.body.append(modal),
);
document.addEventListener('keydown', e => {
if (e.key === 'Escape') {
hideModal();
}
});
Ferdium.injectCSS(_path.default.join(__dirname, 'css', 'modal.css'));
};
|