frictionless-browser/js/app.js
2024-01-03 10:07:58 -05:00

54 lines
1.4 KiB
JavaScript

let area = document.querySelector('#area-main');
let entries = [];
let users = {};
let fetchData;
async function genTree(treeId) {
fetchData = fetchData || await fetch(`https://scratch.mit.edu/projects/${treeId}/remixtree/bare/`)
.then(x => x.json());
entries.push(treeId)
let entry = fetchData[treeId];
while (entry) {
entry = entry.parent_id;
entries.push(entry);
entry = fetchData[entry];
if (entry) users[entry.username] = true;
}
return entry;
}
let doThings = false;
async function main() {
await genTree("946321746"); // latest project
await genTree("654605857"); // tree bug here, unavoidable without jank
doThings = true;
document.querySelector('.contributors').textContent = Object.keys(users).join(', ');
}
main();
let i = 0;
function sanitize(content) {
const decoder = document.createElement('div');
decoder.textContent = content;
return decoder.innerHTML;
}
setInterval(function() {
if (doThings && (window.innerHeight + window.scrollY) >= document.body.scrollHeight - 25) {
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)} [${entries.length - i }]</a></div>`;
i++;
}
area.innerHTML += h;
}
},500);