From 223c8389324c45885da68d46330b2d468ef34789 Mon Sep 17 00:00:00 2001 From: Sean O'Connor Date: Wed, 5 Mar 2025 12:42:17 -0500 Subject: [PATCH] Add 'Why?' button and improve button layout --- api.js | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ index.html | 25 ++++++++++++++++------- style.css | 50 ++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 124 insertions(+), 10 deletions(-) create mode 100644 api.js diff --git a/api.js b/api.js new file mode 100644 index 0000000..6204dae --- /dev/null +++ b/api.js @@ -0,0 +1,59 @@ +/** + * October Today API + * Simple client-side API that returns the current October day count + */ + +// Calculate days since October 1, 2019 +function calculateOctoberDay() { + const startDate = new Date(2019, 9, 1); // Month is 0-indexed, so 9 is October + const today = new Date(); + + // Calculate difference in days + const diffTime = Math.abs(today - startDate); + const diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24)); + + return diffDays; +} + +// Set ordinal suffix (st, nd, rd, th) +function getOrdinalSuffix(number) { + const j = number % 10; + const k = number % 100; + + if (j === 1 && k !== 11) { + return "st"; + } + if (j === 2 && k !== 12) { + return "nd"; + } + if (j === 3 && k !== 13) { + return "rd"; + } + return "th"; +} + +// Handle requests for the API +document.addEventListener('DOMContentLoaded', () => { + // Check if this is an API request from the URL + const urlParams = new URLSearchParams(window.location.search); + const isApiRequest = urlParams.get('api'); + + if (isApiRequest === 'json') { + const octoberDay = calculateOctoberDay(); + const suffix = getOrdinalSuffix(octoberDay); + + // Create the response object + const response = { + day: octoberDay, + ordinal: suffix, + formatted: `${octoberDay}${suffix}`, + text: `happy october ${octoberDay}${suffix}` + }; + + // Display as JSON and prevent normal page rendering + document.body.innerHTML = `
${JSON.stringify(response, null, 2)}
`; + document.body.style.fontFamily = 'monospace'; + document.body.style.padding = '20px'; + document.body.style.backgroundColor = '#f5f5f5'; + } +}); \ No newline at end of file diff --git a/index.html b/index.html index a5b51d3..78c36d7 100644 --- a/index.html +++ b/index.html @@ -18,14 +18,25 @@

October ??th

2019.

- +
+ + + + + + + + Why? + +
+ \ No newline at end of file diff --git a/style.css b/style.css index da32307..c4bf1c1 100644 --- a/style.css +++ b/style.css @@ -226,6 +226,13 @@ footer { z-index: 10; } +.buttons { + display: flex; + justify-content: center; + gap: 12px; + margin-top: 24px; +} + .share-button { display: inline-flex; align-items: center; @@ -239,7 +246,6 @@ footer { font-weight: 500; cursor: pointer; transition: all 0.2s ease; - margin-top: 24px; } .share-button:hover { @@ -259,6 +265,39 @@ footer { transform: translateY(-2px); } +.why-button { + display: inline-flex; + align-items: center; + gap: 8px; + background-color: var(--secondary); + color: var(--secondary-foreground); + border: none; + border-radius: var(--radius); + padding: 10px 16px; + font-size: 14px; + font-weight: 500; + cursor: pointer; + transition: all 0.2s ease; + text-decoration: none; +} + +.why-button:hover { + opacity: 0.9; + transform: translateY(-2px); +} + +.why-button:active { + transform: translateY(0); +} + +.why-button svg { + transition: transform 0.2s ease; +} + +.why-button:hover svg { + transform: rotate(12deg); +} + @media (max-width: 600px) { .container { padding: 30px; @@ -272,8 +311,13 @@ footer { font-size: 2.5rem; } - .share-button { - padding: 8px 14px; + .share-button, .why-button { + padding: 8px 12px; font-size: 13px; } + + .buttons { + flex-direction: column; + gap: 8px; + } } \ No newline at end of file