Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Days Till Year Ends #43

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Added feature that shows days till year ends
  • Loading branch information
StanzTheDev committed Oct 21, 2024
commit cf8879ed11765b3fd0b5a163c0412848bf404874
29 changes: 29 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -50,6 +50,12 @@
height: auto;
border-radius: 1rem;
}
#counter {
font-size: 20px;
text-align: center;
padding: 20px;
border-radius: 10px;
}

@media (max-width: 768px) {
h1 {
@@ -79,13 +85,18 @@
font-size: 0.8rem;
padding: 6px;
}
#counter {
font-size: 12px;
}
}
</style>
</head>

<body>
<h1>Year Progress</h1>
<img id="progress-img" src="https://year-in-progress.vercel.app/year-progress" alt="Year Progress">
<!-- Days Before The Year Ends -->
<div id="counter"></div>

<!-- Button positioned directly below the progress bar and aligned to the left -->
<button id="theme-toggle" class="btn"><i>Switch to Dark Mode</i></button>
@@ -133,6 +144,24 @@ <h1>Year Progress</h1>

// Update the progress image every second
setInterval(updateProgressImg, 1000);
//Function For Days Untill The Year Ends
function tilYearEnd() {
const now = new Date();
const yearEnd = new Date(now.getFullYear(), 11, 31);
const timeDiff = yearEnd.getTime() - now.getTime();
const daysDiff = Math.ceil(timeDiff / (1000 * 3600 * 24));
return daysDiff;
}

function updateCounter() {
const daysLeft = tilYearEnd();
const counterElement = document.getElementById('counter');
counterElement.textContent = `${daysLeft} day${daysLeft !== 1 ? 's' : ''} left until the end of the year!`;
}

// Update the counter immediately and then every 24 hours
updateCounter();
setInterval(updateCounter, 24 * 60 * 60 * 1000);
</script>
</body>