let area = document.querySelector('#area-main'); let entries = []; let users = {}; let fetchData; let sum = 0; async function genTree(treeId) { let entry = treeId; while (true) { let entryDat = fetchData[entry]; if (!entryDat) break; entries.push(entry); let us = users[entryDat.username]; console.log(entryDat); let s = 1 / ((new Date() - new Date(entryDat.datetime_created.$date)) + 1000*60*60); sum += s; users[entryDat.username] = (us ? us : 0) + s; entry = entryDat.parent_id; } return entry; } let doThings = false; async function main() { fetchData = await fetch(`https://scratch.mit.edu/projects/1052168454/remixtree/bare/`).then(x => x.json()); let latestData = await fetch("https://corsproxy.io/?https://api.scratch.mit.edu/studios/34493018/projects").then(x => x.json()); let lid = latestData[0].id; 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 await genTree("654605857"); // tree bug here, unavoidable without jank doThings = true; document.querySelector('.contributors').innerHTML = Object.keys(users) .sort((x, y) => users[y] - users[x]) .map(x => `${x} ${Math.trunc(users[x] / sum * 100000) / 1000}%`) .join(', '); // Doesn't need to be sanitized (hopefully) } 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 += `