Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 5540db425c
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 36 lines (28 sloc) 0.99 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
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.