From 562ffde69b858b9584994295fa1b7df394ddc528 Mon Sep 17 00:00:00 2001 From: Francisco Marques Date: Sat, 10 Oct 2020 03:39:48 +0100 Subject: Fixed Slite querySelector and code style improvements (#324) --- recipes/slite/webview.js | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'recipes') diff --git a/recipes/slite/webview.js b/recipes/slite/webview.js index 6e0fa46..1d6957a 100644 --- a/recipes/slite/webview.js +++ b/recipes/slite/webview.js @@ -1,22 +1,16 @@ "use strict"; -var _path = _interopRequireDefault(require("path")); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +let getInnerInt = selector => { + const element = document.querySelector(selector); + return element && parseInt(element.innerText); +} module.exports = Ferdi => { const getMessages = function getMessages() { - let direct = 0; - - const notificationButton = document.querySelector( - "#app button[data-test-id='notificationsCount'" + let direct = ( + getInnerInt("#app button[data-test-id='notificationsCount']") || 0 ); - if (notificationButton) { - const notificationCount = parseInt(notificationButton.innerText); - direct = isNaN(notificationCount) ? 0 : notificationCount; - } - Ferdi.setBadge(direct); }; -- cgit v1.2.3-70-g09d2