From abbf09aa1bdd0f322052f0e318b28c073c17bcc5 Mon Sep 17 00:00:00 2001 From: Adam Everson Souza Araújo Date: Sat, 27 Aug 2022 19:54:45 -0300 Subject: Add Magic Level recipe (#158) --- recipes/magic-level/webview.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 recipes/magic-level/webview.js (limited to 'recipes/magic-level/webview.js') 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 @@ +const _path = _interopRequireDefault(require('path')); + +function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { default: obj }; +} + +module.exports = Ferdium => { + + const getMessages = () => { + let countImportant = 0; + let countNonImportant = 0; + const inboxLinks = document.querySelectorAll('.J-Ke.n0'); + if (inboxLinks.length > 0) { + let parentNode = inboxLinks[0].parentNode; + if (parentNode) { + let parentNodeOfParentNode = parentNode.parentNode; + if (parentNodeOfParentNode) { + const unreadCounts = parentNodeOfParentNode.querySelectorAll('.bsU'); + if (unreadCounts.length > 0) { + let unreadCount = unreadCounts[0].textContent; + if (unreadCount.includes(':')) { + let counts = unreadCount + .split(':') + .map(s => Ferdium.safeParseInt(s.replace(/[^\p{N}]/gu, ''))); + countImportant = counts[0]; + countNonImportant = counts[1] - counts[0]; + } else { + countImportant = Ferdium.safeParseInt( + unreadCount.replace(/[^\p{N}]/gu, ''), + ); + } + } + } + } + } + Ferdium.setBadge(countImportant, countNonImportant); + }; + + Ferdium.loop(getMessages); + + Ferdium.injectCSS(_path.default.join(__dirname, 'service.css')); +}; -- cgit v1.2.3-70-g09d2