Skip to content

Instantly share code, notes, and snippets.

@gre
Created March 25, 2011 10:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gre/886668 to your computer and use it in GitHub Desktop.
Save gre/886668 to your computer and use it in GitHub Desktop.
Proof Of Concept : JS code to grayscale any web page
(function(){
var svg = document.createElement('div'), body = document.getElementsByTagName('body')[0];
if(/(msie) ([\w.]+)/.exec(navigator.userAgent)) {
body.style.filter = 'progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)';
return;
}
svg.innerHTML = '<svg version="1.1" baseProfile="full" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ev="http://www.w3.org/2001/xml-events"><clipPath id="c1" clipPathUnits="objectBoundingBox"><rect x="0" y="0" rx="0.05" ry="0.05" width="1" height="1"/></clipPath><filter id="desaturate"><feColorMatrix type="matrix" values="0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0"/></filter></svg>';
body.appendChild(svg);
body.style.filter = 'url(#desaturate)';
}())
@gre
Copy link
Author

gre commented Mar 25, 2011

It seems that some webkit based browser don't support inline svg ... So this script only works on FF and IE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment