From 3bde6af55492efc16b25d10767bf574de98ac158 Mon Sep 17 00:00:00 2001 From: Marcus Noble Date: Tue, 15 Sep 2020 15:36:40 +0100 Subject: [PATCH] Add some extra error handling --- index.js | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index 8c57ff5..47f3f14 100644 --- a/index.js +++ b/index.js @@ -275,18 +275,24 @@ async function sendPage(website, tries = 0) { }); document.body.innerHTML = `

${document.getElementById('page-title').innerHTML}

` + document.getElementById('page-content').innerHTML; - } else if (isProbablyReaderable(document.cloneNode(true))) { - var documentClone = document.cloneNode(true); - var article = new Readability(documentClone).parse(); - var postedDate = document.querySelector('time[datetime]'); - var content = ` -
-

${article.title}

- ${article.byline ? `
${article.byline}
` : ""} - ${postedDate && postedDate.getAttribute('datetime') ? `
${postedDate.getAttribute('datetime')}
` : ""} -
- ` + article.content; - document.body.innerHTML = content; + } else { + try { + if (isProbablyReaderable(document.cloneNode(true))) { + var documentClone = document.cloneNode(true); + var article = new Readability(documentClone).parse(); + var postedDate = document.querySelector('time[datetime]'); + var content = ` +
+

${article.title}

+ ${article.byline ? `
${article.byline}
` : ""} + ${postedDate && postedDate.getAttribute('datetime') ? `
${postedDate.getAttribute('datetime')}
` : ""} +
+ ` + article.content; + document.body.innerHTML = content; + } + } catch (ex) { + console.log("Failed to detect if readable") + } } [...document.querySelectorAll('details')].forEach(details => details.setAttribute('open', ''));