Skip to content

Commit

Permalink
replacing a buggy function with an unreadable one
Browse files Browse the repository at this point in the history
  • Loading branch information
Kordyban-Roman-CLG committed Dec 12, 2024
1 parent cbe4650 commit ff616f2
Showing 1 changed file with 15 additions and 32 deletions.
47 changes: 15 additions & 32 deletions timers/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,14 @@

<script>
const timersConfig = [
{ day: 3, hour: 3, color: '#00aaff', label: 'Counter-Strike 2' },
{ day: 3, hour: 2, color: '#00aaff', label: 'Counter-Strike 2' },
{ day: 4, hour: 16, color: '#ff5555', label: 'Dota 2' }
];

function createTimerHTML(id, config) {
const timerSection = document.createElement('div');
timerSection.className = 'timer-section';
timerSection.innerHTML = `
<div class="progress-bar" id="progress-bar-${id}" style="background-color: ${config.color};"></div>
<div class="timer-content">
<div class="timer-label">${config.label}</div>
<div class="timer-display" id="timer-display-${id}">Loading...</div>
</div>
`;
timerSection.innerHTML = `<div class="progress-bar" id="progress-bar-${id}" style="background-color:${config.color};"></div><div class="timer-content"><div class="timer-label">${config.label}</div><div class="timer-display" id="timer-display-${id}">Loading...</div></div>`;

for (let i = 1; i <= 6; i++) {
const divider = document.createElement('div');
Expand All @@ -116,36 +110,25 @@
}

const timersContainer = document.getElementById('timers-container');
timersConfig.forEach((config, index) => {
timersContainer.appendChild(createTimerHTML(index, config));
});

function getNextUpdateTime(targetDay, targetHour) {
const now = new Date();
const nowUTC = now.getTime();
const nextUpdate = new Date(nowUTC + ((targetDay - now.getUTCDay() + 7) % 7 || 7) * 86400000);
nextUpdate.setUTCHours(targetHour, 0, 0, 0);
return nextUpdate;
timersConfig.forEach((config, index) => { timersContainer.appendChild(createTimerHTML(index, config)); });

function getRemainingTime(targetDay, targetHour) {
return Math.floor((3 + targetDay + targetHour / 24) * (60 * 60 * 24) - ((new Date()).getTime() / 1000) % (60 * 60 * 24));
}

function updateTimers() {
const now = new Date();

timersConfig.forEach((config, index) => {
const nextUpdate = getNextUpdateTime(config.day, config.hour);
const totalMillis = nextUpdate - now;
const totalSeconds = Math.floor(totalMillis / 1000);
const totalSeconds = getRemainingTime(config.day, config.hour);

const days = Math.floor(totalSeconds / 86400);
const hours = Math.floor((totalSeconds % 86400) / 3600);
const minutes = Math.floor((totalSeconds % 3600) / 60);
const seconds = totalSeconds % 60;
const days = Math.floor(totalSeconds / 86400).toString().padStart(2, '0');
const hours = Math.floor((totalSeconds % 86400) / 3600).toString().padStart(2, '0');
const minutes = Math.floor((totalSeconds % 3600) / 60).toString().padStart(2, '0');
const seconds = Math.floor(totalSeconds % 60).toString().padStart(2, '0');

document.getElementById(`timer-display-${index}`).innerText =
`${days.toString().padStart(2, '0')}:${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
document.getElementById(`timer-display-${index}`).innerText = `${days}:${hours}:${minutes}:${seconds}`;

const weekMillis = 7 * 24 * 60 * 60 * 1000;
const progress = 100 - (totalMillis / weekMillis * 100);
const weekSeconds = 7 * 24 * 60 * 60;
const progress = 100 - (totalSeconds / weekSeconds * 100);
document.getElementById(`progress-bar-${index}`).style.width = `${progress}%`;
});
}
Expand All @@ -155,4 +138,4 @@
</script>
</body>

</html>
</html>

0 comments on commit ff616f2

Please sign in to comment.