Skip to content

Instantly share code, notes, and snippets.

@loleg
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loleg/b58bd9749e8f8c79e77f to your computer and use it in GitHub Desktop.
Save loleg/b58bd9749e8f8c79e77f to your computer and use it in GitHub Desktop.
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