Created
March 25, 2011 10:37
-
-
Save gre/886668 to your computer and use it in GitHub Desktop.
Proof Of Concept : JS code to grayscale any web page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)'; | |
}()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It seems that some webkit based browser don't support inline svg ... So this script only works on FF and IE.