From d3841b766f9d37d557646003899f67525c5f755f Mon Sep 17 00:00:00 2001 From: Markus Hatvan Date: Tue, 5 Oct 2021 17:04:09 +0200 Subject: chore: add eslint-plugin-unicorn (#733) --- recipes/hey/webview.js | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'recipes/hey/webview.js') diff --git a/recipes/hey/webview.js b/recipes/hey/webview.js index 686e811..67e87d4 100644 --- a/recipes/hey/webview.js +++ b/recipes/hey/webview.js @@ -1,23 +1,29 @@ -module.exports = (Ferdi) => { +module.exports = Ferdi => { const getMessages = () => { - if (document.location.href == "https://app.hey.com/") { + if (document.location.href == 'https://app.hey.com/') { let screener = 0; let unread = 0; - if (document.getElementsByClassName('btn--icon-screener').length > 0) { - let text = document.getElementsByClassName('btn--icon-screener')[0].innerText; - - screener = Ferdi.safeParseInt(/[0-9]+/.exec(text)[0]); + if (document.querySelectorAll('.btn--icon-screener').length > 0) { + let text = document.querySelectorAll('.btn--icon-screener')[0] + .textContent; + if (text) { + const parsedText = Ferdi.safeParseInt(/\d+/.exec(text)); + screener = parsedText[0]; + } } - let postings = document.getElementsByClassName('posting'); + let postings = document.querySelectorAll('.posting'); if (postings.length > 0) { - Array.from(postings).forEach(p => { - if (p.nodeName == "ARTICLE" && p.getAttribute("data-seen") !== "true") { + for (const p of postings) { + if ( + p.nodeName == 'ARTICLE' && + p.getAttribute('data-seen') !== 'true' + ) { unread++; } - }); + } } Ferdi.setBadge(unread, screener); @@ -25,4 +31,4 @@ module.exports = (Ferdi) => { }; Ferdi.loop(getMessages); -} +}; -- cgit v1.2.3-70-g09d2