2024-01-02 17:21:44 -05:00
|
|
|
let area = document.querySelector('#area-main');
|
|
|
|
let entries = [];
|
|
|
|
let users = {};
|
2024-09-13 19:02:19 -04:00
|
|
|
let fetchData;
|
2024-08-04 18:04:17 -04:00
|
|
|
let sum = 0;
|
2024-08-16 23:24:05 -04:00
|
|
|
let doThings = false;
|
|
|
|
let i = 0;
|
2024-01-02 17:21:44 -05:00
|
|
|
|
2024-08-04 18:04:17 -04:00
|
|
|
async function genTree(treeId) {
|
|
|
|
let entry = treeId;
|
|
|
|
|
|
|
|
while (true) {
|
2024-08-02 03:42:44 -04:00
|
|
|
let entryDat = fetchData[entry];
|
2024-08-16 23:24:05 -04:00
|
|
|
|
2024-08-04 18:04:17 -04:00
|
|
|
entries.push(entry);
|
|
|
|
|
2024-08-16 23:24:05 -04:00
|
|
|
if (!entryDat) break;
|
2024-08-04 18:04:17 -04:00
|
|
|
|
2024-08-16 23:24:05 -04:00
|
|
|
let us = users[entryDat.username];
|
2024-08-04 18:13:24 -04:00
|
|
|
|
2024-09-13 19:02:19 -04:00
|
|
|
let s = 1 / ((new Date() - new Date(entryDat.datetime_created.$date)) + 1000 * 60 * 60);
|
2024-08-04 18:04:17 -04:00
|
|
|
sum += s;
|
|
|
|
users[entryDat.username] = (us ? us : 0) + s;
|
|
|
|
entry = entryDat.parent_id;
|
2024-01-02 17:21:44 -05:00
|
|
|
}
|
2024-09-13 19:02:19 -04:00
|
|
|
|
2024-01-02 17:21:44 -05:00
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function main() {
|
2024-09-15 02:07:38 -04:00
|
|
|
fetchData = await fetch(`https://scratch.mit.edu/projects/328479256/remixtree/bare/`).then(x => x.json());
|
2024-08-02 21:00:24 -04:00
|
|
|
|
2024-08-22 00:10:58 -04:00
|
|
|
let latestData = await fetch(`https://hf.zenoverse.net/api/`).then(x => x.json());
|
2024-08-02 21:00:24 -04:00
|
|
|
|
|
|
|
let lid = latestData[0].id;
|
2024-09-13 19:02:19 -04:00
|
|
|
let i = 0;
|
|
|
|
while (!fetchData[lid]) {
|
|
|
|
i++;
|
|
|
|
lid = latestData[i].id;
|
|
|
|
}
|
|
|
|
|
2024-08-02 21:00:24 -04:00
|
|
|
while (fetchData[lid].children.length > 0) {
|
|
|
|
let ch = fetchData[lid].children;
|
|
|
|
let ch2 = ch.filter(x => fetchData[x].children.length > 0);
|
|
|
|
lid = ch2[0] || ch[0];
|
|
|
|
}
|
|
|
|
await genTree(lid); // latest project
|
2024-08-16 23:24:05 -04:00
|
|
|
for (let gap of treeGaps) {
|
|
|
|
await genTree(gap); // tree bug here, unavoidable without jank
|
|
|
|
}
|
|
|
|
|
|
|
|
let params = new URL(window.location).searchParams;
|
|
|
|
|
2024-09-13 19:02:19 -04:00
|
|
|
entries.forEach((x, i) => x && fetchData[x] ? (fetchData[x].id = entries.length - i - 2) : null);
|
2024-08-16 23:24:05 -04:00
|
|
|
|
|
|
|
let start = params.get('start') * 1;
|
|
|
|
let end = params.get('end') * 1;
|
|
|
|
|
2024-09-13 19:02:19 -04:00
|
|
|
end = Math.min(end,entries.length-2);
|
|
|
|
|
2024-08-16 23:24:05 -04:00
|
|
|
if (start && end) {
|
2024-09-13 19:02:19 -04:00
|
|
|
entries = entries.splice(entries.length - end - 2, end - start + 1);
|
2024-08-16 23:24:05 -04:00
|
|
|
}
|
|
|
|
|
2024-01-03 09:43:38 -05:00
|
|
|
doThings = true;
|
2024-08-02 03:42:44 -04:00
|
|
|
document.querySelector('.contributors').innerHTML = Object.keys(users)
|
|
|
|
.sort((x, y) => users[y] - users[x])
|
2024-08-04 18:04:17 -04:00
|
|
|
.map(x => `<a href='https://scratch.mit.edu/users/${x}'>${x}</a> <sub>${Math.trunc(users[x] / sum * 100000) / 1000}%</sub>`)
|
2024-08-02 03:42:44 -04:00
|
|
|
.join(', '); // Doesn't need to be sanitized (hopefully)
|
2024-01-02 17:21:44 -05:00
|
|
|
|
2024-09-13 19:02:19 -04:00
|
|
|
let newEras = importedEras.split('\n').map(x => x.split('-')).map(x => ({ start: x[0] * 1, end: x[1] * 1, name: x[2].slice(1) }));
|
2024-01-02 17:21:44 -05:00
|
|
|
|
2024-08-16 23:24:05 -04:00
|
|
|
eras = [...eras, ...newEras];
|
|
|
|
|
|
|
|
document.querySelector('.eras').innerHTML = eras.map(x => `<a href='?start=${x.start}&end=${x.end}'>${x.name}`).join(', ');
|
|
|
|
setInterval(function () {
|
|
|
|
if (doThings && (window.innerHeight + window.scrollY) >= document.body.scrollHeight - 25)
|
|
|
|
scroller();
|
|
|
|
}, 500)
|
|
|
|
|
|
|
|
}
|
2024-01-02 17:21:44 -05:00
|
|
|
|
|
|
|
function sanitize(content) {
|
|
|
|
const decoder = document.createElement('div');
|
|
|
|
decoder.textContent = content;
|
|
|
|
return decoder.innerHTML;
|
|
|
|
}
|
|
|
|
|
2024-08-16 23:24:05 -04:00
|
|
|
function scroller() {
|
|
|
|
let h = '';
|
|
|
|
for (let j = 0; j < 35; j++) {
|
|
|
|
let entry = entries[i];
|
|
|
|
if (!entry || !(entry in fetchData)) break;
|
|
|
|
h += `<div class='proj'><a href="https://scratch.mit.edu/projects/${entry}"><img src='https://uploads.scratch.mit.edu/get_image/project/${entry}_1920x1080.png'>${sanitize(fetchData[entry].title)}</a> <sub>#${fetchData[entry].id} by ${fetchData[entry].username}</sub></div>`;
|
|
|
|
i++;
|
2024-01-02 17:21:44 -05:00
|
|
|
}
|
2024-08-16 23:24:05 -04:00
|
|
|
area.innerHTML += h;
|
|
|
|
}
|
|
|
|
|
|
|
|
main();
|
|
|
|
|