Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions frontend/js/leaderboard/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,36 @@ document.addEventListener("click", (e) => {
.querySelectorAll(".mobile-score.active")
.forEach((el) => el.classList.remove("active"));
});
// Creates a rank change DOM element (safe — values are internally generated)

function createRankChangeElement(rankChange) {
if (!rankChange) return null;
if (rankChange === "=") {
return null;
}
var span = document.createElement("span");
span.className = "rank-change";
if (rankChange === "NEW") {
span.classList.add("rank-neutral");
span.textContent = "[new]";
} else if (rankChange === "=") {
span.classList.add("rank-neutral");
span.textContent = "[==]";
span.setAttribute("data-tooltip", "Newly added to the leaderboard");
} else if (rankChange.startsWith("+")) {
span.classList.add("rank-up");
span.textContent = "[" + rankChange + "]";
var placesUp = rankChange.replace("+", "");
span.setAttribute(
"data-tooltip",
"Rank increased by " + placesUp + " places today",
);
} else {
span.classList.add("rank-down");
span.textContent = "[" + rankChange + "]";
var placesDown = rankChange.replace("-", "");
span.setAttribute(
"data-tooltip",
"Rank dropped by " + placesDown + " places today",
);
}

return span;
}

Expand Down
40 changes: 40 additions & 0 deletions frontend/styles/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -2819,6 +2819,46 @@ body::-webkit-scrollbar-thumb {
display: none;
}

.rank-change {
position: relative;
cursor: help;
display: inline-block;
user-select: none;
font-family: "Fira Code", monospace;
font-weight: 600;
margin-left: 4px;
}
.rank-change[data-tooltip]::before {
content: attr(data-tooltip);
position: absolute;
bottom: 140%;
left: 50%;
transform: translateX(-50%);
background: var(--bg-raised);
color: var(--text);
border: 1px solid var(--green);
padding: 6px 12px;
font-family: "Fira Code", monospace;
font-size: 0.75rem;
line-height: 1.4;
white-space: nowrap;
border-radius: 4px;
z-index: 99999;
opacity: 0;
pointer-events: none;
transition: opacity 0.15s ease-in-out;
box-shadow: 0 0 15px rgba(0, 255, 65, 0.2);
}
.rank-change[data-tooltip]:hover::before {
opacity: 1;
}
@media (max-width: 480px) {
.rank-change[data-tooltip]::before {
bottom: auto;
top: 140%;
}
}

/* ==========================================================================
LeetCode Leaderboard Peer Comparison Module
========================================================================== */
Expand Down
Loading