Skip to content

Commit 39b6ec8

Browse files
authored
Create download.html
1 parent 21963c0 commit 39b6ec8

1 file changed

Lines changed: 168 additions & 0 deletions

File tree

shreddedpaper/download.html

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
2+
<title>ShreddedPaper Downloads</title>
3+
4+
<style>
5+
html {
6+
height: 100%;
7+
}
8+
9+
body {
10+
background: #f8fff8;
11+
display: flex;
12+
font-family: Arial, Helvetica, sans-serif;
13+
height: 100%;
14+
justify-content: center;
15+
margin: 0;
16+
}
17+
18+
main {
19+
background: white;
20+
box-shadow: 0 0 5px #637063;
21+
height: fit-content;
22+
margin: 0 auto;
23+
min-width: 850px;
24+
padding: 40px 10px;
25+
text-align: center;
26+
}
27+
28+
table {
29+
font-size: 0.9em;
30+
width: 100%;
31+
}
32+
33+
tr.header {
34+
font-size: 1.2em;
35+
text-align: center;
36+
}
37+
38+
td {
39+
border-bottom: 1px #aaa solid;
40+
min-width: 170px;
41+
padding: 15px;
42+
padding-top: 17px;
43+
text-align: center;
44+
}
45+
46+
ul {
47+
list-style-type: none;
48+
padding-left: 0;
49+
margin: 0;
50+
text-align: left;
51+
}
52+
53+
li {
54+
width: 450px;
55+
white-space: nowrap;
56+
overflow: hidden;
57+
text-overflow: ellipsis;
58+
}
59+
60+
code {
61+
position: relative;
62+
top: -2px;
63+
}
64+
65+
a {
66+
color: rgb(0, 153, 0);
67+
}
68+
</style>
69+
70+
<main>
71+
<h1>ShreddedPaper Downloads</h1>
72+
<p>
73+
ShreddedPaper downloads on this page are licensed under <a href="https://github.com/MultiPaper/ShreddedPaper/blob/main/LICENSE.txt">GPLv3</a><br/>
74+
</p>
75+
</main>
76+
77+
<script>
78+
const insertVersionGroupLinks = (versions, selectedVersion, latestVersion) => {
79+
const p = document.createElement('p');
80+
p.innerHTML = versions
81+
.map(version => version == selectedVersion ? version : `<a href="?${version}">${version}</a>`)
82+
.join(' | ');
83+
document.querySelector('main').appendChild(p);
84+
85+
if (selectedVersion != latestVersion) {
86+
const error = document.createElement('p');
87+
error.innerHTML = 'Warning: These versions are outdated and may not contain the latest security and stability features.<br/>No support will be given for these builds.';
88+
error.style.color = 'red';
89+
document.querySelector('main').appendChild(error);
90+
} else {
91+
const error = document.createElement('p');
92+
error.innerHTML = 'Warning: These builds may contain occasional bugs and glitches. Test thoroughly before use in production.<br/>Please report any bugs you find on the <a href="https://github.com/MultiPaper/ShreddedPaper/issues/">GitHub</a>.';
93+
error.style.color = 'red';
94+
document.querySelector('main').appendChild(error);
95+
}
96+
}
97+
98+
const insertVersion = version => {
99+
const h2 = document.createElement('h2');
100+
h2.innerText = `Version ${version}`;
101+
document.querySelector('main').appendChild(h2);
102+
103+
table = document.createElement('table');
104+
table.innerHTML = '<tr class="header"><td>Build No.</td><td>Changes</td><td>Download</td></tr>'
105+
table.cellSpacing = 0;
106+
document.querySelector('main').appendChild(table);
107+
108+
return table;
109+
};
110+
111+
const insertBuild = (data, table) => {
112+
const tr = document.createElement('tr');
113+
114+
table.appendChild(tr);
115+
116+
const build = document.createElement('td');
117+
build.innerHTML = `<b>#${data.build}</b> ${new Date(data.time).toLocaleDateString()}`;
118+
tr.appendChild(build);
119+
120+
const changes = document.createElement('td');
121+
changes.innerHTML = `<ul>${data.changes.map(change => `<li><code>[<a href="https://github.com/MultiPaper/ShreddedPaper/commit/${change.commit}">${change.commit.substr(0, 7)}</a>]</code> ${change.summary}</li>`).join('')}</ul>`;
122+
tr.appendChild(changes);
123+
124+
const downloads = document.createElement('td');
125+
downloads.innerHTML = Object.values(data.downloads).map(download => `<a href="${getFileUrl(data, download.name)}">${download.name}</a>`).join('<br/>');
126+
tr.appendChild(downloads);
127+
};
128+
129+
const getFileUrl = (build, file) => {
130+
return `https://api.multipaper.io/v2/projects/shreddedpaper/versions/${build.version}/builds/${build.build}/downloads/${file}`;
131+
};
132+
133+
const fetchBuilds = async (url) => {
134+
const data = await (await fetch(url)).json();
135+
136+
let lastVersion;
137+
let table;
138+
139+
for (let i = data.builds.length - 1; i >= 0 && i >= data.builds.length - 50; i--) {
140+
const build = data.builds[i];
141+
142+
if (build.version != lastVersion) {
143+
lastVersion = build.version;
144+
table = insertVersion(lastVersion);
145+
}
146+
147+
insertBuild(build, table);
148+
}
149+
};
150+
151+
const fetchVersions = async (url) => {
152+
const data = await (await fetch(url)).json();
153+
154+
const lastestVersion = data.version_groups[data.version_groups.length - 1];
155+
let versionGroup;
156+
if (location.search.length && ~data.version_groups.indexOf(location.search.substr(1))) {
157+
versionGroup = location.search.substr(1);
158+
} else {
159+
versionGroup = lastestVersion;
160+
}
161+
162+
insertVersionGroupLinks(data.version_groups, versionGroup, lastestVersion);
163+
164+
fetchBuilds(`${url}/version_group/${versionGroup}/builds`);
165+
};
166+
167+
fetchVersions('https://api.multipaper.io/v2/projects/shreddedpaper');
168+
</script>

0 commit comments

Comments
 (0)