From 26051543fdbe01470b6f62f10df525818a6d31c5 Mon Sep 17 00:00:00 2001 From: Juraj Oravec Date: Mon, 20 Jun 2022 00:08:09 +0200 Subject: [PATCH] JS: Skip link when "href" attribute is not present Signed-off-by: Juraj Oravec --- rssfinder/finder.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/rssfinder/finder.js b/rssfinder/finder.js index d4bd2f0..4eda248 100644 --- a/rssfinder/finder.js +++ b/rssfinder/finder.js @@ -25,18 +25,20 @@ for (link of links) { linkTitle = siteTitle; } - if (link.getAttribute('href').startsWith('/')) { - linkUrl = window.location.protocol + '//' + window.location.hostname + link.getAttribute('href'); - } else if (!link.getAttribute('href').includes('/')) { - linkUrl = window.location.protocol + '//' + window.location.hostname + '/' + link.getAttribute('href'); - } else { - linkUrl = link.getAttribute('href'); - } + if (link.hasAttribute('href') == true) { + if (link.getAttribute('href').startsWith('/')) { + linkUrl = window.location.protocol + '//' + window.location.hostname + link.getAttribute('href'); + } else if (!link.getAttribute('href').includes('/')) { + linkUrl = window.location.protocol + '//' + window.location.hostname + '/' + link.getAttribute('href'); + } else { + linkUrl = link.getAttribute('href'); + } - availableLinks.push({ - title: linkTitle, - url: linkUrl - }); + availableLinks.push({ + title: linkTitle, + url: linkUrl + }); + } } }