Skip to content

Commit

Permalink
moved javascript from html to background.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Bioblaze committed Oct 11, 2024
1 parent efb8374 commit 1e21548
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 47 deletions.
47 changes: 0 additions & 47 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -140,52 +140,5 @@ <h3 style="font-family: 'Syncopate', sans-serif; text-align: center;">Blazium En
</div>
</div>

<script>
// Function to fetch mirrorlist from the API
function fetchReleaseInfo() {
const protocol = window.location.protocol;
const host = window.location.host;
const apiUrl = `${protocol}//${host}/api/mirrorlist/latest/json`;

console.log("Fetching from URL:", apiUrl); // Add this line to check the URL

fetch(apiUrl)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok ' + response.statusText);
}
return response.json();
})
.then(data => {
const releaseMessage = document.getElementById('release-message');

if (data.mirrors.length === 0) {
releaseMessage.innerHTML = 'Release is pending, visit our <a href="https://discord.gg/sZaf9KYzDp" style="color: #E83951;">Discord</a> for more information.';
} else {
const mirrors = data.mirrors.map(mirror => `
<li>
<a href="${mirror.download_url}" style="color: #E83951;">Download</a> |
SHA256: ${mirror.sha} |
Release Date: ${mirror.release_date}
</li>
`).join('');

releaseMessage.innerHTML = `
<ul style="list-style: none; padding-left: 0; text-align: center;">
${mirrors}
</ul>
`;
}
})
.catch(error => {
console.error('Error fetching release information:', error);
document.getElementById('release-message').innerHTML = 'Error fetching release information. Please try again later.';
});
}

// Call the function to fetch the release info when the page loads
window.onload = fetchReleaseInfo;
</script>

</body>
</html>
45 changes: 45 additions & 0 deletions static/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,51 @@ document.addEventListener('DOMContentLoaded', function () {
}
},"retina_detect":true
});

function fetchReleaseInfo() {
const protocol = window.location.protocol;
const host = window.location.host;
const apiUrl = `${protocol}//${host}/api/mirrorlist/latest/json`;

console.log("Fetching from URL:", apiUrl); // Add this line to check the URL

fetch(apiUrl)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok ' + response.statusText);
}
return response.json();
})
.then(data => {
const releaseMessage = document.getElementById('release-message');

if (data.mirrors.length === 0) {
releaseMessage.innerHTML = 'Release is pending, visit our <a href="https://discord.gg/sZaf9KYzDp" style="color: #E83951;">Discord</a> for more information.';
} else {
const mirrors = data.mirrors.map(mirror => `
<li>
<a href="${mirror.download_url}" style="color: #E83951;">Download</a> |
SHA256: ${mirror.sha} |
Release Date: ${mirror.release_date}
</li>
`).join('');

releaseMessage.innerHTML = `
<ul style="list-style: none; padding-left: 0; text-align: center;">
${mirrors}
</ul>
`;
}
})
.catch(error => {
console.error('Error fetching release information:', error);
document.getElementById('release-message').innerHTML = 'Error fetching release information. Please try again later.';
});
}

// Call the function to fetch the release info when the page loads
window.onload = fetchReleaseInfo;

var intro = document.getElementById('intro');
intro.style.marginTop = - intro.offsetHeight / 2 + 'px';
}, false);

0 comments on commit 1e21548

Please sign in to comment.