Skip to content

Instantly share code, notes, and snippets.

@Traineratwot
Created May 18, 2024 18:30
Show Gist options
  • Save Traineratwot/cfd30f11709ea2bafa8d5d1b10461af3 to your computer and use it in GitHub Desktop.
Save Traineratwot/cfd30f11709ea2bafa8d5d1b10461af3 to your computer and use it in GitHub Desktop.
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