Skip to content

Instantly share code, notes, and snippets.

@frnkst
Created January 15, 2020 21:45
Show Gist options
  • Save frnkst/5e807ce7154dded771bf9c490b4383c5 to your computer and use it in GitHub Desktop.
Save frnkst/5e807ce7154dded771bf9c490b4383c5 to your computer and use it in GitHub Desktop.
# ccsjson from https://github.com/aramk/CSSJSON
# file index.html
<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css" />
<script src="cssjson.js"></script>
<script>
const xhr = new XMLHttpRequest();
xhr.open("GET", "style.css", true);
xhr.onload = function(e) {
if (xhr.readyState === 4 && xhr.status == 200) {
const styleSheetRaw = xhr.responseText;
console.log(styleSheetRaw);
const styleSheet = CSSJSON.toJSON(styleSheetRaw);
console.log(styleSheet);
} else {
console.error(xhr.statusText);
}
};
xhr.onerror = function(e) {
console.error(xhr.statusText);
};
xhr.send();
</script>
</head>
<div class="title">
Title
</div>
</html>
# file style.css
.title {
color: blue;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment