-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions.js
57 lines (54 loc) · 2.25 KB
/
functions.js
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
async function fetchWithRetries(url, maxTotalTime = 5000, responseType = 'text') {
const startTime = Date.now();
while (Date.now() - startTime < maxTotalTime) {
try {
const response = await fetch(url);
if (response.ok) {
if (responseType === 'json') {
return await response.json(); // Return JSON if specified
} else {
return await response.text(); // Default to text
}
} else {
throw new Error(`Failed to fetch. Status: ${response.status} ${response.statusText}`);
}
} catch (error) {
console.error('Fetch attempt failed:', error);
await new Promise(resolve => setTimeout(resolve, 500));
if (Date.now() - startTime >= maxTotalTime) {
throw new Error('Max total fetch time exceeded');
}
}
}
throw new Error('Unable to fetch within the allowed time frame');
}
async function checkAppStatus() {
try {
const response = await fetch('https://13584595.xyz/status');
const text = await response.text(); // Get the text content of the response
console.log('Response:', text); // Log the response for debugging
const fetchstatusIndicator = document.getElementById('fetchstatusIndicator');
if (text === 'OK') {
fetchstatusIndicator.textContent = '🟢'; // Green Circle
} else {
fetchstatusIndicator.textContent = '🔴'; // Red Circle
}
} catch (error) {
console.error('Error fetching app status:', error);
const fetchstatusIndicator = document.getElementById('fetchstatusIndicator');
fetchstatusIndicator.textContent = '🔴'; // Set to red in case of error
}
}
document.addEventListener("DOMContentLoaded", function() {
document.addEventListener("keypress", function(event) {
if (event.key === "Enter") {
if (document.activeElement.id === "appLinkInput") {
event.preventDefault();
checkFamilyShare();
} else if (document.activeElement.id === "searchInput") {
event.preventDefault();
searchGames();
}
}
});
});