Skip to content

Commit c56320f

Browse files
Create themes.js
1 parent b6bdfda commit c56320f

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

themes.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
window.colorThemes = [];
2+
const htmlStyles = getComputedStyle(document.documentElement);
3+
const targetStylesheet = document.querySelector(".page_code_color style");
4+
const regex = /--([^:\s]+):\s*var\(--([^)]+)\);/g;
5+
window.colorThemes.push({});
6+
7+
if (targetStylesheet) {
8+
const rules = targetStylesheet.sheet.cssRules || targetStylesheet.sheet.rules;
9+
for (const rule of rules) {
10+
if (rule.cssText.includes("data-theme=") && !rule.cssText.includes(`data-theme="inherit"`)) {
11+
const styleObject = {};
12+
let match;
13+
while ((match = regex.exec(rule.cssText)) !== null) {
14+
const key = "--" + match[1];
15+
const value = htmlStyles.getPropertyValue("--" + match[2]);
16+
styleObject[key] = value;
17+
}
18+
window.colorThemes.push(styleObject);
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)