Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 js
Octocat-spinner-32 README
README
A tiny little script that swaps itself with a <style> node containing whatever
was inside the <script> tag.

For example:
<head>
....
<script src="script2style.js">
    .hide { display: none !important; }
</script>
</head>

becomes
<head>
....
<style type="text/css">
    .hide { display: none !important; }
</style>
</head>

if JavaScript is enabled.

Content inside of <script> tags is ignored when a src attribute is present, but
it is stored in the element's innerHTML property.

There are two versions of the script:
1. script2style.js does a straight <script> => <style> conversion
2. script2style+.js also extracts @imports from the content and generates <link> tags from them.

File sizes are:
script2style.js   253B (382B uncompressed)
script2style+.js  497B (972B uncompressed)

It looks a little dubious, or confusing even, to see <script...> containing CSS
in your markup, but it works.  It may not be the best solution out there, just
something I came up with one night. YMMV.
Something went wrong with that request. Please try again.