Skip to content

Instantly share code, notes, and snippets.

@hitode909
Created April 13, 2009 07:29
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 hitode909/94324 to your computer and use it in GitHub Desktop.
Save hitode909/94324 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name replaceimage
// @namespace http://d.hatena.ne.jp/hitode909/
// @description replace all images.
// @include *
// ==/UserScript==
while(e = document.images[0]){
e.parentNode.insertBefore(newsvg(e), e)
e.parentNode.removeChild(e);
}
function newsvg(e){
if(!e) return;
var kSVGNS = 'http://www.w3.org/2000/svg';
var svg = document.createElementNS(kSVGNS, "svg:svg");
svg.setAttribute("xmlns",kSVGNS);
svg.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink")
svg.setAttribute("width", e.width);
svg.setAttribute("height", e.height);
// defs, filter
var defs = document.createElementNS(kSVGNS, 'svg:defs');
var filter = document.createElementNS(kSVGNS, 'svg:filter');
filter.setAttribute('id', 'falsecolor');
feComponentTransfer = document.createElementNS(kSVGNS, 'svg:feComponentTransfer');
var feFuncR = document.createElementNS(kSVGNS, 'svg:feFuncR');
feFuncR.setAttribute('type', 'gamma');
feFuncR.setAttribute('amplitude', '-1');
feFuncR.setAttribute('exponent', '0.35');
feFuncR.setAttribute('offset', '1');
feComponentTransfer.appendChild(feFuncR);
var feFuncG = document.createElementNS(kSVGNS, 'svg:feFuncG');
feFuncG.setAttribute('type', 'gamma');
feFuncG.setAttribute('amplitude', '-1');
feFuncG.setAttribute('exponent', '0.35');
feFuncG.setAttribute('offset', '1');
feComponentTransfer.appendChild(feFuncG);
var feFuncB = document.createElementNS(kSVGNS, 'svg:feFuncB');
feFuncB.setAttribute('type', 'gamma');
feFuncB.setAttribute('amplitude', '-1');
feFuncB.setAttribute('exponent', '0.35');
feFuncB.setAttribute('offset', '1');
feComponentTransfer.appendChild(feFuncB);
filter.appendChild(feComponentTransfer);
defs.appendChild(filter);
svg.appendChild(defs);
// image
var image = document.createElementNS(kSVGNS, 'svg:image');
image.setAttribute("x", "0");
image.setAttribute("y", "0");
image.setAttribute('width', e.width);
image.setAttribute('height', e.height);
image.setAttribute("xlink:href", e.src);
image.setAttribute("filter", "url(#falsecolor)");
svg.appendChild(image);
// rect
var rect = document.createElementNS("http://www.w3.org/2000/svg", "svg:rect");
rect.setAttribute("x", "0");
rect.setAttribute("y", "0");
rect.setAttribute("width", e.width);
rect.setAttribute("height", e.height);
rect.setAttribute("fill", "red");
// rect.setAttribute("filter", "url(#falsecolor)");
svg.appendChild(rect);
return svg;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment