-
Notifications
You must be signed in to change notification settings - Fork 0
/
rss.js
46 lines (42 loc) · 1.64 KB
/
rss.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
function wrapHtml(input, wrapper, extra = "") {
return "<" + wrapper + extra + ">" + input + "</" + wrapper + ">";
}
$.ajax({
type: 'GET',
url: "/feeds/rss.xml",
crossDomain: true,
dataType: 'XML',
success: function (xml) {
var x2js = new X2JS();
var rsse = x2js.xml2json(xml).rss;
var rss = rsse.channel;
var buffer = "";
//buffer = buffer + wrapHtml(rss.feed.title, "h1")
const items = rss.item;
// document.getElementById("ett").innerHTML = document.getElementById("ett").innerHTML + toString(rsse);
console.log(rss);
var count = 0;
for (const item of items) {
if (item.link == "" || item.link == null) {
var title = wrapHtml(item.title, "big", " title=\"" + item.guid + "\"");
} else {
var title = wrapHtml(wrapHtml(item.title, "big"), "a", " href=\"" + item.link + "\"");
}
var content = wrapHtml(item.description, "p");
var time = item.pubDate.substring(0, item.pubDate.length - 4);
var options = {
year: 'numeric', month: 'numeric', day: 'numeric',
hour: 'numeric', minute: 'numeric', second: 'numeric'
};
var formatter = new Intl.DateTimeFormat([], options);
var localtime = formatter.format(new Date(new Date(time) - (new Date().getTimezoneOffset() * 1000 * 60)));
var sub = wrapHtml(
"Published by " + item.author + " on " + localtime + " local time",
"small"
);
buffer = buffer + wrapHtml(wrapHtml(item.title + " [By " + item.author + " at " + localtime + "]", "summary") + wrapHtml(title + content + sub, "div"), "details", " title=\"" + item.guid + "\"")
count++;
}
document.getElementById("news2").innerHTML = buffer;
}
})