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/gmail/webview.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'recipes/gmail/webview.js') diff --git a/recipes/gmail/webview.js b/recipes/gmail/webview.js index 23b1382..9b94d33 100644 --- a/recipes/gmail/webview.js +++ b/recipes/gmail/webview.js @@ -1,21 +1,33 @@ const _path = _interopRequireDefault(require('path')); -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { default: obj }; +} -module.exports = (Ferdi) => { +module.exports = Ferdi => { // if the user is on gmail's landing page, go to the login page. - if (location.hostname == 'www.google.com' && location.href.includes('gmail/about/')) { - location.href = 'https://accounts.google.com/AccountChooser?service=mail&continue=https://mail.google.com/mail/'; + if ( + location.hostname == 'www.google.com' && + location.href.includes('gmail/about/') + ) { + location.href = + 'https://accounts.google.com/AccountChooser?service=mail&continue=https://mail.google.com/mail/'; } const getMessages = () => { let count = 0; - const inboxLinks = document.getElementsByClassName('J-Ke n0'); + const inboxLinks = document.querySelectorAll('.J-Ke.n0'); if (inboxLinks.length > 0) { - const unreadCounts = inboxLinks[0].parentNode.parentNode.getElementsByClassName('bsU'); - if (unreadCounts.length > 0) { - count = Ferdi.safeParseInt(unreadCounts[0].innerHTML); + let parentNode = inboxLinks[0].parentNode; + if (parentNode) { + let parentNodeOfParentNode = parentNode.parentNode; + if (parentNodeOfParentNode) { + const unreadCounts = parentNodeOfParentNode.querySelectorAll('.bsU'); + if (unreadCounts.length > 0) { + count = Ferdi.safeParseInt(unreadCounts[0].textContent); + } + } } } -- cgit v1.2.3-70-g09d2