From 64e85099ad8b6f9f5729cf349cd026b677d434c9 Mon Sep 17 00:00:00 2001 From: lapineige Date: Mon, 21 Oct 2019 22:41:41 +0200 Subject: [PATCH] Improve content detection --- xExtension-ReadingTime/static/readingtime.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xExtension-ReadingTime/static/readingtime.js b/xExtension-ReadingTime/static/readingtime.js index 2910a5b..6328d70 100644 --- a/xExtension-ReadingTime/static/readingtime.js +++ b/xExtension-ReadingTime/static/readingtime.js @@ -27,8 +27,8 @@ if (document.body.clientWidth <= 840) { // in mobile mode, the feed name is not visible (there is only the favicon) // add the reading time right before article's title // in that case, [Time] - [Title] format is used instead of a "|" (as it looks better and doesn't take much more space) - if ( document.querySelector("#" + reading_time.flux.id + " ul.horizontal-list li.item.title a").textContent.substring(0,(reading_time.reading_time + 'm - ').length) != reading_time.reading_time + 'm - ' ) { - document.querySelector("#" + reading_time.flux.id + " ul.horizontal-list li.item.title a").textContent = reading_time.reading_time + 'm - ' + document.querySelector("#" + reading_time.flux.id + " ul.horizontal-list li.item.title a").textContent; + if ( document.querySelector("#" + reading_time.flux.id + " ul.horizontal-list li.item.title a").textContent.substring(0,(reading_time.reading_time + 'm - ').length) != reading_time.reading_time + 'm - ' ) { + document.querySelector("#" + reading_time.flux.id + " ul.horizontal-list li.item.title a").textContent = reading_time.reading_time + 'm - ' + document.querySelector("#" + reading_time.flux.id + " ul.horizontal-list li.item.title a").textContent; } } else { // add the reading time just after the feed name @@ -42,7 +42,7 @@ flux_words_count: function flux_words_count(flux) { - reading_time.textContent = flux.childNodes[2].childNodes[1].textContent; // get textContent, from the article itself (not the header, not the bottom line). `childNodes[2].childNodes[1]` gives : `
` element + reading_time.textContent = flux.querySelector('.flux_content').textContent; // get textContent, from the article itself (not the header, not the bottom line). `childNodes[2].childNodes[1]` gives : `
` element // split the text to count the words correctly (source: http://www.mediacollege.com/internet/javascript/text/count-words.html) reading_time.textContent = reading_time.textContent.replace(/(^\s*)|(\s*$)/gi,"");//exclude start and end white-space