-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscript.js
71 lines (66 loc) · 3.8 KB
/
script.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
62
63
64
65
66
67
68
69
70
71
$(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)
//$('body').append(`<div class="cardContainer"><p class="rssCard" id="title_${listIndex}">${listIndex}</p><div class="rssCard" id="card_${listIndex}"><ul class="rssList">content_${listIndex}</ul></div></div>`)
var newfeed = ''
$.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 != '') { // Create card if feed is not empty
//let columnNum = `rssColumn_${$('.cardContainer').length % 3}` // Calculate number of existing elements of class cardContainer. Decide which column to place in.
// appendColumn(listIndex, newfeed)
// append to the body
$('body').append(`<div class="cardContainer"><h1 class="rssCard" id="title_${listIndex}">${listIndex.replaceAll('_','/')}</h1>${newfeed}</div>`)
}
});
}
// Function that appends html content to a div of id rssColumn_x
function appendColumn(listIndex, newfeed) {
$(`#${findMinHeight().colId}`).append(`<div class="cardContainer"><h1 class="rssCard" id="title_${listIndex}">${listIndex.replaceAll('_','/')}</h1><div class="rssCard" id="card_${listIndex}"><ul class="rssList">content_${listIndex}</ul></div></div>`)
$(`#card_${listIndex} > ul.rssList`).html(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)) {
newfeed += `<div class='itemTitle'><a href='${item['link']}' target='_blank'>${item['title']}</a></div><div class='itemPublisher'>${newsPublisher}</div><div class='itemContent'>${item['description'].slice(0,config['maxDescLen'])}</div><hr>`;
}
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
}
function findMinHeight() {
var minHeight = $('#rssColumn_0').height();
var colId = 'rssColumn_0';
$('.rssColumn').each(function() {
if ($(this).height() < minHeight) {
console.log($(this).attr('id'), $(this).height())
minHeight = $(this).height();
colId = $(this).attr('id');
}
});
return {minHeight, colId};
}