RSSFinder/rssfinder/finder.js
Juraj Oravec f242973384
Correctly show the "No rSS feed was found" message
Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
2022-03-12 02:20:11 +01:00

51 lines
1.3 KiB
JavaScript

(function() {
var availableLinks = [];
var links = document.getElementsByTagName('link');
var siteTitle = 'No title was found';
if (document.getElementsByTagName('title').lenght > 0) {
siteTitle = document.getElementsByTagName('title')[0].innerHTML
}
for (link of links) {
if (link.getAttribute('rel') == 'alternate' && link.getAttribute('type') == 'application/rss+xml') {
var linkTitle;
var linkUrl;
if (link.hasAttribute('title')) {
linkTitle = link.getAttribute('title');
} else {
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');
}
availableLinks.push({
title: linkTitle,
url: linkUrl
});
}
}
if (availableLinks.length == 0) {
availableLinks.push({
title: 'No RSS feed was found',
url: 'No URL is provided'
});
}
var out = {
links: availableLinks
};
return out;
})()