first commit lop
This commit is contained in:
commit
1bb22a2808
5 changed files with 264 additions and 0 deletions
96
js/app.js
Normal file
96
js/app.js
Normal file
|
@ -0,0 +1,96 @@
|
|||
let area = document.querySelector('#area-main');
|
||||
let entries = [];
|
||||
let users = {};
|
||||
let fetchData;
|
||||
let sum = 0;
|
||||
let doThings = false;
|
||||
let i = 0;
|
||||
|
||||
async function genTree(treeId) {
|
||||
let entry = treeId;
|
||||
|
||||
while (true) {
|
||||
let entryDat = fetchData[entry];
|
||||
|
||||
entries.push(entry);
|
||||
|
||||
if (!entryDat) break;
|
||||
|
||||
let us = users[entryDat.username];
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
async function main() {
|
||||
|
||||
let users = document.querySelector('#users').value.split('\n');
|
||||
|
||||
let url = new URL(window.location);
|
||||
url.search = '?users=' + users.join('&users=');
|
||||
history.pushState(null, '', url);
|
||||
|
||||
entries = [];
|
||||
|
||||
for (let user of users) {
|
||||
let extraFetch = await fetch(`https://hf.zenoverse.net/user/${user}`, {
|
||||
|
||||
});
|
||||
extraFetch = await extraFetch.json();
|
||||
extraFetch.forEach(x => x.username = user);
|
||||
entries = [...entries, ...extraFetch];
|
||||
}
|
||||
entries = entries.sort((a, b) => b.id - a.id);
|
||||
|
||||
let params = new URL(window.location).searchParams;
|
||||
|
||||
let start = params.get('start') * 1;
|
||||
let end = params.get('end') * 1;
|
||||
|
||||
end = Math.min(end, entries.length - 2);
|
||||
|
||||
if (start && end) {
|
||||
entries = entries.splice(entries.length - end - 2, end - start + 1);
|
||||
}
|
||||
|
||||
doThings = true;
|
||||
|
||||
|
||||
setInterval(function () {
|
||||
if (doThings && (window.innerHeight + window.scrollY) >= document.body.scrollHeight - 25)
|
||||
scroller();
|
||||
}, 500);
|
||||
}
|
||||
|
||||
function sanitize(content) {
|
||||
const decoder = document.createElement('div');
|
||||
decoder.textContent = content;
|
||||
return decoder.innerHTML;
|
||||
}
|
||||
|
||||
function scroller() {
|
||||
let h = '';
|
||||
for (let j = 0; j < 35; j++) {
|
||||
let entry = entries[i];
|
||||
if (!entry) continue;
|
||||
h += `<div class='proj'><a href="https://scratch.mit.edu/projects/${entry.id}"><img src='https://uploads.scratch.mit.edu/get_image/project/${entry.id}_1920x1080.png'>${entry.title}</a> <sub>by ${entry.username}</sub></div>`;
|
||||
i++;
|
||||
}
|
||||
area.innerHTML += h;
|
||||
}
|
||||
|
||||
let sub = document.querySelector('#users');
|
||||
|
||||
let params = new URLSearchParams(window.location.search).getAll('users');
|
||||
|
||||
let val = params.join('\n') || sub.value;
|
||||
|
||||
sub.textContent = sub.value = val;
|
||||
|
||||
main();
|
||||
document.querySelector('#submit').onclick = main;
|
Loading…
Add table
Add a link
Reference in a new issue