-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
182 lines (170 loc) · 7.32 KB
/
index.html
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<!DOCTYPE html>
<html lang="en">
<head>
<script>
// the woes of attempting to code on a school computer... where inspect element is blocked...
window.onerror = (message, url, lineNumber, colNumber) => {alert(message+'\n\n'+lineNumber+':'+colNumber)}
</script>
<title>GitHub Downloads</title>
<style>
:root {
color-scheme: light dark;
}
body {
/* right: 50%;
bottom: 50%;
transform: translate(50%,50%);
position: absolute; */
text-align: center;
overfloW: auto;
}
.downloads {
text-align: center;
}
td, th {
padding: 3px;
}
* {
font-family: Helvetica;
}
</style>
<script type="text/javascript" src="./day.js"></script>
<script>
function startTheThing() {
document.getElementById('downloads').innerHTML = '<p><i>Starting...</i></p>';
var xhttp1 = new XMLHttpRequest();
var xhttp2 = new XMLHttpRequest();
var xhttp3 = new XMLHttpRequest();
var xhttp4 = new XMLHttpRequest();
var repoId = 0;
xhttp1.onreadystatechange = function() {
if (this.readyState == 4) {
if (this.status == 200) {
document.getElementById('downloads').innerHTML = '<p><i>Attempting to get array from the archive...</i></p>';
repoId = JSON.parse(this.responseText).id;
xhttp3.open('GET', './downloads/' + repoId + '/files.json');
xhttp3.send();
} else {
xhttp2.open('GET', './downloads/repositories.json');
xhttp2.send();
}
}
}
xhttp2.onreadystatechange = function() {
if (this.readyState == 4) {
if (this.status == 200) {
document.getElementById('downloads').innerHTML = '<p><i>Attempting to get repository from the archive...</i></p>';
var repositoryIndex = JSON.parse(this.responseText)[document.getElementById("username").value.trim() + '/' + document.getElementById("repository").value.trim()];
if ((!(repositoryIndex == undefined)) || repositoryIndex) {
document.getElementById('downloads').innerHTML = '<p><i>Attempting to get array from the archive...</i></p>';
repoId = repositoryIndex;
xhttp3.open('GET', './downloads/' + repoId + '/files.json');
xhttp3.send();
} else {
document.getElementById('downloads').innerHTML = '<p><i>Couldn\'t get repository</i></p>';
}
} else {
document.getElementById('downloads').innerHTML = '<p><i>Couldn\'t get repository</i></p>';
}
}
}
xhttp3.onreadystatechange = function() {
if (this.readyState == 4) {
if (this.status == 200) {
doTheThing(this.responseText, repoId);
} else {
document.getElementById('downloads').innerHTML = '<p><i>Attempting to get array from the GitHub API...</i></p>';
xhttp3.open('GET', 'https://api.github.com/repos/' + document.getElementById("username").value.trim() + '/' + document.getElementById("repository").value.trim() + '/downloads', true);
xhttp3.send();
}
}
}
xhttp4.onreadystatechange = function() {
if (this.readyState == 4) {
if (this.status == 200) {
doTheThing(this.responseText, repoId);
} else {
document.getElementById('downloads').innerHTML = '<p><i>Couldn\'t get array</i></p>';
}
}
}
document.getElementById('downloads').innerHTML = '<p><i>Attempting to get repository from the GitHub API...</i></p>';
xhttp1.open('GET', 'https://api.github.com/repos/' + document.getElementById("username").value.trim() + '/' + document.getElementById("repository").value.trim(), true);
xhttp1.send();
}
function doTheThing(array, repoId) {
// so many of these would be EXCELLENT as not variables but JAVASCRIPT IS A HOE
// sorry for the inconsistent names lol
document.getElementById('downloads').innerHTML = '';
if (JSON.parse(array) === undefined || JSON.parse(array).length == 0) {
document.getElementById('downloads').innerHTML = '<p><i>Couldn\'t find any downloads for repository</i></p>';
return;
}
var table = document.createElement('table');
var tbody = document.createElement('tbody');
var row = document.createElement('tr');
var nameheader = document.createElement('th');
var descheader = document.createElement('th');
var dateheader = document.createElement('th');
var urlheader = document.createElement('th');
var nameheadertext = document.createTextNode('Name');
var descheadertext = document.createTextNode('Description');
var dateheadertext = document.createTextNode('Date');
var urlheadertext = document.createTextNode('Download');
row.appendChild(nameheader);
row.appendChild(descheader);
row.appendChild(dateheader);
row.appendChild(urlheader);
nameheader.appendChild(nameheadertext);
descheader.appendChild(descheadertext);
dateheader.appendChild(dateheadertext);
urlheader.appendChild(urlheadertext);
tbody.appendChild(row);
JSON.parse(array).forEach((download) => {
var row = document.createElement('tr');
var namefield = document.createElement('td');
var descfield = document.createElement('td');
var datefield = document.createElement('td');
var urlfield = document.createElement('td');
var name = document.createTextNode(download.name);
var desc = document.createTextNode(download.description);
var date = document.createTextNode(dayjs(download.created_at));
var url = document.createElement('a');
url.href = download.html_url ? download.html_url : ('./downloads/' + repoId + '/' + download.id);
url.download = download.name;
url.textContent = 'Download';
namefield.appendChild(name);
datefield.appendChild(date);
descfield.appendChild(desc);
urlfield.appendChild(url);
row.appendChild(namefield);
row.appendChild(descfield);
row.appendChild(datefield);
row.appendChild(urlfield);
tbody.appendChild(row);
})
table.appendChild(tbody);
document.getElementById('downloads').appendChild(table);
}
</script>
</head>
<body>
<p><b style="font-size:150%">GitHub Downloads</b></p>
<noscript>Unfortunately, you need JavaScript for this. Sorry!</noscript>
<form action="javascript:startTheThing()">
https://github.com/
<input type="text" id="username" name="username">
/
<input type="text" id="repository" name="repository">
<br>
<br>
<input type="submit" value="Submit">
<br>
<p>this is really barebones and poorly put together, sorry lol</p>
</form>
<br>
<div id="downloads"></div>
<br>
<p><a href="https://github.com/jbmagination/githubdownloads" style="font-size:75%">Source code, licenses, and takedowns</a></p>
</body>
</html>