Add some extra error handling

This commit is contained in:
Marcus Noble 2020-09-15 15:36:40 +01:00
parent eecc70d89b
commit 3bde6af554

View File

@ -275,18 +275,24 @@ async function sendPage(website, tries = 0) {
}); });
document.body.innerHTML = `<h1>${document.getElementById('page-title').innerHTML}</h1>` + document.getElementById('page-content').innerHTML; document.body.innerHTML = `<h1>${document.getElementById('page-title').innerHTML}</h1>` + document.getElementById('page-content').innerHTML;
} else if (isProbablyReaderable(document.cloneNode(true))) { } else {
var documentClone = document.cloneNode(true); try {
var article = new Readability(documentClone).parse(); if (isProbablyReaderable(document.cloneNode(true))) {
var postedDate = document.querySelector('time[datetime]'); var documentClone = document.cloneNode(true);
var content = ` var article = new Readability(documentClone).parse();
<header> var postedDate = document.querySelector('time[datetime]');
<h1>${article.title}</h1> var content = `
${article.byline ? `<blockquote>${article.byline}</blockquote>` : ""} <header>
${postedDate && postedDate.getAttribute('datetime') ? `<blockquote>${postedDate.getAttribute('datetime')}</blockquote>` : ""} <h1>${article.title}</h1>
</header> ${article.byline ? `<blockquote>${article.byline}</blockquote>` : ""}
` + article.content; ${postedDate && postedDate.getAttribute('datetime') ? `<blockquote>${postedDate.getAttribute('datetime')}</blockquote>` : ""}
document.body.innerHTML = content; </header>
` + article.content;
document.body.innerHTML = content;
}
} catch (ex) {
console.log("Failed to detect if readable")
}
} }
[...document.querySelectorAll('details')].forEach(details => details.setAttribute('open', '')); [...document.querySelectorAll('details')].forEach(details => details.setAttribute('open', ''));