Skip to content

Commit

Permalink
season status & release countdown
Browse files Browse the repository at this point in the history
readded season status
update release countdown
  • Loading branch information
HerrErde committed May 13, 2023
1 parent 8d83d1c commit 8c08537
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 23 deletions.
14 changes: 12 additions & 2 deletions assets/js/githubRelease.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,46 @@
const owner = 'HerrErde';
const repo = 'SubwayBooster';

// Define constants for milliseconds per day, hour, minute, and release cycle
const MILLISECONDS_PER_DAY = 1000 * 60 * 60 * 24;
const MILLISECONDS_PER_HOUR = 1000 * 60 * 60;
const MILLISECONDS_PER_MINUTE = 1000 * 60;
const MILLISECONDS_PER_RELEASE_CYCLE = (21 * 24 + 10) * MILLISECONDS_PER_HOUR;

// Define variables to store the latest release and the time of the last fetch
let latestRelease = null;
let lastFetchTime = 0;

// Define an asynchronous function to fetch the latest release of the specified repository
async function fetchLatestRelease() {
const response = await fetch(
`https://api.github.com/repos/${owner}/${repo}/releases/latest`
);

if (!response.ok) {
// if the response is not successful, log an error message and return null
console.log('Failed to get latest release.');
return null;
}

return response.json();
return response.json(); // return the parsed JSON data of the latest release
}

// Define a function to update the time until the next release
async function updateRelease() {
if (!latestRelease) {
// if the latest release has not been fetched yet, fetch it
latestRelease = await fetchLatestRelease();
}

// Calculate the time since the latest release and the time until the next release based on the release cycle
const releaseDate = new Date(latestRelease.published_at);
const timeSinceRelease = Date.now() - releaseDate;

const timeUntilNextRelease =
MILLISECONDS_PER_RELEASE_CYCLE -
(timeSinceRelease % MILLISECONDS_PER_RELEASE_CYCLE);

// Format the time as days, hours, and minutes
const daysUntilNextRelease = Math.floor(
timeUntilNextRelease / MILLISECONDS_PER_DAY
);
Expand All @@ -43,8 +51,10 @@ async function updateRelease() {
(timeUntilNextRelease % MILLISECONDS_PER_HOUR) / MILLISECONDS_PER_MINUTE
);

// Update the text content of an HTML element with id "release"
const releaseElement = document.getElementById('release');
releaseElement.textContent = `~${daysUntilNextRelease}d ${hoursUntilNextRelease}h ${minutesUntilNextRelease}m`;
}

// Call the updateRelease function to initialize the time until the next release when the page loads
updateRelease();
46 changes: 25 additions & 21 deletions require/info.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,31 @@
$api = json_decode(file_get_contents($playapi), true);
?>

<div class="version-info">
<div class="version-column">
<div>
<span>Latest Version:</span>
<span>v<?= $json["version"] ?></span>
<div class="version-info">
<div class="version-column">
<div>
<span>Season:</span>
<span><?= $json["season"] ?></span>
</div>
<div>
<span>Latest Version:</span>
<span>v<?= $json["version"] ?></span>
</div>
<div>
<span>Next Release:</span>
<span id="release"></span>
</div>
</div>
<div class="version-column">
<div>
<span>Latest App Version:</span>
<span><?= $api["version"] ?></span>
</div>
<div>
<span>Supported App Version:</span>
<span><?= $json["appversion"] ?></span>
</div>
</div>
</div>
<div>
<span>Next Release:</span>
<span id="release"></span>
</div>
</div>
<div class="version-column">
<div>
<span>Latest App Version:</span>
<span><?= $api["version"] ?></span>
</div>
<div>
<span>Supported App Version:</span>
<span><?= $json["appversion"] ?></span>
</div>
</div>
</div>
</body>
</html>

0 comments on commit 8c08537

Please sign in to comment.