From 25276b5aac2bc197b3a7dba34f7a4540f62d0da9 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Thu, 19 Jan 2012 22:04:27 +0100 Subject: [PATCH] Fool the browser cache and CloudFlare's cache when trying to reload a picture from 4chan. --- 4chan_x.user.js | 22 ++++++++++++---------- script.coffee | 16 +++++++++------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index bda3e90f8..697732903 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -3005,9 +3005,10 @@ }, expand: function(thumb, url) { var a, filesize, img, max; + if (thumb.hidden) return; a = thumb.parentNode; img = $.el('img', { - src: url ? url : a.href + src: url || a.href }); if (engine === 'gecko' && a.parentNode.className !== 'op') { filesize = $.x('preceding-sibling::span[@class="filesize"]', a).textContent; @@ -3019,28 +3020,29 @@ return $.add(a, img); }, error: function() { - var req, src, thumb, url; + var href, req, src, thumb, url; + href = this.parentNode.href; thumb = this.previousSibling; imgExpand.contract(thumb); - src = this.src.split('/'); + src = href.split('/'); if (src[2] === 'images.4chan.org' && (url = redirect.image(src[3], src[5]))) { - return setTimeout(imgExpand.expand, 10000, thumb, url); - } else if (engine === 'webkit') { + setTimeout(imgExpand.expand, 10000, thumb, url); + return; + } + url = href + '?' + Date.now(); + if (engine === 'webkit') { return req = $.ajax(this.src, (function() { if (this.status !== 404) { - return setTimeout(imgExpand.retry, 10000, thumb); + return setTimeout(imgExpand.expand, 10000, thumb, url); } }), { type: 'head', event: 'onreadystatechange' }); } else if (!g.dead) { - return setTimeout(imgExpand.retry, 10000, thumb); + return setTimeout(imgExpand.expand, 10000, thumb, url); } }, - retry: function(thumb) { - if (!thumb.hidden) return imgExpand.expand(thumb); - }, dialog: function() { var controls, form, imageType, select; controls = $.el('div', { diff --git a/script.coffee b/script.coffee index 1def04236..3eaf57b90 100644 --- a/script.coffee +++ b/script.coffee @@ -2325,9 +2325,10 @@ imgExpand = $.rm thumb.nextSibling expand: (thumb, url) -> + return if thumb.hidden a = thumb.parentNode img = $.el 'img', - src: if url then url else a.href + src: url or a.href if engine is 'gecko' and a.parentNode.className isnt 'op' filesize = $.x('preceding-sibling::span[@class="filesize"]', a).textContent max = filesize.match /(\d+)x/ @@ -2337,22 +2338,23 @@ imgExpand = $.add a, img error: -> + href = @parentNode.href thumb = @previousSibling imgExpand.contract thumb - src = @src.split '/' + src = href.split '/' if src[2] is 'images.4chan.org' and url = redirect.image src[3], src[5] setTimeout imgExpand.expand, 10000, thumb, url + return + url = href + '?' + Date.now() #navigator.online is not x-browser/os yet - else if engine is 'webkit' + if engine is 'webkit' req = $.ajax @src, (-> - setTimeout imgExpand.retry, 10000, thumb if @status isnt 404 + setTimeout imgExpand.expand, 10000, thumb, url if @status isnt 404 ), type: 'head', event: 'onreadystatechange' #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.retry, 10000, thumb - retry: (thumb) -> - imgExpand.expand thumb unless thumb.hidden + setTimeout imgExpand.expand, 10000, thumb, url dialog: -> controls = $.el 'div',