From 5c8c7be4babedf7c08e1982e2622e8747665c1cc Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Wed, 29 Feb 2012 18:54:23 +0100 Subject: [PATCH] Replace auto-GIF thumbnails once the GIF has finished loading. --- 4chan_x.user.js | 10 ++++++++-- script.coffee | 6 +++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index ff58e1446..4bdf446de 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -3556,10 +3556,16 @@ return g.callbacks.push(this.node); }, node: function(root) { - var src, thumb; + var img, src, thumb; if (root.hidden || !(thumb = $('img[md5]', root))) return; src = thumb.parentNode.href; - if (/gif$/.test(src) && !/spoiler/.test(src)) return thumb.src = src; + if (/gif$/.test(src) && !/spoiler/.test(src)) { + img = $.el('img'); + $.on(img, 'load', function() { + return thumb.src = src; + }); + return img.src = src; + } } }; diff --git a/script.coffee b/script.coffee index 2326e0175..92c6ca415 100644 --- a/script.coffee +++ b/script.coffee @@ -2862,7 +2862,11 @@ imgGif = return if root.hidden or !thumb = $ 'img[md5]', root src = thumb.parentNode.href if /gif$/.test(src) and !/spoiler/.test src - thumb.src = src + img = $.el 'img' + $.on img, 'load', -> + # Replace the thumbnail once the GIF has finished loading. + thumb.src = src + img.src = src imgExpand = init: ->