-
Notifications
You must be signed in to change notification settings - Fork 0
/
webview.js
62 lines (56 loc) · 1.51 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
62
"use strict";
module.exports = Franz => {
const contains = function (selector, text) {
const elements = document.querySelectorAll(selector);
return Array.prototype.filter.call(elements, function (element) {
return RegExp(text).test(element.textContent);
});
};
const getMessages = function getMessages() {
let unread = 0;
try {
// old layout
unread += parseInt(
contains('#workflow span.tray-display-name', 'Awaiting Shipment')[0]
.parentElement
.querySelector('.status-count')
.textContent
.replace(',', ''),
10,
);
unread += parseInt(
contains('#workflow span.tray-display-name', 'On Hold')[0]
.parentElement
.querySelector('.status-count')
.textContent
.replace(',', ''),
10,
);
} catch (e) {
// unable to find order count (it's likely not the old layout)
}
try {
// new layout
unread += parseInt(
contains('#app-root a', 'Awaiting Shipment')[0]
.nextSibling
.children[0]
.textContent
.replace(',', ''),
10,
);
unread += parseInt(
contains('#app-root a', 'On Hold')[0]
.nextSibling
.children[0]
.textContent
.replace(',', ''),
10,
);
} catch (e) {
// unable to find order count (it's likely not the new layout)
}
Franz.setBadge(parseInt(unread, 10));
};
Franz.loop(getMessages);
};