-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathwebview.js
More file actions
38 lines (29 loc) · 1.11 KB
/
webview.js
File metadata and controls
38 lines (29 loc) · 1.11 KB
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
const path = require('path');
const performTextSubstitutions = require('electron-text-substitutions').default;
module.exports = (Franz) => {
const getMessages = function getMessages() {
const elements = document.querySelectorAll('.CxUIE, .unread');
let count = 0;
for (let i = 0; i < elements.length; i += 1) {
if (elements[i].querySelectorAll('*[data-icon="muted"]').length === 0) {
count += 1;
}
}
// set Franz badge
Franz.setBadge(count);
};
this.lastTextInput = null;
const attachTextSubstitutions = function attachTextSubstitutions() {
const textInput = document.querySelector('.copyable-text.selectable-text[contenteditable="true"]');
if (textInput && !this.lastTextInput !== textInput) {
performTextSubstitutions(textInput);
this.lastTextInput = textInput;
}
};
// inject franz.css stylesheet
Franz.injectCSS(path.join(__dirname, 'service.css'));
// check for new messages every second and update Franz badge
Franz.loop(getMessages);
// check for new text input to attach text substitutions
Franz.loop(attachTextSubstitutions);
};