-
Notifications
You must be signed in to change notification settings - Fork 5
/
webview.js
41 lines (32 loc) · 1.1 KB
/
webview.js
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
const path = require('path');
module.exports = Franz => {
let modal;
let updates = 0;
const createModal = () => {
const franzModal = document.createElement('div');
franzModal.setAttribute('id', 'franz-modal');
franzModal.innerHTML = '<div class="modal-content"><span class="close">×</span><p></p></div>';
franzModal.querySelector('.close').addEventListener('click', hideModal);
return franzModal;
};
const showModal = text => {
modal.querySelector('p').innerHTML = text;
updates++;
modal.classList.add('open');
};
const hideModal = () => {
modal.querySelector('p').innerHTML = '';
updates--;
updates = updates < 0 ? 0 : updates;
modal.classList.remove('open');
};
window.alert = showModal;
const getMessages = () => Franz.setBadge(updates);
modal = createModal();
document.addEventListener('DOMContentLoaded', event => {
document.body.appendChild(modal);
document.addEventListener('keydown', event => event.keyCode === 27 && hideModal());
});
Franz.injectCSS(path.join(__dirname, 'calendar.css'));
Franz.loop(getMessages);
};