From 51699134bc1eb23dcd3b8a558efcd8c540b13b9e Mon Sep 17 00:00:00 2001 From: onezDerv Date: Thu, 19 Sep 2024 02:49:56 -0400 Subject: [PATCH] add scripts --- download.js | 37 +++++++++++++++++++++++++++++++++++++ download_tree.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 download.js create mode 100644 download_tree.js diff --git a/download.js b/download.js new file mode 100644 index 0000000..3bd8535 --- /dev/null +++ b/download.js @@ -0,0 +1,37 @@ +var tree = [], gek, the; + +function downloadURI(uri, name) { + var link = document.createElement("a"); + link.download = name; + link.href = uri; + link.click(); +} + +async function downloadUser(user = "08draven") { + let i = 0; + for (let i = 0; ; i++) { + let fetchReq = await fetch(`https://api.scratch.mit.edu/users/${user}/projects/?limit=40&offset=${i * 40}`); + let fetchJson = await fetchReq.json(); + if (fetchJson.length < 1) break; + tree = [...tree, ...fetchJson]; + } + gek = 0; +} + +async function getPoject() { + if (the = tree[gek]) { + the = the.id; + e = await fetch("https://api.scratch.mit.edu/projects/" + the); + e = await e.json(); + if (e.project_token != undefined) { + downloadURI("https://projects.scratch.mit.edu/" + the + "?token=" + e.project_token, the) + } + gek++; + } else { + console.log("end"); + } +} + +await downloadUser(); + +setInterval(getPoject, 500) \ No newline at end of file diff --git a/download_tree.js b/download_tree.js new file mode 100644 index 0000000..d468bfd --- /dev/null +++ b/download_tree.js @@ -0,0 +1,31 @@ +var tree = [], gek, the; + +function downloadURI(uri, name) { + var link = document.createElement("a"); + link.download = name; + link.href = uri; + link.click(); +} + +async function downloadTree(id = "945859211") { + tree = await fetch("https://scratch.mit.edu/projects/"+id+"/remixtree/bare"); + tree = await tree.json(); + gek = tree.root_id; +} + +async function getPoject() { + if (the != gek) { + e = await fetch("https://api.scratch.mit.edu/projects/"+the); + e = await e.json(); + if (e.project_token != undefined) { + downloadURI("https://projects.scratch.mit.edu/"+the+"?token="+e.project_token, the) + } + the = tree[the].parent_id + } else { + console.log("end"); + } +} + +await downloadTree(); + +setInterval(getPoject, 500) \ No newline at end of file