3 ms·
I took yours and lukegb's a bit further - thanks for the inspiration. Probably overkill, though :-P var removeImageByHash = function() { var bad =
by someone13 13y ago
I took yours and lukegb's a bit further - thanks for the inspiration. Probably overkill, though :-P
var removeImageByHash = function() {
var bad = [525994816];
var canvas = document.createElement('canvas');
var ctx = canvas.getContext("2d");
var imgs = document.querySelectorAll('img');
for( var idx = 0; idx < imgs.length; idx++ ) {
var el = imgs[idx];
canvas.width = el.width;
canvas.height = el.height;
ctx.drawImage(el, 0, 0, el.width, el.height);
var hash = 0;
for( var i = 0; i < el.width; i++ ) {
for( var j = 0; j < el.height; j++ ) {
var pixel = ctx.getImageData(1, 1, 1, 1);
hash = ((hash << 5) - hash) + pixel.data[0];
hash |= 0;
hash = ((hash << 5) - hash) + pixel.data[1];
hash |= 0;
hash = ((hash << 5) - hash) + pixel.data[2];
hash |= 0;
}
}
var found = false;
for( var i = 0; i < bad.length; i++ ) {
if( bad[i] === hash ) {
found = true;
break;
}
}
if( found ) {
var hidden = document.createElement('div');
hidden.style.display = 'none';
hidden.style.width = 0;
hidden.style.height = 0;
document.body.appendChild(hidden);
hidden.appendChild(el.parentNode.removeChild(el));
}
console.log(idx + ": " + hash);
}
};