Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script to replace cropped animations with originals in Newscoop
// Encapsulate script code
(function($) {
// Select all images in 'ad' articles
$("a.section-ad.layoutbgimage, article.ad img.image-link").each(function() {
asBgImage = typeof $(this).attr('src') === "undefined";
// Obtain current url(..) path to the image
u = asBgImage ? this.style.backgroundImage : this.src;
// Apply additional criteria to ensure target crop format
if (u.indexOf('/cache/')<0 || u.indexOf('.gif')<0) return;
// Use a regular expression to trim the crop path out
re = /cache\/[0-9]+x[0-9]+\/(crop[_0-9]*|fit)\/+images%7C/
v = u.replace(re, '');
// For debugging, output the result
//console.log(v);
// Set the new path to the original image
if (asBgImage) {
this.style.backgroundImage = v;
} else {
this.src = v;
}
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.