-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathfeed_shipflippdev.js
More file actions
90 lines (81 loc) · 3.35 KB
/
feed_shipflippdev.js
File metadata and controls
90 lines (81 loc) · 3.35 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
class feedShipFlippDev{
constructor() {
this.cardSpanName = 'cardFeedShipFlippDev';
this.cardTitle = 'Shipment Updates';//'Latest Shipment Updates';
this.cardCollapseBodyClassCode = cardCollapseEnabled() ? "collapse" : "";
this.cardCollapseBodyIdCode = this.cardSpanName+'Body';
this.cardCollapseHeadCode = genCardHeadCode(this.cardTitle, this.cardSpanName);
this.feed = null;
this.maxUpdates = 3;
this.cardCode = `
<div class="card mb-3">
${this.cardCollapseHeadCode}
<div class="card-body ${this.cardCollapseBodyClassCode}" id="${this.cardCollapseBodyIdCode}">
<!--<h5>Newest Updates</h5>-->
<div id="feedShipFlippDev_body" class="overflow-auto">
</div>
</div>
</div>
`;
}
feedAppend = (x) => { this.feed.innerHTML = this.feed.innerHTML.trim() + (this.feed.innerHTML.trim() == '' ? '' : '<br />'+(false ? '~'.repeat(10) : '')+'<br />' ) + x; }
async renderCard(){
var infoGeneralCard = document.getElementById(this.cardSpanName);
infoGeneralCard.innerHTML = this.cardCode;
this.feed = document.getElementById('feedShipFlippDev_body');
showHideCard(this.cardSpanName+'BodyCollapse', '#'+this.cardSpanName+'Body');
let items = await getRSSFeedProxy('https://ship.flipp.dev/rss');
items = items.items;
var cntrMax = this.maxUpdates;
var cntr = 0;
items.forEach(x => {
if(cntr < cntrMax){
let date = x.pubDate.replace(' ','T')+ '-00:00';
//var DateTime = luxon.DateTime;
//console.log('x.pubDate',x.pubDate.replace(' ','T')+ '-00:00');
//console.log(DateTime.fromISO(x.pubDate.replace(' ','T')+ '-00:00'));
date = new Date(date);
date = date.toLocaleDateString("en-US")
let content = x.content;
content = content.trim();
content = this.toUnicode(content).replaceAll('\\uD83C\\uDDEC\\uD83C\\uDDE7', '<br /><b>UK:</b> ')
.replaceAll('\\uD83C\\uDDEA\\uD83C\\uDDFA', '<br /><b>EU:</b> ')
.replaceAll('\\uD83C\\uDDF7\\uD83C\\uDDFA', '<br /><b>RU:</b> ')
.replaceAll('\\uD83C\\uDDFA\\uD83C\\uDDF8', '<br /><b>USA:</b> ');
content = this.toNormalString(content);
content = content.replaceAll('\n', '')
.replaceAll('\r', '')
.replaceAll('<br>', '')
.replaceAll('<strong>- </strong>', '');
while(content.includes('<strong> ')) content = content.replaceAll('<strong> ', '<strong>');
while(content.includes(' </strong>')) content = content.replaceAll(' </strong>', '</strong>');
content = content.replaceAll('</strong>', '</strong> ');
while(content.includes(' ')) content = content.replaceAll(' ', ' ');
if (content.indexOf('<br>') == 0) content = content.slice(4);
if (content.indexOf('<br />') == 0) content = content.slice(6);
content = `<center><h5>${date}</h5></center>${content}`;
while(content.includes('<br /><br />')) content = content.replaceAll('<br /><br />', '<br />');
this.feedAppend(content);
}
cntr++;
});
updateMasonryLayout();
}
toNormalString(str) {
while(str.includes('\\u')) str = this.unicodeToChar(str);
return str
}
unicodeToChar(x) {
return x.replace(/\\u[\dA-F]{4}/gi,
function (match) {
return String.fromCharCode(parseInt(match.replace(/\\u/g, ''), 16));
});
}
toUnicode(str) {
return str.split('').map(function (value, index, array) {
var temp = value.charCodeAt(0).toString(16).toUpperCase();
if (temp.length > 2) return '\\u' + pad(temp,4);
return value;
}).join('');
}
}