Skip to content

Instantly share code, notes, and snippets.

@FlandreDaisuki
Last active August 29, 2015 14:23
Show Gist options
  • Save FlandreDaisuki/d99baac96396140d1765 to your computer and use it in GitHub Desktop.
Save FlandreDaisuki/d99baac96396140d1765 to your computer and use it in GitHub Desktop.
paste on console and 🌈
function repImg( tar ) {
var div = document.createElement( 'div' );
div.style.height = tar.height + 'px';
div.style.width = tar.width + 'px';
div.style.display = 'inline-block';
div.style.backgroundColor = 'transparent';
// http://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser
var isFirefox = typeof InstallTrigger !== 'undefined';
var isChrome = !!window.chrome && !isOpera;
var isOpera = !!window.opera || navigator.userAgent.indexOf( ' OPR/' ) >= 0;
var gradient;
// https://developer.mozilla.org/en-US/docs/Web/CSS/linear-gradient
if ( isChrome ) {
gradient = "-webkit-linear-gradient(top, #FE6648, #FEB144, #FEE142, #4AFE92, #43C2FD, #8D50FE)";
} else if ( isFirefox ) {
gradient = "-moz-linear-gradient(top, #FE6648, #FEB144, #FEE142, #4AFE92, #43C2FD, #8D50FE)";
} else if ( isOpera ) {
gradient = "-o-linear-gradient(top, #FE6648, #FEB144, #FEE142, #4AFE92, #43C2FD, #8D50FE)";
} else {
gradient = "linear-gradient(top, #FE6648, #FEB144, #FEE142, #4AFE92, #43C2FD, #8D50FE)";
}
div.style.backgroundImage = 'url("' + tar.src + '"), ' + gradient;
div.style.backgroundBlendMode = 'multiply';
div.style.backgroundSize = '100%';
tar.parentNode.insertBefore( div, tar.nextSibling );
tar.style.display = 'none';
}
function replaceAll() {
var imgs = document.querySelectorAll( 'img' );
[].forEach.call( imgs, ( function ( img ) {
if ( !img.classList.contains( 'rainbow' ) ) {
repImg( img );
img.classList.add( 'rainbow' );
}
} ) );
}
var registerObserver = function () { // thanks dannvix
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
var throttle = ( function () {
var timer_;
return function ( fn, wait ) {
if ( timer_ ) {
clearTimeout( timer_ );
}
timer_ = setTimeout( fn, wait );
};
} )();
var target = document;
var config = {
attributes: true,
childList: true,
characterData: true,
subtree: true,
};
var mutationObserver = new MutationObserver( function ( mutations ) {
var hasNewNode = false;
mutations.forEach( function ( mutation, idx ) {
if ( mutation.type == 'childList' && mutation.addedNodes.length > 0 )
hasNewNode = true;
} );
if ( hasNewNode ) {
throttle( function () {
replaceAll();
}, 500 );
}
} );
mutationObserver.observe( target, config );
};
registerObserver();
function repImg( tar ) {
var div = document.createElement( 'div' );
div.style.height = tar.height + 'px';
div.style.width = tar.width + 'px';
div.style.display = 'inline-block';
div.style.backgroundColor = 'transparent';
div.style.backgroundImage = 'url("' + tar.src + '"), url("http://www.csie.ntnu.edu.tw/~4024s/img/rainbow.png")';
div.style.backgroundRepeat = 'no-repeat, no-repeat';
div.style.backgroundPosition = ' 0% 0%, 0% 0%';
div.style.backgroundSize = '100%, 100%';
div.style.backgroundBlendMode = 'multiply';
tar.parentNode.insertBefore( div, tar.nextSibling );
tar.style.display = 'none';
}
function replaceAll() {
var imgs = document.querySelectorAll( 'img' );
[].forEach.call( imgs, ( function ( img ) {
if ( !img.classList.contains( 'rainbow' ) ) {
repImg( img );
img.classList.add( 'rainbow' );
}
} ) );
}
var registerObserver = function () { // thanks dannvix
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
var throttle = ( function () {
var timer_;
return function ( fn, wait ) {
if ( timer_ ) {
clearTimeout( timer_ );
}
timer_ = setTimeout( fn, wait );
};
} )();
var target = document;
var config = {
attributes: true,
childList: true,
characterData: true,
subtree: true,
};
var mutationObserver = new MutationObserver( function ( mutations ) {
var hasNewNode = false;
mutations.forEach( function ( mutation, idx ) {
if ( mutation.type == 'childList' && mutation.addedNodes.length > 0 )
hasNewNode = true;
} );
if ( hasNewNode ) {
throttle( function () {
replaceAll();
}, 500 );
}
} );
mutationObserver.observe( target, config );
};
registerObserver();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment