aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/magic-level/webview.js
diff options
context:
space:
mode:
authorLibravatar Adam Everson Souza Araújo <adameversons@gmail.com>2022-08-27 19:54:45 -0300
committerLibravatar GitHub <noreply@github.com>2022-08-27 22:54:45 +0000
commitabbf09aa1bdd0f322052f0e318b28c073c17bcc5 (patch)
tree886a15157795c6967d97f74a36acd2cc6b07cdcf /recipes/magic-level/webview.js
parentdocs: add hafiz-muhammad as a contributor for code (#161) [skip ci] (diff)
downloadferdium-recipes-abbf09aa1bdd0f322052f0e318b28c073c17bcc5.tar.gz
ferdium-recipes-abbf09aa1bdd0f322052f0e318b28c073c17bcc5.tar.zst
ferdium-recipes-abbf09aa1bdd0f322052f0e318b28c073c17bcc5.zip
Add Magic Level recipe (#158)
Diffstat (limited to 'recipes/magic-level/webview.js')
-rw-r--r--recipes/magic-level/webview.js42
1 files changed, 42 insertions, 0 deletions
diff --git a/recipes/magic-level/webview.js b/recipes/magic-level/webview.js
new file mode 100644
index 0000000..d39c90d
--- /dev/null
+++ b/recipes/magic-level/webview.js
@@ -0,0 +1,42 @@
1const _path = _interopRequireDefault(require('path'));
2
3function _interopRequireDefault(obj) {
4 return obj && obj.__esModule ? obj : { default: obj };
5}
6
7module.exports = Ferdium => {
8
9 const getMessages = () => {
10 let countImportant = 0;
11 let countNonImportant = 0;
12 const inboxLinks = document.querySelectorAll('.J-Ke.n0');
13 if (inboxLinks.length > 0) {
14 let parentNode = inboxLinks[0].parentNode;
15 if (parentNode) {
16 let parentNodeOfParentNode = parentNode.parentNode;
17 if (parentNodeOfParentNode) {
18 const unreadCounts = parentNodeOfParentNode.querySelectorAll('.bsU');
19 if (unreadCounts.length > 0) {
20 let unreadCount = unreadCounts[0].textContent;
21 if (unreadCount.includes(':')) {
22 let counts = unreadCount
23 .split(':')
24 .map(s => Ferdium.safeParseInt(s.replace(/[^\p{N}]/gu, '')));
25 countImportant = counts[0];
26 countNonImportant = counts[1] - counts[0];
27 } else {
28 countImportant = Ferdium.safeParseInt(
29 unreadCount.replace(/[^\p{N}]/gu, ''),
30 );
31 }
32 }
33 }
34 }
35 }
36 Ferdium.setBadge(countImportant, countNonImportant);
37 };
38
39 Ferdium.loop(getMessages);
40
41 Ferdium.injectCSS(_path.default.join(__dirname, 'service.css'));
42};