blob: 2158d0bf69cf8e02a015d39c0d1d54638f72b285 (
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
|
const path = require('path');
module.exports = (Franz, options) => {
let updates = 0;
const modal = document.createElement('div');
function showModal (text) {
show(modal);
modal.querySelector('p').innerHTML = text;
updates += 1;
}
function hideModal () {
hide(modal);
modal.querySelector('p').innerHTML = '';
updates -= 1;
}
// Replace window.alert to hide alerts in Franz
const oldAlert = window.alert;
window.alert = function () {
// when Google Calendar displays an alert notify the user
showModal.apply(oldAlert, arguments);
};
function show (element) {
element.style.display = 'inherit';
}
function hide (element) {
element.style.display = 'none';
}
const getMessages = () => {
// get unread messages
//const updates = document.getElementById('franz').getAttribute('data-unread');
// get conversations in 'My Inbox'
//const inbox = document.getElementById('franz').getAttribute('data-inbox');
// set Franz badge
// updates => passive unread count
// inbox => active unread count
Franz.setBadge(0, updates);
};
modal.id = 'franz-modal';
modal.innerHTML = '<div class="modal-content"><span class="close">×</span><p></p></div>';
modal.querySelector('.close').addEventListener('click', hideModal);
document.body.appendChild(modal);
document.addEventListener('keydown', function(e) { if (e.keyCode === 27) { hideModal(); } })
// inject franz.css stylesheet
Franz.injectCSS(path.join(__dirname, 'css', 'modal.css'));
// check for new messages every second and update Franz badge
Franz.loop(getMessages);
};
|