From 152d1c475f406478bfa51cbd5eac823e4974364e Mon Sep 17 00:00:00 2001 From: creations Date: Fri, 30 May 2025 20:14:45 -0400 Subject: [PATCH 1/6] add timezone 12h kv, add tooltops for badges --- README.md | 1 + public/js/index.js | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index b4a85fd..79598cd 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,7 @@ These can be defined in Lanyard's KV store to customize the page: | `optout` | Allows users to stop sharing there profile on the website (`true` / `false`) | | `reviews` | Enables reviews from reviewdb (`true` / `false`) | | `timezone`| Enables the showing of the current time from the timezone db API (`true` / `false`) | +| `timezone_12` | Sets the timezone to default show 12h format, default is 24h | --- diff --git a/public/js/index.js b/public/js/index.js index aaba9d6..3ef1d93 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -11,6 +11,7 @@ let socket; let badgesLoaded = false; let readmeLoaded = false; let cssLoaded = false; +let timezoneLoaded = false; const reviewsPerPage = 50; let currentReviewOffset = 0; @@ -210,8 +211,8 @@ async function populateReviews(userId) { } } -function populateTimezone(userId) { - if (!userId || !timezoneApiUrl) return; +function populateTimezone(userId, format = "24h") { + if (!userId || !timezoneApiUrl || timezoneLoaded) return; let currentTimezone = null; @@ -233,7 +234,8 @@ function populateTimezone(userId) { } function updateTime() { - if (!currentTimezone) return; + if (!currentTimezone || timezoneLoaded) return; + timezoneLoaded = true; const timezoneEl = document.querySelector(".timezone-value"); if (!timezoneEl) return; @@ -256,8 +258,10 @@ function populateTimezone(userId) { second: "2-digit", }); - timezoneEl.textContent = time24; - timezoneEl.title = `${time12} (${currentTimezone})`; + timezoneEl.textContent = format === "24h" ? time24 : time12; + timezoneEl.title = `${format === "12h" ? time24 : time12} (${currentTimezone})`; + + timezoneEl.classList.remove("hidden"); } fetchTimezone(); @@ -468,6 +472,7 @@ async function loadBadges(userId, options = {}) { img.src = badge.badge; img.alt = badge.tooltip; img.title = badge.tooltip; + img.tooltip = badge.tooltip; img.className = "badge"; target.appendChild(img); } @@ -649,11 +654,7 @@ async function updatePresence(initialData) { } if (kv.timezone !== "false" && userId && timezoneApiUrl) { - populateTimezone(userId); - const timezoneEl = document.querySelector(".timezone-value"); - if (timezoneEl) { - timezoneEl.classList.remove("hidden"); - } + populateTimezone(userId, kv.timezone_12 === "true" ? "12h" : "24h"); } const platform = { From 9ca877602f77b0249649f03bec826a88b9516d42 Mon Sep 17 00:00:00 2001 From: creations Date: Sat, 31 May 2025 10:56:44 -0400 Subject: [PATCH 2/6] fix two simple bugs with reviews and timezone showing even if they dont exist --- public/js/index.js | 11 +++++++---- src/views/index.html | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/public/js/index.js b/public/js/index.js index 3ef1d93..a232fec 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -132,7 +132,7 @@ function resolveActivityImage(img, applicationId) { async function populateReviews(userId) { if (!reviewURL || !userId || isLoadingReviews || !hasMoreReviews) return; - const reviewSection = document.querySelector(".reviews"); + const reviewSection = document.getElementById("reviews-section"); const reviewList = reviewSection?.querySelector(".reviews-list"); if (!reviewList) return; @@ -201,7 +201,9 @@ async function populateReviews(userId) { if (currentReviewOffset === 0) reviewList.innerHTML = reviewsHTML; else reviewList.insertAdjacentHTML("beforeend", reviewsHTML); - reviewSection.classList.remove("hidden"); + if (data.reviews.length > 0 && reviewsHTML) { + reviewSection.classList.remove("hidden"); + } hasMoreReviews = data.hasNextPage; isLoadingReviews = false; @@ -238,7 +240,8 @@ function populateTimezone(userId, format = "24h") { timezoneLoaded = true; const timezoneEl = document.querySelector(".timezone-value"); - if (!timezoneEl) return; + const timezoneWrapper = document.getElementById("timezone-wrapper"); + if (!timezoneEl || !timezoneWrapper) return; const now = new Date(); @@ -261,7 +264,7 @@ function populateTimezone(userId, format = "24h") { timezoneEl.textContent = format === "24h" ? time24 : time12; timezoneEl.title = `${format === "12h" ? time24 : time12} (${currentTimezone})`; - timezoneEl.classList.remove("hidden"); + timezoneWrapper.classList.remove("hidden"); } fetchTimezone(); diff --git a/src/views/index.html b/src/views/index.html index 1c4884f..5f71625 100644 --- a/src/views/index.html +++ b/src/views/index.html @@ -27,7 +27,7 @@ style="opacity: 0.5" loading="lazy" /> -
+ @@ -61,7 +61,7 @@ -