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/reddit/webview.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'recipes/reddit') diff --git a/recipes/reddit/webview.js b/recipes/reddit/webview.js index 5095ba1..8d165aa 100644 --- a/recipes/reddit/webview.js +++ b/recipes/reddit/webview.js @@ -12,16 +12,21 @@ module.exports = Ferdi => { let count = 0; if (elements[0]) { - count = Ferdi.safeParseInt(elements[0].innerHTML); + count = Ferdi.safeParseInt(elements[0].textContent); } Ferdi.setBadge(count); }; if (document.querySelectorAll('.promotedlink').length > 0) { - document.querySelectorAll('.promotedlink').forEach(sponsoredLink => { - sponsoredLink.parentElement.parentElement.style.display = 'none'; - }); + for (const sponsoredLink of document.querySelectorAll('.promotedlink')) { + if ( + sponsoredLink.parentElement && + sponsoredLink.parentElement.parentElement + ) { + sponsoredLink.parentElement.parentElement.style.display = 'none'; + } + } } Ferdi.loop(getMessages); @@ -41,8 +46,10 @@ module.exports = Ferdi => { const btn = document.querySelector('[role=menu] button button'); const checked = btn && btn.getAttribute('aria-checked') === 'true'; - if ((checked && !isEnabled) || (!checked && isEnabled)) { - // Click the button to switch between modes + if ( + ((checked && !isEnabled) || (!checked && isEnabled)) && // Click the button to switch between modes + btn + ) { btn.click(); } }, 50); -- cgit v1.2.3-70-g09d2