From 6e60ef83ac19946d3a11cee5e7864689a7a4ef54 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Mon, 20 Jan 2020 11:05:06 +0100 Subject: [PATCH] Apply review comments --- xExtension-ReadingTime/static/readingtime.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/xExtension-ReadingTime/static/readingtime.js b/xExtension-ReadingTime/static/readingtime.js index 6328d70..5adfad3 100644 --- a/xExtension-ReadingTime/static/readingtime.js +++ b/xExtension-ReadingTime/static/readingtime.js @@ -23,7 +23,6 @@ reading_time.words_count = reading_time.flux_words_count(flux_list[i]); // count the words reading_time.reading_time = reading_time.calc_read_time(reading_time.words_count, 300); // change this number (in words) to your prefered reading speed - 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) @@ -42,20 +41,14 @@ flux_words_count: function flux_words_count(flux) { - 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 + reading_time.textContent = flux.querySelector('.flux_content .content').textContent; // get textContent, from the article itself (not the header, not the bottom line). // 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 reading_time.textContent = reading_time.textContent.replace(/[ ]{2,}/gi," ");//2 or more space to 1 reading_time.textContent = reading_time.textContent.replace(/\n /,"\n"); // exclude newline with a start spacing - /// This part ↓↓↓ is not working if the content of the title bar is changed by the user… need to do that in proper, more robust way - // flux.childNodes[0].childNodes[2].textContent.split(' ').length - // excluding website length - // flux.childNodes[0].childNodes[4].textContent.split(' ').length - // excluding date length - // flux.childNodes[0].childNodes[6].textContent.split(' ').length; // excluding title length - // Not 100% acurate as it doesn't check if there are shown at the bottom of the article - return reading_time.textContent.split(' ').length - //raw number of words - 15 ; // Temporary fix for excluding website/date/title text. It assumes than the title (+ author) label is rougly 15 words long. + return reading_time.textContent.split(' ').length; }, calc_read_time : function calc_read_time(wd_count, speed) {