frictionless-browser/js/app.js

52 lines
1.3 KiB
JavaScript
Raw Normal View History

2024-01-02 17:21:44 -05:00
let area = document.querySelector('#area-main');
let entries = [];
let users = {};
let fetchData;
async function genTree(treeId) {
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;
}
async function main() {
2024-01-02 19:21:11 -05:00
await genTree("946114669"); // latest project
2024-01-02 17:21:44 -05:00
await genTree("654605857"); // tree bug here, unavoidable without jank
console.log(entries)
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 ((window.innerHeight + window.scrollY) >= document.body.scrollHeight) {
let h = '';
for (let j = 0; j < 35; j++) {
let entry = entries[i];
2024-01-02 18:16:12 -05:00
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>`;
2024-01-02 17:21:44 -05:00
i++;
}
area.innerHTML += h;
}
},500);