Skip to content

Instantly share code, notes, and snippets.

@0mg
Created January 13, 2010 05:41
Show Gist options
  • Save 0mg/275965 to your computer and use it in GitHub Desktop.
Save 0mg/275965 to your computer and use it in GitHub Desktop.
js: モザイク
javascript:(function(c,z,Z,m,s){
c = function(e,r,c){
r = function(){ return (Math.random()*256^0) };
c = function(c){ return ( "rgb(" + (c = r()) + "," + c + "," + c + ")") };
e.style.backgroundColor = e.style.color = c();
};
z = function(E,e,i,t,j,S,s){
for( e = E.childNodes, i = 0; i < e.length; i++){
if(
( e[i].nodeType == 3 || e[i].nodeType == 4 )
&& /\S/.test(e[i].nodeValue)
){
S = document.createElement("span");
for( t = e[i].nodeValue, j = 0; j < t.length; j++ ){
s = document.createElement("span");
s.className = m;
c(s);
s.appendChild(
document.createTextNode(t.charAt(j))
);
S.appendChild(s);
}
E.replaceChild(S, e[i]);
}
else{
if( !/^script/i.test(e[i].tagName) ) arguments.callee(e[i]);
}
}
};
Z = function(S,t,i){
while( 0 < s.length ){
S = s[0].parentNode;
t = "";
for( i = 0; i < S.childNodes.length; i++){
t += S.childNodes[i].firstChild.nodeValue;
}
S.parentNode.replaceChild( document.createTextNode(t), S );
}
};
m = "char";
s = document.getElementsByClassName(m);
s.length == 0 ? z(document.body): Z();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment