This commit is contained in:
2022-12-03 03:10:46 +01:00
parent df3312a604
commit 46d6b1d991
86 changed files with 1078 additions and 0 deletions

67
js/const.js Normal file
View File

@@ -0,0 +1,67 @@
const seasons = ["winter", "spring", "summer", "autumn"];
const winterStarts = new Date(Date.UTC(2018, 10, 8, 15, 00, 00));
let lastCheckedSeason;
let minuteInterval = 0;
let secondInterval = 0;
// List of the uploaded user's images
const userBackgrounds = {
"autumn": [
"DANGERD33-1",
"InternetExplorer8-1", // 3837x2159
"maikee_bery-1",
"MrsAverageMan-1",
"MrsAverageMan-2",
"OriginalForzaCoverArt-1",
"SkylineSonata-1",
"ThroughJaysLens-1",
"Vadeel-1",
],
"spring": [
// "-MattyMcFly-1", // Not 1080p; 1252x724
"And_Justice-1",
"AzudemK-1",
"Enzo03-1",
"flakgunna-1",
"flakgunna-2",
"OriginalForzaCoverArt-1",
"Positivevibes845-1",
"Semyonov-1", // 1440p
"slamdunk_12-1",
"xXMetalFlakeXx-1",
],
"summer": [
"MainlyGod-1",
"OfficialForzaCoverArt-1",
"Soovin-1",
"WillPill_-1",
"WallHaven-10",
"WallHaven-11",
"WallHaven-12",
"WallHaven-13",
"WallHaven-14",
"WallHaven-15",
"WallHaven-16",
"WallHaven-17",
"WallHaven-18",
"WallHaven-19",
],
"winter": [
"ARCLab-1", // 4K
"CCXGT-1",
"CraazyGamerz-1",
"DakarGelb-1",
"flakgunna-1", // 2715x1121
"kml--1",
"LooniLuna-1",
"maikee_bery-1",
"naixu-1",
"OriginalForzaCoverArt-1",
"parkel42-1",
"parkel42-2",
"sjoel92-1",
"StickManTwit-1",
"ThatsJustLogic-1",
"TigerusTheReal-1",
],
};

59
js/const.js.backup Normal file
View File

@@ -0,0 +1,59 @@
const seasons = ["winter", "spring", "summer", "autumn"];
const winterStarts = new Date(Date.UTC(2018, 10, 8, 15, 30, 00));
let lastCheckedSeason;
let minuteInterval = 0;
let secondInterval = 0;
// List of the uploaded user's images
const userBackgrounds = {
"autumn": [
"DANGERD33-1",
"InternetExplorer8-1", // 3837x2159
"maikee_bery-1",
"MrsAverageMan-1",
"MrsAverageMan-2",
"OriginalForzaCoverArt-1",
"SkylineSonata-1",
"ThroughJaysLens-1",
"Vadeel-1",
],
"spring": [
// "-MattyMcFly-1", // Not 1080p; 1252x724
"And_Justice-1",
"AzudemK-1",
"Enzo03-1",
"flakgunna-1",
"flakgunna-2",
"OriginalForzaCoverArt-1",
"Positivevibes845-1",
"Semyonov-1", // 1440p
"slamdunk_12-1",
// "ur4ddiction-1", // Not 1080p; 1022x598
"xXMetalFlakeXx-1",
],
"summer": [
"MainlyGod-1",
"OfficialForzaCoverArt-1",
"Soovin-1",
"WillPill_-1",
],
"winter": [
"ARCLab-1", // 4K
"CCXGT-1",
"CraazyGamerz-1",
"DakarGelb-1",
"flakgunna-1", // 2715x1121
"kml--1",
"LooniLuna-1",
"maikee_bery-1",
"naixu-1",
"OriginalForzaCoverArt-1",
"parkel42-1",
"parkel42-2",
// "parkel42-3", // Not a fan
"sjoel92-1",
"StickManTwit-1",
"ThatsJustLogic-1",
"TigerusTheReal-1",
],
};

69
js/content.js Normal file
View File

@@ -0,0 +1,69 @@
function setBackgroundImage(currentSeason) {
// Randomly select a background appropriate for the season
let selectedBackground = userBackgrounds[currentSeason][Math.floor(Math.random() * userBackgrounds[currentSeason].length)];
document.body.style.backgroundImage = `url(images/${currentSeason}/backgrounds/${selectedBackground}.jpg)`;
// Art credit
document.body.alt = `Image courtesy of ${selectedBackground.slice(0, -2)}`;
console.log(`Background image courtesy of ${selectedBackground.slice(0, -2)}`);
}
function setSeasonal(currentSeason, nextSeason) {
document.title = "It's " + currentSeason + " in Horizon";
document.getElementById("season-splash").src = `images/${currentSeason}/${currentSeason}-splash.svg`;
document.getElementById("countdown-title").textContent = nextSeason + " starts in";
setBackgroundImage(currentSeason);
}
function setCountdown(days, hours, minutes, seconds) {
// Set all the times
document.getElementById("days").textContent = days;
document.getElementById("hours").textContent = hours;
document.getElementById("minutes").textContent = minutes;
// Pad the seconds to two digits
document.getElementById("seconds").textContent = (seconds > 9) ? seconds : ("0" + seconds);
// Hide the days if there are zero full days left
if (days === 0) {
document.getElementById("days").style.display = "none";
document.getElementById("days-label").style.display = "none";
} else {
document.getElementById("days").style.display = "";
document.getElementById("days-label").style.display = "";
}
// Hide the hours if there are zero full hours AND days left
if (hours === 0 && days === 0) {
document.getElementById("hours").style.display = "none";
document.getElementById("hours-label").style.display = "none";
} else {
document.getElementById("hours").style.display = "";
document.getElementById("hours-label").style.display = "";
}
// Hide the minutes if there are zero full minutes, hours, AND days left
if (minutes === 0 && hours === 0 && days === 0) {
document.getElementById("minutes").style.display = "none";
document.getElementById("minutes-label").style.display = "none";
} else {
document.getElementById("minutes").style.display = "";
document.getElementById("minutes-label").style.display = "";
}
if (days === 0 && hours === 0) {
// If there are no full hours or days left, show the seconds
document.getElementById("seconds").style.display = "";
document.getElementById("seconds-label").style.display = "";
// If there are also no minutes left, show the full "seconds" label
if (minutes === 0) {
document.getElementById("seconds-label").textContent = "SECONDS";
} else {
document.getElementById("seconds-label").textContent = "S";
}
} else {
document.getElementById("seconds").style.display = "none";
document.getElementById("seconds-label").style.display = "none";
}
}

31
js/times.js Normal file
View File

@@ -0,0 +1,31 @@
function calculateTimes() {
let now = new Date();
// Calculate the number of seasons (weeks) since the seed time.
let numberOfSeasonsPassed = Math.floor(Math.abs(
(now - winterStarts) / (7 * 24 * 60 * 60 * 1000)
));
let currentSeason = seasons[numberOfSeasonsPassed % 4];
// Calculate the next season.
let nextSeason = seasons[(numberOfSeasonsPassed + 1) % 4];
let nextSeasonStart = new Date(winterStarts);
nextSeasonStart.setDate(nextSeasonStart.getDate() + ((numberOfSeasonsPassed + 1) * 7));
// How much time until the next season.
let timeTilNextSeason = nextSeasonStart - now;
let days = Math.floor(timeTilNextSeason / (24 * 60 * 60 * 1000));
let hours = Math.floor((timeTilNextSeason / (60 * 60 * 1000)) - (days * 24));
let minutes = Math.floor((timeTilNextSeason / (60 * 1000)) - (hours * 60) - (days * 24 * 60));
let seconds = Math.floor((timeTilNextSeason / 1000) - (minutes * 60) - (hours * 60 * 60) - (days * 24 * 60 * 60));
return {
currentSeason,
nextSeason,
days,
hours,
minutes,
seconds
}
}

30
js/update.js Normal file
View File

@@ -0,0 +1,30 @@
function update() {
let times = calculateTimes();
// Check if the season has changed or not
if (times.currentSeason !== lastCheckedSeason) {
setSeasonal(times.currentSeason, times.nextSeason);
lastCheckedSeason = times.currentSeason;
}
// Configure the countdown timer
setCountdown(times.days, times.hours, times.minutes, times.seconds);
//
if ((times.days === 0 && times.hours === 0) || (times.hours === 1 && times.minutes === 0)) {
// If there are just minutes (or just seconds) left, update every second.
if (!secondInterval) {
clearInterval(minuteInterval);
secondInterval = setInterval(() => update(), 1000);
}
} else {
// If there are just minutes (or just seconds) left, update every second.
if (!minuteInterval) {
clearInterval(secondInterval);
minuteInterval = setInterval(() => update(), 60000);
}
}
}
// Sets the page going.
update();