From 078db94ee819027e4522034116da0e72bde4992f Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Mon, 30 Jan 2012 20:42:30 +0100 Subject: [PATCH] Refactoring masturbation. --- 4chan_x.user.js | 12 +++++------- script.coffee | 18 ++++++++---------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 990efc2ab..bd4141a52 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -3312,16 +3312,14 @@ var href, src, thumb, timeoutID, url; href = this.parentNode.href; thumb = this.previousSibling; - imgExpand.contract(thumb); src = href.split('/'); - if (this.src.split('/')[2] === 'images.4chan.org' && (url = redirect.image(src[3], src[5]))) { - setTimeout(imgExpand.expand, 10000, thumb, url); - return; + imgExpand.contract(thumb); + if (!(this.src.split('/')[2] === 'images.4chan.org' && (url = redirect.image(src[3], src[5])))) { + if (g.dead) return; + url = href + '?' + Date.now(); } - if (g.dead) return; - url = href + '?' + Date.now(); timeoutID = setTimeout(imgExpand.expand, 10000, thumb, url); - return $.ajax(this.src, { + return $.ajax(url, { onreadystatechange: (function() { if (this.status === 404) return clearTimeout(timeoutID); }) diff --git a/script.coffee b/script.coffee index 1f02c0736..f7211ad63 100644 --- a/script.coffee +++ b/script.coffee @@ -2537,20 +2537,18 @@ imgExpand = $.add a, img error: -> - href = @parentNode.href + href = @parentNode.href thumb = @previousSibling + src = href.split '/' imgExpand.contract thumb - src = href.split '/' - 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() + 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. + # This will fool CloudFlare's cache. + url = href + '?' + Date.now() #navigator.online is not x-browser/os yet timeoutID = setTimeout imgExpand.expand, 10000, thumb, url - $.ajax @src, onreadystatechange: (-> clearTimeout timeoutID if @status is 404), + $.ajax url, onreadystatechange: (-> clearTimeout timeoutID if @status is 404), type: 'head' dialog: ->