-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
55 lines (41 loc) · 1.5 KB
/
background.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
$(document).ready(function() {
console.log('Loaded')
var host = window.location.hostname;
var WPM = 200;
console.log(host)
setTimeout(function() {
if($('article') && ['www.newyorker.com', 'www.theatlantic.com', 'www.washingtonpost.com', 'www.nytimes.com'].includes(host)) {
article = $('article');
articleText = article.text();
var words = articleText.split(' ').length;
var estimatedReadTime = Math.round(words/WPM);
var read_time_div = "<div class='read-div'><span class='readTime'>Estimated Read Time: " + estimatedReadTime + " Minutes</span></div>"
switch(host) {
case "www.newyorker.com":
console.log('The New Yorker');
article.prepend(read_time_div)
break;
case "www.theatlantic.com":
console.log('The Atlantic');
article.find('.article-cover-content-wrapper').prepend(read_time_div)
break;
case "www.washingtonpost.com":
console.log('The Washington Post');
article.prepend(read_time_div)
break;
case "www.nytimes.com":
console.log('The New York Times');
article.find('header').prepend(read_time_div)
break;
}
}
else if(host == "www.economist.com" && $('.blog-post')) {
var article = $('.blog-post');
var articleText = article.text();
var words = articleText.split(' ').length;
var estimatedReadTime = Math.round(words/WPM);
var read_time_div = "<div class='read-div'><span class='readTime'>Estimated Read Time: " + estimatedReadTime + " Minutes</span></div>"
article.prepend(read_time_div)
}
}, 800)
})