-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsupporters.js
54 lines (50 loc) · 1.84 KB
/
supporters.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
(function() {
const patrons = (async function() {
const uri = location.protocol === 'file:' ? 'https://www.sauce.llc/' : '/';
const [brags, supporters] = await Promise.all([
fetch(uri + 'brags.json').then(x => x.json()),
fetch(uri + 'supporters-v2.json').then(x => x.json())
]);
if (brags.length < supporters.length) {
console.warn("Need more brags!");
}
return {brags, supporters};
})();
function shuffle(data) {
for (let i = data.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
const temp = data[i];
data[i] = data[j];
data[j] = temp;
}
return data;
}
async function onDOMLoaded() {
const orders = [];
const {brags, supporters} = await patrons;
for (let i = 0; i < supporters.length; i++) {
orders.push(i);
}
const frag = document.createDocumentFragment();
for (const i of shuffle(orders)) {
const patron = document.createElement('patron');
const sup = supporters[i];
if (sup.url) {
const link = document.createElement('a');
link.href = sup.url;
link.target = '_blank';
link.textContent = sup.name;
patron.appendChild(link);
} else {
patron.textContent = sup.name;
}
const brag = document.createElement('div');
brag.classList.add('brag');
brag.textContent = sup.quip || brags[i % brags.length];
patron.appendChild(brag);
frag.appendChild(patron);
}
document.querySelector('section.supporters').appendChild(frag);
}
addEventListener('DOMContentLoaded', onDOMLoaded);
})();