mirror of
https://github.com/soconnor0919/october.today.git
synced 2025-12-15 07:24:44 -05:00
Redesign site with enhanced UI, animations, and SMS sharing feature
This commit is contained in:
86
script.js
86
script.js
@@ -12,31 +12,73 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
// Add 1 because October 1 is the first day
|
||||
const octoberDay = diffDays + 1;
|
||||
|
||||
// Set the day in the HTML
|
||||
document.getElementById('october-day').textContent = octoberDay;
|
||||
// Animate the counter
|
||||
const octoberDayElement = document.getElementById('october-day');
|
||||
const targetNumber = octoberDay;
|
||||
|
||||
// Start from a lower number for animation
|
||||
let currentNumber = Math.max(1, targetNumber - 50);
|
||||
|
||||
// Set initial value
|
||||
octoberDayElement.textContent = currentNumber;
|
||||
|
||||
// Animate the number counting up
|
||||
const counterAnimation = setInterval(() => {
|
||||
currentNumber++;
|
||||
octoberDayElement.textContent = currentNumber;
|
||||
|
||||
if (currentNumber >= targetNumber) {
|
||||
clearInterval(counterAnimation);
|
||||
// Once animation is done, set the correct ordinal suffix
|
||||
setOrdinalSuffix(targetNumber);
|
||||
}
|
||||
}, 30);
|
||||
|
||||
// Set the correct ordinal suffix (st, nd, rd, th)
|
||||
const ordinal = document.getElementById('ordinal');
|
||||
|
||||
if (octoberDay % 100 >= 11 && octoberDay % 100 <= 13) {
|
||||
// Special case for 11th, 12th, 13th
|
||||
ordinal.textContent = 'th';
|
||||
} else {
|
||||
switch (octoberDay % 10) {
|
||||
case 1:
|
||||
ordinal.textContent = 'st';
|
||||
break;
|
||||
case 2:
|
||||
ordinal.textContent = 'nd';
|
||||
break;
|
||||
case 3:
|
||||
ordinal.textContent = 'rd';
|
||||
break;
|
||||
default:
|
||||
ordinal.textContent = 'th';
|
||||
function setOrdinalSuffix(number) {
|
||||
const ordinal = document.getElementById('ordinal');
|
||||
|
||||
if (number % 100 >= 11 && number % 100 <= 13) {
|
||||
// Special case for 11th, 12th, 13th
|
||||
ordinal.textContent = 'th';
|
||||
} else {
|
||||
switch (number % 10) {
|
||||
case 1:
|
||||
ordinal.textContent = 'st';
|
||||
break;
|
||||
case 2:
|
||||
ordinal.textContent = 'nd';
|
||||
break;
|
||||
case 3:
|
||||
ordinal.textContent = 'rd';
|
||||
break;
|
||||
default:
|
||||
ordinal.textContent = 'th';
|
||||
}
|
||||
}
|
||||
|
||||
// Set the page title to include the current October day
|
||||
document.title = `October ${number}${ordinal.textContent}, 2019`;
|
||||
|
||||
// Setup SMS share button
|
||||
setupShareButton(number, ordinal.textContent);
|
||||
}
|
||||
|
||||
// Set the page title to include the current October day
|
||||
document.title = `October ${octoberDay}${ordinal.textContent}, 2019`;
|
||||
// Setup SMS share button
|
||||
function setupShareButton(dayNumber, ordinalSuffix) {
|
||||
const shareButton = document.getElementById('share-button');
|
||||
|
||||
if (shareButton) {
|
||||
shareButton.addEventListener('click', function() {
|
||||
// Create the message: "happy october xxxxth"
|
||||
const message = `happy october ${dayNumber}${ordinalSuffix}`;
|
||||
|
||||
// Create SMS link with the message
|
||||
const smsLink = `sms:?&body=${encodeURIComponent(message)}`;
|
||||
|
||||
// Open the SMS app
|
||||
window.open(smsLink, '_blank');
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user