From 79b0c85d72baa22ece5ad586f4582a85ff7a466a Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Thu, 22 Sep 2011 20:25:19 +0200 Subject: [PATCH 1/8] Set to retry after one second unless the thread 404'd. --- 4chan_x.user.js | 4 +++- script.coffee | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index b77c3c370..4882c635c 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2732,7 +2732,9 @@ $.bind(img, 'error', function(e) { thumb = this.previousSibling; imgExpand.contract(thumb); - return imgExpand.expand(thumb); + if (!g.dead) { + return setTimeout(imgExpand.expand, 1000, thumb); + } }); return $.add(a, img); }, diff --git a/script.coffee b/script.coffee index 6802230f7..c97cbe807 100644 --- a/script.coffee +++ b/script.coffee @@ -2025,7 +2025,8 @@ imgExpand = $.bind img, 'error', (e) -> thumb = @previousSibling imgExpand.contract thumb - imgExpand.expand thumb + unless g.dead + setTimeout imgExpand.expand, 1000, thumb $.add a, img dialog: -> From 3333bfe4884b3e4e538abadf7a7552b3e7117611 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Thu, 22 Sep 2011 20:26:26 +0200 Subject: [PATCH 2/8] Hide at the end. --- 4chan_x.user.js | 2 +- script.coffee | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 4882c635c..99a352ee3 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2719,7 +2719,6 @@ }, expand: function(thumb) { var a, filesize, img, max, _, _ref; - thumb.hidden = true; a = thumb.parentNode; img = $.el('img', { src: a.href @@ -2736,6 +2735,7 @@ return setTimeout(imgExpand.expand, 1000, thumb); } }); + thumb.hidden = true; return $.add(a, img); }, dialog: function() { diff --git a/script.coffee b/script.coffee index c97cbe807..b9b3b19f0 100644 --- a/script.coffee +++ b/script.coffee @@ -2014,7 +2014,6 @@ imgExpand = $.rm thumb.nextSibling expand: (thumb) -> - thumb.hidden = true a = thumb.parentNode img = $.el 'img', src: a.href @@ -2027,6 +2026,7 @@ imgExpand = imgExpand.contract thumb unless g.dead setTimeout imgExpand.expand, 1000, thumb + thumb.hidden = true $.add a, img dialog: -> From 62f697cca6db160322569ba88d82a6544b12edc3 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Fri, 23 Sep 2011 01:34:18 +0200 Subject: [PATCH 3/8] Clean up, improve, retry arbitrarily every 10 seconds as to not shit up 4chan's servers even more. --- 4chan_x.user.js | 21 ++++++++++++++------- script.coffee | 15 ++++++++++----- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 99a352ee3..f2681f928 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2728,16 +2728,23 @@ _ref = filesize.textContent.match(/(\d+)x/), _ = _ref[0], max = _ref[1]; img.style.maxWidth = "-moz-calc(" + max + "px)"; } - $.bind(img, 'error', function(e) { - thumb = this.previousSibling; - imgExpand.contract(thumb); - if (!g.dead) { - return setTimeout(imgExpand.expand, 1000, thumb); - } - }); + $.bind(img, 'error', imgExpand.error); thumb.hidden = true; return $.add(a, img); }, + error: function(e) { + var thumb; + thumb = this.previousSibling; + imgExpand.contract(thumb); + if (!g.dead) { + return setTimeout(imgExpand.retry, 10000, thumb); + } + }, + retry: function(thumb) { + if (!(g.dead || thumb.hidden)) { + return imgExpand.expand(thumb); + } + }, dialog: function() { var controls, delform, imageType, option, select, _i, _len, _ref; controls = $.el('div', { diff --git a/script.coffee b/script.coffee index b9b3b19f0..6723e9c35 100644 --- a/script.coffee +++ b/script.coffee @@ -2021,14 +2021,19 @@ imgExpand = filesize = $ 'span.filesize', a.parentNode [_, max] = filesize.textContent.match /(\d+)x/ img.style.maxWidth = "-moz-calc(#{max}px)" - $.bind img, 'error', (e) -> - thumb = @previousSibling - imgExpand.contract thumb - unless g.dead - setTimeout imgExpand.expand, 1000, thumb + $.bind img, 'error', imgExpand.error thumb.hidden = true $.add a, img + error: (e) -> + thumb = @previousSibling + imgExpand.contract thumb + #navigator.online is not x-browser/os yet + #can't easily check if the image/post is deleted + setTimeout imgExpand.retry, 10000, thumb unless g.dead + retry: (thumb) -> + imgExpand.expand thumb unless g.dead or thumb.hidden + dialog: -> controls = $.el 'div', id: 'imgControls' From a112ba332bbee65f306831f59090360cde198aa9 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Fri, 23 Sep 2011 16:29:09 +0200 Subject: [PATCH 4/8] Shorter selector --- 4chan_x.user.js | 2 +- script.coffee | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index f2681f928..f29f41906 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2769,7 +2769,7 @@ return $.prepend(delform, controls); }, resize: function(e) { - return imgExpand.style.innerHTML = "body.fitheight img[md5] + img { max-height: " + d.body.clientHeight + "px }"; + return imgExpand.style.innerHTML = ".fitheight img[md5] + img {max-height:" + d.body.clientHeight + "px;}"; } }; firstRun = { diff --git a/script.coffee b/script.coffee index 6723e9c35..192a7f29d 100644 --- a/script.coffee +++ b/script.coffee @@ -2055,7 +2055,7 @@ imgExpand = $.prepend delform, controls resize: (e) -> - imgExpand.style.innerHTML = "body.fitheight img[md5] + img { max-height: #{d.body.clientHeight}px }" + imgExpand.style.innerHTML = ".fitheight img[md5] + img {max-height:#{d.body.clientHeight}px;}" firstRun = init: -> From c14bd0a84c88e61e808e61e27ac6fadc801d8f15 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Fri, 23 Sep 2011 16:44:32 +0200 Subject: [PATCH 5/8] Use CSS instead of JS, bitches love CSS. --- 4chan_x.user.js | 17 +++++++++-------- script.coffee | 11 ++++------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index f29f41906..62653deeb 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2667,21 +2667,22 @@ return imgExpand.toggle(this); }, all: function(e) { - var thumb, thumbs, _i, _j, _len, _len2, _results, _results2; - thumbs = $$('img[md5]'); + var thumb, _i, _j, _len, _len2, _ref, _ref2, _results, _results2; imgExpand.on = this.checked; if (imgExpand.on) { + _ref = $$('img[md5]:not([hidden])'); _results = []; - for (_i = 0, _len = thumbs.length; _i < _len; _i++) { - thumb = thumbs[_i]; - _results.push(!thumb.hidden ? imgExpand.expand(thumb) : void 0); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + thumb = _ref[_i]; + _results.push(imgExpand.expand(thumb)); } return _results; } else { + _ref2 = $$('img[md5][hidden]'); _results2 = []; - for (_j = 0, _len2 = thumbs.length; _j < _len2; _j++) { - thumb = thumbs[_j]; - _results2.push(thumb.hidden ? imgExpand.contract(thumb) : void 0); + for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) { + thumb = _ref2[_j]; + _results2.push(imgExpand.contract(thumb)); } return _results2; } diff --git a/script.coffee b/script.coffee index 192a7f29d..a30796844 100644 --- a/script.coffee +++ b/script.coffee @@ -1980,16 +1980,13 @@ imgExpand = e.preventDefault() imgExpand.toggle @ all: (e) -> - thumbs = $$ 'img[md5]' imgExpand.on = @checked if imgExpand.on #expand - for thumb in thumbs - unless thumb.hidden #thumbnail hidden, image already expanded - imgExpand.expand thumb + for thumb in $$ 'img[md5]:not([hidden])' + imgExpand.expand thumb else #contract - for thumb in thumbs - if thumb.hidden #thumbnail hidden - unhide it - imgExpand.contract thumb + for thumb in $$ 'img[md5][hidden]' + imgExpand.contract thumb typeChange: (e) -> switch @value when 'full' From 691f8c69d41b8c4b97ff75581767e30f05971b92 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Fri, 23 Sep 2011 16:50:11 +0200 Subject: [PATCH 6/8] Expand, don't go through toggle. --- 4chan_x.user.js | 2 +- script.coffee | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 62653deeb..26a1e433d 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2655,7 +2655,7 @@ a = thumb.parentNode; $.bind(a, 'click', imgExpand.cb.toggle); if (imgExpand.on && root.className !== 'inline') { - return imgExpand.toggle(a); + return imgExpand.expand(a.firstChild); } }, cb: { diff --git a/script.coffee b/script.coffee index a30796844..c1615a1c4 100644 --- a/script.coffee +++ b/script.coffee @@ -1973,7 +1973,7 @@ imgExpand = return unless thumb = $ 'img[md5]', root a = thumb.parentNode $.bind a, 'click', imgExpand.cb.toggle - if imgExpand.on and root.className isnt 'inline' then imgExpand.toggle a + if imgExpand.on and root.className isnt 'inline' then imgExpand.expand a.firstChild cb: toggle: (e) -> return if e.shiftKey or e.altKey or e.ctrlKey or e.button isnt 0 From e319beae48618f1f4613118c045a767e38284aa8 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Sat, 24 Sep 2011 13:34:35 +0200 Subject: [PATCH 7/8] Update /sci/ archive redirection, close #294 --- 4chan_x.user.js | 2 +- changelog | 1 + script.coffee | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 26a1e433d..bc754d053 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2537,10 +2537,10 @@ var url; switch (g.BOARD) { case 'g': + case 'sci': url = "http://archive.installgentoo.net/cgi-board.pl/" + g.BOARD + "/thread/" + g.THREAD_ID; break; case 'lit': - case 'sci': case 'tv': url = "http://archive.gentoomen.org/cgi-board.pl/" + g.BOARD + "/thread/" + g.THREAD_ID; break; diff --git a/changelog b/changelog index 9ddeeb680..f6a862e9a 100644 --- a/changelog +++ b/changelog @@ -2,6 +2,7 @@ master - mayhem initiate 4chan X earlier automatically reload expanded pictures on error + update /sci/ archive redirection 2.20.1 - mayhem diff --git a/script.coffee b/script.coffee index c1615a1c4..66b26cfae 100644 --- a/script.coffee +++ b/script.coffee @@ -1915,9 +1915,9 @@ Favicon = redirect = -> switch g.BOARD - when 'g' + when 'g', 'sci' url = "http://archive.installgentoo.net/cgi-board.pl/#{g.BOARD}/thread/#{g.THREAD_ID}" - when 'lit', 'sci', 'tv' + when 'lit', 'tv' url = "http://archive.gentoomen.org/cgi-board.pl/#{g.BOARD}/thread/#{g.THREAD_ID}" when 'a', 'jp', 'm', 'tg' url = "http://archive.easymodo.net/#{g.BOARD}/thread/#{g.THREAD_ID}" From fe45fcb4f04bec0ca484805cc63de5854f3d8b55 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Sat, 24 Sep 2011 15:56:52 +0200 Subject: [PATCH 8/8] Retry if and only if we're sure the picture 404'd. --- 4chan_x.user.js | 13 ++++++++----- script.coffee | 6 +++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index bc754d053..c33e9a5a9 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2734,15 +2734,18 @@ return $.add(a, img); }, error: function(e) { - var thumb; + var req, thumb; thumb = this.previousSibling; imgExpand.contract(thumb); - if (!g.dead) { - return setTimeout(imgExpand.retry, 10000, thumb); - } + req = $.ajax(this.src, null, 'head'); + return req.onreadystatechange = function(e) { + if (this.status !== 404) { + return setTimeout(imgExpand.retry, 10000, thumb); + } + }; }, retry: function(thumb) { - if (!(g.dead || thumb.hidden)) { + if (!thumb.hidden) { return imgExpand.expand(thumb); } }, diff --git a/script.coffee b/script.coffee index 66b26cfae..fd975629e 100644 --- a/script.coffee +++ b/script.coffee @@ -2026,10 +2026,10 @@ imgExpand = thumb = @previousSibling imgExpand.contract thumb #navigator.online is not x-browser/os yet - #can't easily check if the image/post is deleted - setTimeout imgExpand.retry, 10000, thumb unless g.dead + req = $.ajax @src, null, 'head' + req.onreadystatechange = (e) -> setTimeout imgExpand.retry, 10000, thumb if @status isnt 404 retry: (thumb) -> - imgExpand.expand thumb unless g.dead or thumb.hidden + imgExpand.expand thumb unless thumb.hidden dialog: -> controls = $.el 'div',