-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgithub.js
More file actions
48 lines (40 loc) · 1.44 KB
/
Copy pathgithub.js
File metadata and controls
48 lines (40 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
async function gh_get_subfolder(name, url, path) {
let response = await fetch(url);
let data = (await response.json())["tree"];
let folders = []
try {
folders = data.filter(i=>i.type=='tree');
} catch (e) {
alert("Cannot connect to GitHub API... rate limit exceeded?")
}
let files = data.filter(i=>i.type=='blob');
console.log(folders, files)
let el = document.createElement("details");
let summary = document.createElement("summary");
summary.innerText = name;
el.appendChild(summary);
for (var i=0;i<folders.length;i++) {
el.appendChild(await gh_get_subfolder(folders[i].path.split("/").slice(-1)[0], folders[i].url, path+"/"+folders[i].path))
}
for (var i=0;i<files.length;i++) {
let link = document.createElement("a");
link.href = "#";
link.innerText = files[i].path.split("/").slice(-1)[0];
link.dataset.fullpath = path + "/" + files[i].path;
console.log(files[i].url)
link.onclick = function() {
fetch("https://rawcdn.githack.com/wazzu-racing/log_files/main"+this.dataset.fullpath)
.then(r=>r.bytes())
.then(b=>fromfile(b.buffer))
fname = "GitHub - "+this.dataset.fullpath
}
el.appendChild(link);
el.appendChild(document.createElement("br"))
}
return el;
}
async function gh_get_files() {
let node = await gh_get_subfolder("Hosted Files (GitHub)", "https://api.github.com/repos/wazzu-racing/log_files/git/trees/main", "");
document.getElementById("github_files").appendChild(node);
}
// gh_get_files()