Skip to content

Commit 6002a5b

Browse files
authored
Add profile views counter; clean up JS (NextCommunity#274)
1 parent c149b22 commit 6002a5b

File tree

2 files changed

+70
-26
lines changed

2 files changed

+70
-26
lines changed

src/_includes/header.njk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<p class="hidden md:flex text-[var(--text-muted)] text-[9px] font-mono uppercase tracking-[0.3em] mt-1 items-center gap-2">
2626
{% if page.url == "/" %}
2727
<span class="w-1.5 h-1.5 rounded-full bg-green-500 animate-pulse"></span>
28-
Global Talent Directory
28+
<span class="header-gtd">Global Talent Directory</span>
2929
{% else %}
3030
Viewing Profile Details
3131
{% endif %}

src/assets/js/script.js

Lines changed: 69 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -491,9 +491,6 @@ function initDotEasterEgg() {
491491
};
492492
}
493493

494-
// Call the function once the DOM is ready
495-
document.addEventListener("DOMContentLoaded", initDotEasterEgg);
496-
497494
const konamiCode = [
498495
"arrowup",
499496
"arrowup",
@@ -859,23 +856,6 @@ window.toggleScreenshotMode = function () {
859856
}, 5000);
860857
};
861858

862-
/**
863-
* 8. INITIALIZATION
864-
*/
865-
document.addEventListener("DOMContentLoaded", () => {
866-
const devToolsVisible = localStorage.getItem("devToolsVisible") === "true";
867-
const devPanel = document.getElementById("dev-tools");
868-
// Add this to your initialization script
869-
let skillHoverCount = 0;
870-
871-
if (devToolsVisible && devPanel) {
872-
devPanel.classList.remove("hidden");
873-
}
874-
875-
applyTheme(localStorage.getItem("theme") || "light");
876-
updateGameUI();
877-
});
878-
879859
/**
880860
* 9. ENHANCED XP & SKILL MINING SYSTEM
881861
*/
@@ -1051,8 +1031,50 @@ function initSkillMining() {
10511031
});
10521032
}
10531033

1054-
// Run this on page load
1055-
document.addEventListener("DOMContentLoaded", initSkillMining);
1034+
/**
1035+
* Tracks profile views via localStorage and updates the header.
1036+
* Displays current view count and the associated level from the LEVELS array.
1037+
*/
1038+
function initProfileTracker() {
1039+
// 1. Target the specific span class from your template
1040+
const headerSpan = document.querySelector(".header-gtd");
1041+
if (!headerSpan) return;
1042+
1043+
// 2. Create the counter element
1044+
// Using a wrapper to ensure it sits nicely under the span
1045+
const statsContainer = document.createElement("div");
1046+
statsContainer.id = "profile-stats-display";
1047+
statsContainer.style.cssText =
1048+
"font-size: 0.7rem; font-weight: normal; margin-top: 2px; opacity: 0.8; display: block;";
1049+
1050+
// Append it right after the span or inside the parent container
1051+
headerSpan.parentElement.appendChild(statsContainer);
1052+
1053+
// 3. UI Update Logic
1054+
const refreshStats = () => {
1055+
const count = parseInt(localStorage.getItem("profile_view_count") || 0);
1056+
statsContainer.innerHTML = `
1057+
<span style="letter-spacing: 1px;">VIEWS: ${count}</span>
1058+
`;
1059+
};
1060+
1061+
// Initial render
1062+
refreshStats();
1063+
1064+
// 4. Listen for clicks on any "Profile" links
1065+
document.addEventListener("click", (e) => {
1066+
const targetLink = e.target.closest("a");
1067+
1068+
// Only increment if the link text contains "Profile"
1069+
if (targetLink && targetLink.textContent.includes("Profile")) {
1070+
let currentCount = parseInt(
1071+
localStorage.getItem("profile_view_count") || 0,
1072+
);
1073+
localStorage.setItem("profile_view_count", currentCount + 1);
1074+
refreshStats();
1075+
}
1076+
});
1077+
}
10561078

10571079
function initSkillXP() {
10581080
const skills = document.querySelectorAll(".skill-item");
@@ -1078,9 +1100,6 @@ function initSkillXP() {
10781100
});
10791101
}
10801102

1081-
// Re-initialize skills after Surprise scroll or any DOM changes
1082-
window.addEventListener("DOMContentLoaded", initSkillXP);
1083-
10841103
/**
10851104
* SYS ADMIN XP (Level 6 Mechanic)
10861105
*/
@@ -1125,3 +1144,28 @@ function jumpToLevel() {
11251144
triggerForceSurge();
11261145
}
11271146
}
1147+
1148+
// Re-initialize skills after Surprise scroll or any DOM changes
1149+
window.addEventListener("DOMContentLoaded", initSkillXP);
1150+
1151+
/**
1152+
* INITIALIZATION
1153+
*/
1154+
document.addEventListener("DOMContentLoaded", () => {
1155+
const devToolsVisible = localStorage.getItem("devToolsVisible") === "true";
1156+
const devPanel = document.getElementById("dev-tools");
1157+
// Add this to your initialization script
1158+
let skillHoverCount = 0;
1159+
1160+
if (devToolsVisible && devPanel) {
1161+
devPanel.classList.remove("hidden");
1162+
}
1163+
1164+
initDotEasterEgg();
1165+
initSkillMining();
1166+
// Initialize the profile counter
1167+
initProfileTracker();
1168+
1169+
applyTheme(localStorage.getItem("theme") || "light");
1170+
updateGameUI();
1171+
});

0 commit comments

Comments
 (0)