Created
May 18, 2024 18:30
-
-
Save Traineratwot/cfd30f11709ea2bafa8d5d1b10461af3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getAllCSSVariables() { | |
const cssVariables = {}; | |
const sheets = document.styleSheets; | |
for (let i = 0; i < sheets.length; i++) { | |
const rules = sheets[i].cssRules || sheets[i].rules; | |
for (let j = 0; j < rules.length; j++) { | |
const rule = rules[j]; | |
if (rule.style) { | |
for (let k = 0; k < rule.style.length; k++) { | |
const property = rule.style[k]; | |
if (property.startsWith('--')) { | |
cssVariables[property] = rule.style.getPropertyValue(property).trim(); | |
} | |
} | |
} | |
} | |
} | |
return cssVariables; | |
} | |
// Вызов функции и вывод результата в консоль | |
const cssVariables = getAllCSSVariables(); | |
console.log(cssVariables); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment