This repository has been archived by the owner on Jan 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webview.js
61 lines (50 loc) · 1.64 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'use strict';
const path = require('path');
// works for any "type" of tab loaded (Chats/Spaces, DMs, Mentions)
function getGenericUnreadCountForType(){
return (document.querySelectorAll('ul.ic-spaces .ic-news').length || 0);
}
function getSpacesHasUnread(){
return !!document.querySelector('.ic-menu-spaces.ic-has-unread');
}
function getDirectMessagesHasUnread(){
return !!document.querySelector('.ic-direct-messages.ic-has-unread');
}
function getMentionsHasUnread(){
return !!document.querySelector('.ic-mentions.ic-has-unread');
}
module.exports = Franz => {
const getMessages = function getMessages() {
let directCount = 0;
let indirectCount = 0;
/*
* NOTE: if WW ever changes its high level behavior to allow for better querySelector access
* to unread counts, this can change to be more specific, for now, it's only specific for
* when the user is in the "tab" of the type, making it inelegant
*/
/*
// selected into a type of space
if(document.querySelector('.ic-conversations-header')){
const label = document.querySelector('.ic-conversations-header h2').innerText;
}
*/
if( getGenericUnreadCountForType() ){
indirectCount++;
}
if( getSpacesHasUnread() ){
indirectCount++;
}
if( getDirectMessagesHasUnread() ){
directCount++;
}
if( getMentionsHasUnread() ){
directCount++;
}
// set Franz badges
Franz.setBadge(directCount, indirectCount);
};
// inject franz.css stylesheet
Franz.injectCSS(path.join(__dirname, 'service.css'));
// check for new messages every second and update Franz badge
Franz.loop(getMessages);
};