Skip to content

Commit 4c33720

Browse files
committed
add toggle colors
1 parent 0c97fac commit 4c33720

2 files changed

Lines changed: 24 additions & 23 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ You can provide fewer values; missing values will be padded by repeating the las
9595
Example (Blue Palette):
9696

9797
```md
98-
![](https://leetcard.jacoblin.cool/jacoblincool?colors=012a4a,013a63,a9d6e5,ffffff,0077b6,0096c7,00b4d8,90e0ef)
98+
![](https://leetcard.jacoblin.cool/JacobLinCool?theme=light&font=Noto%20Serif%20Kannada&colors=%231e1e2e%2C%2345475a%2C%23cdd6f4%2C%23bac2de%2C%23fab387%2C%23a6e3a1%2C%23f9e2af%2C%23f38ba8)
9999
```
100100

101101
When both `theme` and `colors` are provided, `colors` takes precedence.

packages/cloudflare-worker/src/demo/demo.html

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -604,16 +604,6 @@ <h1>LeetCode Stats Card</h1>
604604
});
605605
}
606606

607-
function getColors() {
608-
const order = ["bg0", "bg1", "text0", "text1", "color0", "color1", "color2", "color3"];
609-
return order
610-
.map((key) => {
611-
const el = document.querySelector("#color-" + key);
612-
return el ? el.value.trim() : "";
613-
})
614-
.join(",");
615-
}
616-
617607
function toggleTheme() {
618608
document.body.classList.toggle("dark-mode");
619609
}
@@ -623,6 +613,21 @@ <h1>LeetCode Stats Card</h1>
623613
img.src = url() || img.src;
624614
}
625615

616+
function getColors() {
617+
const order = ["bg0", "bg1", "text0", "text1", "color0", "color1", "color2", "color3"];
618+
return order
619+
.map((key) => {
620+
const el = document.querySelector("#color-" + key);
621+
if (!el) return "";
622+
let val = el.value.trim();
623+
624+
// Ensure we keep valid #, &, , but still make it URL-safe later
625+
// Replace commas inside color values to avoid splitting issues
626+
return val.replace(/,/g, "%2C");
627+
})
628+
.join(",");
629+
}
630+
626631
function url() {
627632
if (!value("username")) {
628633
return "";
@@ -632,18 +637,14 @@ <h1>LeetCode Stats Card</h1>
632637
const useCustomColors = useCustomColorsEl ? useCustomColorsEl.checked : false;
633638
const colors = useCustomColors ? getColors() : "";
634639

635-
return (
636-
location.origin +
637-
"/" +
638-
encodeURIComponent(value("username")) +
639-
"?theme=" +
640-
encodeURIComponent(value("theme")) +
641-
"&font=" +
642-
encodeURIComponent(value("font")) +
643-
(useCustomColors && colors ? "&colors=" + encodeURIComponent(colors) : "") +
644-
(value("extension") ? "&ext=" + encodeURIComponent(value("extension")) : "") +
645-
(value("site") === "cn" ? "&site=cn" : "")
646-
);
640+
const params = new URLSearchParams();
641+
params.set("theme", value("theme"));
642+
params.set("font", value("font"));
643+
if (useCustomColors && colors) params.set("colors", colors);
644+
if (value("extension")) params.set("ext", value("extension"));
645+
if (value("site") === "cn") params.set("site", "cn");
646+
647+
return `${location.origin}/${encodeURIComponent(value("username"))}?${params.toString()}`;
647648
}
648649

649650
function go() {

0 commit comments

Comments
 (0)