diff --git a/4chan_x.user.js b/4chan_x.user.js index 47adb40c3..d7668f557 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -3293,7 +3293,7 @@ return $.add(a, img); }, error: function() { - var href, req, src, thumb, url; + var href, src, thumb, timeoutID, url; href = this.parentNode.href; thumb = this.previousSibling; imgExpand.contract(thumb); @@ -3302,20 +3302,16 @@ setTimeout(imgExpand.expand, 10000, thumb, url); return; } + if (g.dead) return; url = href + '?' + Date.now(); - if (engine === 'webkit') { - return req = $.ajax(this.src, { - onreadystatechange: (function() { - if (this.status !== 404) { - return setTimeout(imgExpand.expand, 10000, thumb, url); - } - }) - }, { - type: 'head' - }); - } else if (!g.dead) { - return setTimeout(imgExpand.expand, 10000, thumb, url); - } + timeoutID = setTimeout(imgExpand.expand, 10000, thumb, url); + return $.ajax(this.src, { + onreadystatechange: (function() { + if (this.status === 404) return clearTimeout(timeoutID); + }) + }, { + type: 'head' + }); }, dialog: function() { var controls, form, imageType, select; diff --git a/script.coffee b/script.coffee index da29e8477..a8232f7ff 100644 --- a/script.coffee +++ b/script.coffee @@ -2512,15 +2512,14 @@ imgExpand = if @src.split('/')[2] is 'images.4chan.org' and url = redirect.image src[3], src[5] setTimeout imgExpand.expand, 10000, thumb, url return + return if g.dead + # CloudFlare may cache banned pages instead of images. + # This will fool CloudFlare's cache. url = href + '?' + Date.now() #navigator.online is not x-browser/os yet - if engine is 'webkit' - req = $.ajax @src, onreadystatechange: (-> setTimeout imgExpand.expand, 10000, thumb, url if @status isnt 404), - type: 'head' - #Firefox returns a status code of 0 because of the same origin policy - #Oprah doesn't send any request - else unless g.dead - setTimeout imgExpand.expand, 10000, thumb, url + timeoutID = setTimeout imgExpand.expand, 10000, thumb, url + $.ajax @src, onreadystatechange: (-> clearTimeout timeoutID if @status is 404), + type: 'head' dialog: -> controls = $.el 'div',