-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy paththemes.js
More file actions
21 lines (20 loc) · 787 Bytes
/
themes.js
File metadata and controls
21 lines (20 loc) · 787 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
window.colorThemes = [];
const htmlStyles = getComputedStyle(document.documentElement);
const targetStylesheet = document.querySelector(".page_code_color style");
const regex = /--([^:\s]+):\s*var\(--([^)]+)\);/g;
window.colorThemes.push({});
if (targetStylesheet) {
const rules = targetStylesheet.sheet.cssRules || targetStylesheet.sheet.rules;
for (const rule of rules) {
if (rule.cssText.includes("data-theme=") && !rule.cssText.includes(`data-theme="inherit"`)) {
const styleObject = {};
let match;
while ((match = regex.exec(rule.cssText)) !== null) {
const key = "--" + match[1];
const value = htmlStyles.getPropertyValue("--" + match[2]);
styleObject[key] = value;
}
window.colorThemes.push(styleObject);
}
}
}