-
Notifications
You must be signed in to change notification settings - Fork 0
/
dl.html
225 lines (194 loc) · 8.51 KB
/
dl.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Downloading...</title>
<style>
body {
background-color: #121212;
color: #ffffff;
font-family: Arial, sans-serif;
text-align: center;
}
#invalid-os-warning {
color: red;
font-size: 24px;
}
a {
color: #bb86fc;
}
#header-image {
max-width: 100%;
height: auto;
}
#noscript-warning {
color: red;
font-size: 20px;
margin: 20px;
}
.rate-limit-warning {
color: yellow;
font-size: 20px;
}
</style>
</head>
<body>
<noscript>
<div id="noscript-warning">Warning! NoScript detected! This website will not work without Javascript. Sorry about that.</div>
</noscript>
<div id="download-container">
<div>
<img id="header-image" src="assets/pghead.png" alt="Header Image" style="max-width: 100%; height: auto;">
</div>
<h1 id="download-title" style="display: none;">Downloading the files now</h1>
<p id="download-prompt" style="display: none;">If the download has not started, <a id="download-link" href="#">Click Here</a></p>
<div id="message"></div>
<div id="rate-limit-message" class="rate-limit-warning"></div>
<div id="invalid-os-warning"></div>
</div>
<script>
function getQueryParameters() {
const params = {};
const queryString = window.location.search.substring(1);
const regex = /([^&=]+)=([^&]*)/g;
let m;
while (m = regex.exec(queryString)) {
params[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
}
return params;
}
function getOperatingSystem() {
const params = getQueryParameters();
if (params['os']) {
return params['os'].toLowerCase();
}
const userAgent = window.navigator.userAgent.toLowerCase();
if (userAgent.includes("windows")) return "windows";
if (userAgent.includes("mac")) return "mac";
if (userAgent.includes("linux")) return "linux";
return "unknown";
}
async function fetchReleases(repoName, owner) {
const response = await fetch(`https://api.github.com/repos/${owner}/${repoName}/releases`);
if (response.status === 403) {
const remaining = response.headers.get('X-RateLimit-Remaining');
const reset = response.headers.get('X-RateLimit-Reset');
if (remaining === '0') {
const resetTime = new Date(reset * 1000);
const rateLimitMessage = `Rate limit exceeded. Please try again after ${resetTime.toLocaleString()}.`;
document.getElementById("rate-limit-message").textContent = rateLimitMessage;
throw new Error(rateLimitMessage);
}
}
if (!response.ok) {
throw new Error('Failed to fetch releases');
}
return await response.json();
}
async function fetchSpecificRelease(repoName, version, owner) {
const response = await fetch(`https://api.github.com/repos/${owner}/${repoName}/releases/tags/${version}`);
if (!response.ok) {
throw new Error('Failed to fetch specific version release');
}
return await response.json();
}
async function fetchLatestPreRelease(repoName, owner) {
const response = await fetch(`https://api.github.com/repos/${owner}/${repoName}/releases?per_page=1`);
if (!response.ok) {
throw new Error('Failed to fetch pre-releases');
}
const releases = await response.json();
return releases;
}
async function downloadFile() {
const params = getQueryParameters();
const os = getOperatingSystem();
// Check if 'os' is Android, iOS, or mobile
if (['android', 'ios', 'mobile'].includes(os)) {
displayMessage("Fetching your download... Just a moment.");
setTimeout(() => {
// Redirect to rickroll after a delay
window.location.href = "https://www.youtube.com/watch?v=dQw4w9WgXcQ";
}, 3000); // 3 seconds delay
return;
}
if (Object.keys(params).length === 0) {
alert("No query parameters present. Closing the tab.");
window.close();
return;
}
const ownerParam = params['owner'] || 'pikakid98-games';
const repoParam = params['repo'];
const specificFileParam = params['file'];
const versionParam = params['ver'];
const isDev = params['dev'] === "1";
if (!repoParam) {
displayMessage("No repository specified in the query parameter.");
return;
}
let fileUrl;
if (os === 'unknown' || (os !== 'windows' && os !== 'mac' && os !== 'linux')) {
displayMessage("Unsupported operating system. Click the link below to download anyway (recommend using WINE from https://www.winehq.org)");
const downloadUrl = `https://github.com/${ownerParam}/${repoParam}/releases/latest`; // fallback URL
document.getElementById("invalid-os-warning").innerHTML = `<a href="${downloadUrl}" target="_blank">Download Anyway</a>`;
return;
}
try {
let releases;
if (versionParam) {
const release = await fetchSpecificRelease(repoParam, versionParam, ownerParam);
releases = [release];
} else {
releases = await fetchReleases(repoParam, ownerParam);
}
// File fetching logic
const assets = releases.flatMap(release => release.assets);
if (specificFileParam) {
const specificFile = assets.find(asset => asset.name === specificFileParam);
if (specificFile) {
fileUrl = specificFile.browser_download_url;
} else {
throw new Error(`File "${specificFileParam}" not found in the repository.`);
}
} else {
const foundFiles = assets.filter(asset =>
asset.name.toLowerCase().includes(`_${os}`) &&
(asset.name.toLowerCase().endsWith('.zip') || asset.name.toLowerCase().endsWith('.7z'))
);
if (foundFiles.length > 0) {
fileUrl = foundFiles[0].browser_download_url; // Get the first matched file
} else {
throw new Error(`No suitable file found for OS: ${os}.`);
}
}
// Check for dev parameter
if (isDev && !versionParam) {
const latestPreRelease = await fetchLatestPreRelease(repoParam, ownerParam);
const latestPreReleaseFound = latestPreRelease.find(release => release.prerelease);
if (latestPreReleaseFound) {
fileUrl = latestPreReleaseFound.assets[0].browser_download_url;
}
}
document.getElementById("download-title").style.display = "block";
document.getElementById("download-prompt").style.display = "block";
document.getElementById("download-link").href = fileUrl;
window.location = fileUrl;
console.log("Download initiated for: " + fileUrl);
setTimeout(() => {
window.history.back();
}, 3000);
} catch (error) {
console.error(error);
displayMessage("Error fetching releases: " + error.message);
}
}
function displayMessage(msg) {
const messageDiv = document.getElementById("message");
messageDiv.innerHTML = '';
messageDiv.textContent = msg;
}
window.onload = downloadFile;
</script>
</body>
</html>