-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscripta.js
61 lines (55 loc) · 2.79 KB
/
scripta.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
55
56
57
58
59
60
61
$(document).ready(function() {
populateFeedList()
});
// Populate body element with list of RSS feeds
function populateFeedList() {
$.each(rss2json,function(listIndex, listElement){
console.log('Looping through RSS Category:', listIndex)
newfeed = `<p>New category, ${listIndex.replaceAll('_','/')}. `
$.each(listElement, function (index, value) {
console.log('Looping through RSS URL:', value['feed']['title'])
$.each(value['entries'], function(index, data) {
console.log('Looping through title:', data['title'])
newfeed = newfeed + parseFeed(data, value['feed']['title'])
});
});
if (newfeed.split('.').length > 3) { // Add category if there is atleast one article
$('body').append(newfeed)
}
});
}
// Parse the JSON dump and return html
function parseFeed(data, value) { // https://stackoverflow.com/a/7067582/3016570
let newsPublisher = value
let newfeed = ''
item = {
title: data['title'],
link: data['link'],
description: data['summary'],
pubDate: data['published_js'],
//author: data['author']
}
//console.log('Parsed feed of:', item['title'])
if (itemValid(item)) {
console.log(newsPublisher)
if (newsPublisher != "Today I Learned (TIL)") {
// Check if the string "Summary:" is present in item['description']
if (item['description'].includes("Summary:")) {
newfeed += `Next article, ${item['title']}. ${item['description'].slice(0,config['maxDescLen'])}. `;
} else {
newfeed += `Next article, ${item['title']}. Summary is, ${item['description'].slice(0,config['maxDescLen'])}. `;
}
} else {
newfeed += `Next article, ${item['title']}. `;
}
}
return newfeed
};
function itemValid(item) { // Checks to see if item should be included in feed
timediff = new Date($.now()).getTime() - new Date(item['pubDate']).getTime(); // Get timediff between now and when this article was published
termExcluded = config['excludeTerms'].some(function(v) { return item['title'].indexOf(v) >= 0; }) || config['excludeTerms'].some(function(v) { return item['title'].indexOf(v[0].toUpperCase() + v.slice(1)) >= 0; }) // True if title contains any of the terms (as is & capitalized) to exclude - https://stackoverflow.com/a/5582621/3016570
termIncluded = config['includeTerms'].some(function(v) { return item['title'].indexOf(v) >= 0; }) // True if title contains any of the terms to include
//boolval = !(timediff > config['maxPublishTime']*60*1000 || (termExcluded && !termIncluded)) // Check all conditions
boolval = !((termExcluded && !termIncluded)) // Check all conditions
return boolval
}