Last active
August 29, 2015 14:21
-
-
Save loleg/b58bd9749e8f8c79e77f to your computer and use it in GitHub Desktop.
Script to replace cropped animations with originals in Newscoop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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