diff --git a/4chan_x.user.js b/4chan_x.user.js index 8a274de2f..6c29c7cc0 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -3308,7 +3308,7 @@ var thumb, _i, _j, _len, _len2, _ref, _ref2, _results, _results2; imgExpand.on = this.checked; if (imgExpand.on) { - _ref = $$('.op > a > img[md5]:last-child, table:not([hidden]) img[md5]:last-child'); + _ref = $$('img[md5]'); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { thumb = _ref[_i]; @@ -3364,11 +3364,16 @@ }, contract: function(thumb) { thumb.hidden = false; - return $.rm(thumb.nextSibling); + return thumb.nextSibling.hidden = true; }, expand: function(thumb, url) { var a, filesize, img, max; - if (thumb.hidden) return; + if ($.x('ancestor-or-self::*[@hidden]', thumb)) return; + thumb.hidden = true; + if (img = thumb.nextSibling) { + img.hidden = false; + return; + } a = thumb.parentNode; img = $.el('img', { src: url || a.href @@ -3379,7 +3384,6 @@ img.style.maxWidth = "" + max[1] + "px"; } if (conf['404 Redirect']) $.on(img, 'error', imgExpand.error); - thumb.hidden = true; return $.add(a, img); }, error: function() { @@ -3388,6 +3392,7 @@ thumb = this.previousSibling; src = href.split('/'); imgExpand.contract(thumb); + $.rm(this); if (!(this.src.split('/')[2] === 'images.4chan.org' && (url = redirect.image(src[3], src[5])))) { if (g.dead) return; url = href + '?' + Date.now(); diff --git a/script.coffee b/script.coffee index bf592066b..b751e1a17 100644 --- a/script.coffee +++ b/script.coffee @@ -2541,7 +2541,7 @@ imgExpand = all: -> imgExpand.on = @checked if imgExpand.on #expand - for thumb in $$ '.op > a > img[md5]:last-child, table:not([hidden]) img[md5]:last-child' + for thumb in $$ 'img[md5]' imgExpand.expand thumb else #contract for thumb in $$ 'img[md5][hidden]' @@ -2577,10 +2577,16 @@ imgExpand = contract: (thumb) -> thumb.hidden = false - $.rm thumb.nextSibling + thumb.nextSibling.hidden = true expand: (thumb, url) -> - return if thumb.hidden + # Do not expand images of hidden/filtered replies, or already expanded pictures. + return if $.x 'ancestor-or-self::*[@hidden]', thumb + thumb.hidden = true + if img = thumb.nextSibling + # Expand already loaded picture + img.hidden = false + return a = thumb.parentNode img = $.el 'img', src: url or a.href @@ -2589,7 +2595,6 @@ imgExpand = max = filesize.match /(\d+)x/ img.style.maxWidth = "#{max[1]}px" $.on img, 'error', imgExpand.error if conf['404 Redirect'] - thumb.hidden = true $.add a, img error: -> @@ -2597,6 +2602,7 @@ imgExpand = thumb = @previousSibling src = href.split '/' imgExpand.contract thumb + $.rm @ unless @src.split('/')[2] is 'images.4chan.org' and url = redirect.image src[3], src[5] return if g.dead # CloudFlare may cache banned pages instead of images.