-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
105 lines (79 loc) · 2.76 KB
/
main.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
(function(global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.OSFeedbox = global.OSFeedbox || {})));
}(this, (function(exports) { 'use strict';
const mod = {
// COMMAND
async goLoad (input, _debug) {
const _window = _debug || window;
class OSFeedboxInstance {
limit = Infinity;
constructor (params) {
Object.assign(this, params, mod);
}
}
const instance = new OSFeedboxInstance(input);
return instance._populate(input.items || instance._items(await mod._fetch(input.feed)));
},
async _fetch (input, _debug) {
const _window = _debug || window;
return await (await _window.fetch(mod._corsProxy() + input)).text();
},
_corsProxy () {
return 'https://cors.rosano.ca/';
},
_items (input) {
const output = [];
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(input, 'text/xml');
const xPathResult = xmlDoc.evaluate('/rss/channel/item', xmlDoc, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
let node = xPathResult.iterateNext();
for (let i = 0; (i < this.limit) && node; i++) {
output.push({
title: node.getElementsByTagName('title')[0].textContent,
link: node.getElementsByTagName('link')[0].textContent,
description: node.getElementsByTagName('description')[0].textContent,
pubDate: new Date(node.getElementsByTagName('pubDate')[0].textContent),
});
node = xPathResult.iterateNext();
}
return output;
},
_populate (input) {
this.parent.innerHTML = `<div class="OSFeedbox OLSKDecorModule">
<h2>
<span class="OSFeedboxHeading">Latest updates</span>
<sup><a class="OSFeedboxButton" href="${ this.feed }" title="Feed">(feed)</a></sup>
</h2>
<div class="OSFeedboxList">
${ input.map( (e, i) => `
<a class="OSFeedboxListItem" href="${ e.link }" target="_blank">${ e.title }</a>`
+ (!e.description || this.hideBlurb ? '' : `<p class="OSFeedboxListItemBlurb">${ e.description }</p>`)
+ (i === input.length - 1 ? '' : `<hr/>`)
).join('') }
</div></div>`;
},
// MESSAGE
async DOMContentLoaded () {
const _mod = (typeof process !== 'undefined' && process.env.npm_lifecycle_script === 'olsk-spec') ? this : mod;
if (typeof window === 'object' && window.origin === null) {
return;
}
// _mod._populate();
},
// LIFECYCLE
lifeDidLoad (debug) {
// (debug || window).document.addEventListener('DOMContentLoaded', mod.DOMContentLoaded);
},
};
Object.assign(exports, mod, {
load: mod.goLoad,
});
if (typeof window === 'object') {
// mod.lifeDidLoad();
}
Object.defineProperty(exports, '__esModule', {
value: true
});
})));