diff options
Diffstat (limited to 'recipes/basecamp/webview.js')
-rw-r--r-- | recipes/basecamp/webview.js | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/recipes/basecamp/webview.js b/recipes/basecamp/webview.js new file mode 100644 index 0000000..2158d0b --- /dev/null +++ b/recipes/basecamp/webview.js | |||
@@ -0,0 +1,59 @@ | |||
1 | const path = require('path'); | ||
2 | |||
3 | module.exports = (Franz, options) => { | ||
4 | let updates = 0; | ||
5 | const modal = document.createElement('div'); | ||
6 | |||
7 | function showModal (text) { | ||
8 | show(modal); | ||
9 | modal.querySelector('p').innerHTML = text; | ||
10 | updates += 1; | ||
11 | } | ||
12 | |||
13 | function hideModal () { | ||
14 | hide(modal); | ||
15 | modal.querySelector('p').innerHTML = ''; | ||
16 | updates -= 1; | ||
17 | } | ||
18 | |||
19 | // Replace window.alert to hide alerts in Franz | ||
20 | const oldAlert = window.alert; | ||
21 | window.alert = function () { | ||
22 | // when Google Calendar displays an alert notify the user | ||
23 | showModal.apply(oldAlert, arguments); | ||
24 | }; | ||
25 | |||
26 | function show (element) { | ||
27 | element.style.display = 'inherit'; | ||
28 | } | ||
29 | |||
30 | function hide (element) { | ||
31 | element.style.display = 'none'; | ||
32 | } | ||
33 | |||
34 | const getMessages = () => { | ||
35 | // get unread messages | ||
36 | //const updates = document.getElementById('franz').getAttribute('data-unread'); | ||
37 | |||
38 | // get conversations in 'My Inbox' | ||
39 | //const inbox = document.getElementById('franz').getAttribute('data-inbox'); | ||
40 | |||
41 | // set Franz badge | ||
42 | // updates => passive unread count | ||
43 | // inbox => active unread count | ||
44 | Franz.setBadge(0, updates); | ||
45 | }; | ||
46 | |||
47 | modal.id = 'franz-modal'; | ||
48 | modal.innerHTML = '<div class="modal-content"><span class="close">×</span><p></p></div>'; | ||
49 | modal.querySelector('.close').addEventListener('click', hideModal); | ||
50 | document.body.appendChild(modal); | ||
51 | |||
52 | document.addEventListener('keydown', function(e) { if (e.keyCode === 27) { hideModal(); } }) | ||
53 | |||
54 | // inject franz.css stylesheet | ||
55 | Franz.injectCSS(path.join(__dirname, 'css', 'modal.css')); | ||
56 | |||
57 | // check for new messages every second and update Franz badge | ||
58 | Franz.loop(getMessages); | ||
59 | }; | ||