Skip to content

Instantly share code, notes, and snippets.

@negipo
Created April 19, 2010 05:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save negipo/370772 to your computer and use it in GitHub Desktop.
Save negipo/370772 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name hitodenize
// @namespace http://polog.org/
// @include http://*
// @require http://gist.github.com/3242.txt
// ==/UserScript==
// using $X http://gist.github.com/3242 by os0x
// http://d.hatena.ne.jp/hitode909/20100418/1271583701
function init(doc){
$X('.//img | .//embed | ./object', doc).forEach(function(img){
svg_filter(img);
});
}
// http://d.hatena.ne.jp/javascripter/20090319/1237449590 by id:javascripter
var isAppended = false;
function svg_filter(element) {
if (!isAppended) {
document.documentElement.appendChild(
E4XToDOM(
<svg:svg xmlns:svg="http://www.w3.org/2000/svg" height="0">
<svg:defs>
<svg:filter id="reverse_filter">
<svg:feColorMatrix type="matrix" values="-1 0 0 0 1 0 -1 0 0 1 0 0 -1 0 1 0 0 0 1 0"/>
</svg:filter>
</svg:defs>
</svg:svg>
)
);
isAppended = true;
}
element.style.cssText += 'filter: url("#reverse_filter");';
}
function E4XToDOM(xml) {
return document.adoptNode(
new DOMParser().parseFromString(xml.toXMLString(), "application/xml").documentElement
);
}
init(document);
if(window.AutoPagerize)
window.AutoPagerize.addFilter(function(docs){
docs.forEach(function(doc){
init(doc);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment