Skip to content

Commit 06f1b54

Browse files
authored
Merge pull request #298 from teamEPYC/Murtaza-TC1-patch-5
Update dark-mode.js
2 parents 7c92b9d + f406b4c commit 06f1b54

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

dark-mode.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,27 @@ function colorModeToggle() {
2828
}
2929

3030
let darkColors = {};
31+
3132
cssVariables.split(",").forEach(function (item) {
32-
let lightValue = computed.getPropertyValue(`--color--${item}`);
33-
let darkValue = computed.getPropertyValue(`--dark--${item}`);
33+
// Clean up the variable name - remove "var(" and ")" and trim whitespace
34+
let cleanedItem = item
35+
.trim()
36+
.replace(/^var\(/, "")
37+
.replace(/\)$/, "");
38+
39+
// Extract the variable name (e.g., "--polygon-v3---color--primary")
40+
let lightVarName = cleanedItem;
41+
42+
// Create dark variable name by replacing "--color--" with "--dark--"
43+
// Adjust this based on your actual CSS variable naming convention
44+
let darkVarName = cleanedItem.replace("---color--", "---dark--");
45+
46+
let lightValue = computed.getPropertyValue(lightVarName);
47+
let darkValue = computed.getPropertyValue(darkVarName);
48+
3449
if (lightValue.length) {
3550
if (!darkValue.length) darkValue = lightValue;
36-
darkColors[`--color--${item}`] = darkValue;
51+
darkColors[lightVarName] = darkValue;
3752
}
3853
});
3954

@@ -62,10 +77,9 @@ function colorModeToggle() {
6277
setColors(darkColors, false);
6378
}
6479

65-
// Force dark mode immediately - ignore user preferences
80+
// Force dark mode immediately
6681
forceDarkMode();
6782

68-
// Also ensure dark mode is set after DOM is fully loaded
6983
window.addEventListener("DOMContentLoaded", (event) => {
7084
forceDarkMode();
7185
});

0 commit comments

Comments
 (0)