From 831de267c5c10e4277e23d9981b8a1c5ccdf2bd7 Mon Sep 17 00:00:00 2001 From: patricksnape Date: Wed, 6 Feb 2013 13:35:26 +0000 Subject: [PATCH] Fixes issue #235 by adding an onerror function This could also help by allowing other image hosting site extensions to leverage the onerror function --- lib/reddit_enhancement_suite.user.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/reddit_enhancement_suite.user.js b/lib/reddit_enhancement_suite.user.js index aafcd9faae..27c5eff92f 100644 --- a/lib/reddit_enhancement_suite.user.js +++ b/lib/reddit_enhancement_suite.user.js @@ -9255,6 +9255,7 @@ modules['showImages'] = { var thisSrc = (imageLink.type == 'IMAGE_SCRAPE') ? imageLink.getAttribute('scraped_src') : imageLink.src; $(imageAnchor).html(''); var image = imageAnchor.querySelector('IMG'); + image.onerror = imageLink.onerror; if ('credits' in imageLink) { var credits = document.createElement('div'); @@ -9825,6 +9826,13 @@ modules['showImages'] = { if (RESUtils.pageType() == 'linklist') { $(elem).closest('.thing').find('.thumbnail').attr('href',elem.href); } + elem.onerror = function() { + if (this.src.match(/\.jpg/)) { + this.src = this.src.slice(0, elem.src.length - 3) + 'png'; + } else if (this.src.match(/\.png/)) { + this.src = this.src.slice(0, elem.src.length - 3) + 'gif'; + } + } modules['showImages'].createImageExpando(elem); } },