NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript==
// @name Pixelator (by Pixelate.js)
// @description Pixelates all images on page
// @copyright 2016, Rustam Second_Fry Gubaydullin (http://twitter.com/second_fry)
// @license MIT; https://github.com/secondfry/license/raw/master/LICENSE
// @homepageURL https://github.com/secondfry/pixelate.js
// @author Rustam @Second_Fry Gubaydullin
// @author SecondFry
// @version 0.1
// @include *
// @grant none
// ==/UserScript==
/* jshint -W097 */
'use strict';
function ready(fn) {
if (document.readyState != 'loading'){
fn();
} else {
document.addEventListener('DOMContentLoaded', fn);
}
}
function loadPixelateJS(callback) {
var pixelate_js = document.createElement('script');
pixelate_js.src = 'https://secondfry.github.io/pixelate.js/pixelate.min.js';
pixelate_js.onreadystatechange = callback;
pixelate_js.onload = callback;
document.body.appendChild(pixelate_js);
}
function pixelateImages(images) {
if(images) {
images.forEach(function(image){
if(image.complete) {
image.src = image.src + '?' + new Date().getTime();
}
image.addEventListener('load', function(e) {
this.pixelate({value: 0.25, reveal_on_hover: true});
})
})
}
}
ready(function(){
loadPixelateJS(function(){
pixelateImages(document.querySelectorAll('img'));
document.addEventListener('DOMNodeInserted', function(e) {
if(e.target && e.target.querySelectorAll) {
pixelateImages(e.target.querySelectorAll('img'));
}
})
})
});