From 8b0950b53810ecafd019033f3ac7133e1910249c Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Mon, 16 Jun 2025 08:31:06 +1000 Subject: [PATCH] refactor: update post-it note color selection to use date-based hashing --- website/main.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/website/main.js b/website/main.js index a60ee05..90b7e19 100644 --- a/website/main.js +++ b/website/main.js @@ -24,11 +24,23 @@ function getRandomPostItColor() { return postItColors[Math.floor(Math.random() * postItColors.length)]; } +function getPostItColorByDate(dateString) { + // Create a simple hash from the date string + let hash = 0; + for (let i = 0; i < dateString.length; i++) { + hash = ((hash << 5) - hash) + dateString.charCodeAt(i); + hash = hash & hash; // Convert to 32-bit integer + } + // Use absolute value and modulo to get color index + const colorIndex = Math.abs(hash) % postItColors.length; + return postItColors[colorIndex]; +} + function createPost(t) { const post = document.createElement("div"); post.className = "post"; post.style.transform = `rotate(${getRandomRotation()}deg)`; - post.style.backgroundColor = getRandomPostItColor(); + post.style.backgroundColor = getPostItColorByDate(t.createdAt); // --- Shrink-then-grow hover effect --- post.addEventListener('mouseenter', function () {