From 2a1f482e66d0c1325fc03fb69ebb1a1eb7f72dd2 Mon Sep 17 00:00:00 2001 From: ahodesuka Date: Tue, 17 Jan 2012 23:39:38 -0600 Subject: [PATCH 01/22] Fix scroll offset when contracting images --- 4chan_x.user.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 6f59cf6ff..71db82528 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2960,7 +2960,7 @@ _results2 = []; for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) { thumb = _ref2[_j]; - _results2.push(imgExpand.contract(thumb)); + _results2.push(imgExpand.contract(thumb, false)); } return _results2; } @@ -2994,13 +2994,23 @@ var thumb; thumb = a.firstChild; if (thumb.hidden) { - return imgExpand.contract(thumb); + return imgExpand.contract(thumb, true); } else { return imgExpand.expand(thumb); } }, - contract: function(thumb) { + contract: function(thumb, bScroll) { thumb.hidden = false; + if (bScroll) { + var el, top; + el = thumb.parentNode.parentNode; + top = el.offsetTop; + while (el.offsetParent) { + el = el.offsetParent; + top += el.offsetTop; + } + if (top < window.scrollY) window.scroll(window.scrollX, top); + } return $.rm(thumb.nextSibling); }, expand: function(thumb, url) { @@ -3021,7 +3031,7 @@ error: function() { var req, src, thumb, url; thumb = this.previousSibling; - imgExpand.contract(thumb); + imgExpand.contract(thumb, true); src = this.src.split('/'); if (url = redirect.image(src[3], src[5])) { return imgExpand.expand(thumb, url); From 7a2343f6c53674cdb70f6ce0e443a1b2f946bd6a Mon Sep 17 00:00:00 2001 From: ahodesuka Date: Wed, 18 Jan 2012 16:16:01 -0600 Subject: [PATCH 02/22] Changed offset fix for only images that are larger than the viewport --- 4chan_x.user.js | 28 +++++++++++++--------------- script.coffee | 6 ++++++ 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 71db82528..8a990db59 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2960,7 +2960,7 @@ _results2 = []; for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) { thumb = _ref2[_j]; - _results2.push(imgExpand.contract(thumb, false)); + _results2.push(imgExpand.contract(thumb)); } return _results2; } @@ -2991,26 +2991,24 @@ } }, toggle: function(a) { - var thumb; + var el, thumb, top; thumb = a.firstChild; if (thumb.hidden) { - return imgExpand.contract(thumb, true); + if (thumb.nextSibling.offsetHeight > window.innerHeight) { + el = thumb.nextSibling; + top = el.offsetTop; + while (el = el.offsetParent) { + top += el.offsetTop; + } + if (top < window.scrollY) window.scroll(window.scrollX, top); + } + return imgExpand.contract(thumb); } else { return imgExpand.expand(thumb); } }, - contract: function(thumb, bScroll) { + contract: function(thumb) { thumb.hidden = false; - if (bScroll) { - var el, top; - el = thumb.parentNode.parentNode; - top = el.offsetTop; - while (el.offsetParent) { - el = el.offsetParent; - top += el.offsetTop; - } - if (top < window.scrollY) window.scroll(window.scrollX, top); - } return $.rm(thumb.nextSibling); }, expand: function(thumb, url) { @@ -3031,7 +3029,7 @@ error: function() { var req, src, thumb, url; thumb = this.previousSibling; - imgExpand.contract(thumb, true); + imgExpand.contract(thumb); src = this.src.split('/'); if (url = redirect.image(src[3], src[5])) { return imgExpand.expand(thumb, url); diff --git a/script.coffee b/script.coffee index 0b00eb3bd..7f789239c 100644 --- a/script.coffee +++ b/script.coffee @@ -2316,6 +2316,12 @@ imgExpand = toggle: (a) -> thumb = a.firstChild if thumb.hidden + if thumb.nextSibling.offsetHeight > window.innerHeight + el = thumb.nextSibling + top = el.offsetTop + while el = el.offsetParent + top += el.offsetTop + window.scroll window.scrollX, top if top < window.scrollY imgExpand.contract thumb else imgExpand.expand thumb From 9baddbc771269d3efc152d6aa4035572bd09c5f3 Mon Sep 17 00:00:00 2001 From: ahodesuka Date: Wed, 18 Jan 2012 19:09:37 -0600 Subject: [PATCH 03/22] Use getBoundingClientRect and body.clientHeight for offset fix --- 4chan_x.user.js | 11 +++-------- script.coffee | 8 ++------ 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 8a990db59..e49f56285 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2991,16 +2991,11 @@ } }, toggle: function(a) { - var el, thumb, top; + var thumb, top; thumb = a.firstChild; if (thumb.hidden) { - if (thumb.nextSibling.offsetHeight > window.innerHeight) { - el = thumb.nextSibling; - top = el.offsetTop; - while (el = el.offsetParent) { - top += el.offsetTop; - } - if (top < window.scrollY) window.scroll(window.scrollX, top); + if (thumb.nextSibling.offsetHeight > d.body.clientHeight && (top = a.getBoundingClientRect().top) < 0) { + window.scroll(window.scrollX, window.scrollY + top); } return imgExpand.contract(thumb); } else { diff --git a/script.coffee b/script.coffee index 7f789239c..d4c4aabae 100644 --- a/script.coffee +++ b/script.coffee @@ -2316,12 +2316,8 @@ imgExpand = toggle: (a) -> thumb = a.firstChild if thumb.hidden - if thumb.nextSibling.offsetHeight > window.innerHeight - el = thumb.nextSibling - top = el.offsetTop - while el = el.offsetParent - top += el.offsetTop - window.scroll window.scrollX, top if top < window.scrollY + if thumb.nextSibling.offsetHeight > d.body.clientHeight and (top = a.getBoundingClientRect().top) < 0 + window.scroll window.scrollX, window.scrollY + top imgExpand.contract thumb else imgExpand.expand thumb From 3d1de50d152f6604cdb6a80032298804e4003efd Mon Sep 17 00:00:00 2001 From: ahodesuka Date: Wed, 18 Jan 2012 21:00:54 -0600 Subject: [PATCH 04/22] Scroll to the same position on the thumbnail as was being viewed before contracting --- script.coffee | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/script.coffee b/script.coffee index d4c4aabae..b21c55485 100644 --- a/script.coffee +++ b/script.coffee @@ -2316,8 +2316,9 @@ imgExpand = toggle: (a) -> thumb = a.firstChild if thumb.hidden - if thumb.nextSibling.offsetHeight > d.body.clientHeight and (top = a.getBoundingClientRect().top) < 0 - window.scroll window.scrollX, window.scrollY + top + rect = a.getBoundingClientRect() + d.body.scrollTop += if rect.top < 0 then rect.top + thumb.height / (rect.height / rect.top * -1) else 0 + d.body.scrollLeft += if rect.left < 0 then rect.left + thumb.width / (rect.width / rect.left * -1) else 0 imgExpand.contract thumb else imgExpand.expand thumb From 791c3fcd789b7cee1338abe18797efa42d989967 Mon Sep 17 00:00:00 2001 From: ahodesuka Date: Wed, 18 Jan 2012 21:01:44 -0600 Subject: [PATCH 05/22] Build --- 4chan_x.user.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index e49f56285..053ea029c 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2991,12 +2991,12 @@ } }, toggle: function(a) { - var thumb, top; + var rect, thumb; thumb = a.firstChild; if (thumb.hidden) { - if (thumb.nextSibling.offsetHeight > d.body.clientHeight && (top = a.getBoundingClientRect().top) < 0) { - window.scroll(window.scrollX, window.scrollY + top); - } + rect = a.getBoundingClientRect(); + d.body.scrollTop += rect.top < 0 ? rect.top + thumb.height / (rect.height / rect.top * -1) : 0; + d.body.scrollLeft += rect.left < 0 ? rect.left + thumb.width / (rect.width / rect.left * -1) : 0; return imgExpand.contract(thumb); } else { return imgExpand.expand(thumb); From 8f29d8eac9421bf26fc1ce127b783760ecaeb2a8 Mon Sep 17 00:00:00 2001 From: ahodesuka Date: Wed, 18 Jan 2012 22:55:16 -0600 Subject: [PATCH 06/22] Replace ternary operator with simple if --- 4chan_x.user.js | 8 ++++++-- script.coffee | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 053ea029c..fa37d7b68 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2995,8 +2995,12 @@ thumb = a.firstChild; if (thumb.hidden) { rect = a.getBoundingClientRect(); - d.body.scrollTop += rect.top < 0 ? rect.top + thumb.height / (rect.height / rect.top * -1) : 0; - d.body.scrollLeft += rect.left < 0 ? rect.left + thumb.width / (rect.width / rect.left * -1) : 0; + if (rect.top < 0) { + d.body.scrollTop += rect.top + thumb.height / (rect.height / rect.top * -1); + } + if (rect.left < 0) { + d.body.scrollLeft += rect.left + thumb.width / (rect.width / rect.left * -1); + } return imgExpand.contract(thumb); } else { return imgExpand.expand(thumb); diff --git a/script.coffee b/script.coffee index b21c55485..25be94ca4 100644 --- a/script.coffee +++ b/script.coffee @@ -2317,8 +2317,8 @@ imgExpand = thumb = a.firstChild if thumb.hidden rect = a.getBoundingClientRect() - d.body.scrollTop += if rect.top < 0 then rect.top + thumb.height / (rect.height / rect.top * -1) else 0 - d.body.scrollLeft += if rect.left < 0 then rect.left + thumb.width / (rect.width / rect.left * -1) else 0 + d.body.scrollTop += rect.top + thumb.height / (rect.height / rect.top * -1) if rect.top < 0 + d.body.scrollLeft += rect.left + thumb.width / (rect.width / rect.left * -1) if rect.left < 0 imgExpand.contract thumb else imgExpand.expand thumb From efc557cb1dd6fa3d9fad97bf50c316e441d0759e Mon Sep 17 00:00:00 2001 From: ahodesuka Date: Thu, 19 Jan 2012 10:15:07 -0600 Subject: [PATCH 07/22] Scroll to top of thumbnail when contracting expanded image --- 4chan_x.user.js | 8 ++------ script.coffee | 4 ++-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index fa37d7b68..cf7704076 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2995,12 +2995,8 @@ thumb = a.firstChild; if (thumb.hidden) { rect = a.getBoundingClientRect(); - if (rect.top < 0) { - d.body.scrollTop += rect.top + thumb.height / (rect.height / rect.top * -1); - } - if (rect.left < 0) { - d.body.scrollLeft += rect.left + thumb.width / (rect.width / rect.left * -1); - } + if (rect.top < 0) d.body.scrollTop += rect.top; + if (rect.left < 0) d.body.scrollLeft += rect.left; return imgExpand.contract(thumb); } else { return imgExpand.expand(thumb); diff --git a/script.coffee b/script.coffee index 25be94ca4..c5e22e0bf 100644 --- a/script.coffee +++ b/script.coffee @@ -2317,8 +2317,8 @@ imgExpand = thumb = a.firstChild if thumb.hidden rect = a.getBoundingClientRect() - d.body.scrollTop += rect.top + thumb.height / (rect.height / rect.top * -1) if rect.top < 0 - d.body.scrollLeft += rect.left + thumb.width / (rect.width / rect.left * -1) if rect.left < 0 + d.body.scrollTop += rect.top if rect.top < 0 + d.body.scrollLeft += rect.left if rect.left < 0 imgExpand.contract thumb else imgExpand.expand thumb From 0ccacc490fe33044c593d8a97a11f193adbaf9ac Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Thu, 19 Jan 2012 20:31:36 +0100 Subject: [PATCH 08/22] Do not try to reload the picture immediately from archivers; if it fails to load from archivers, try to load from 4chan again. --- 4chan_x.user.js | 4 ++-- script.coffee | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 6f59cf6ff..bda3e90f8 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -3023,8 +3023,8 @@ thumb = this.previousSibling; imgExpand.contract(thumb); src = this.src.split('/'); - if (url = redirect.image(src[3], src[5])) { - return imgExpand.expand(thumb, url); + if (src[2] === 'images.4chan.org' && (url = redirect.image(src[3], src[5]))) { + return setTimeout(imgExpand.expand, 10000, thumb, url); } else if (engine === 'webkit') { return req = $.ajax(this.src, (function() { if (this.status !== 404) { diff --git a/script.coffee b/script.coffee index 0b00eb3bd..1def04236 100644 --- a/script.coffee +++ b/script.coffee @@ -2340,8 +2340,8 @@ imgExpand = thumb = @previousSibling imgExpand.contract thumb src = @src.split '/' - if url = redirect.image src[3], src[5] - imgExpand.expand thumb, url + if src[2] is 'images.4chan.org' and url = redirect.image src[3], src[5] + setTimeout imgExpand.expand, 10000, thumb, url #navigator.online is not x-browser/os yet else if engine is 'webkit' req = $.ajax @src, (-> From 25276b5aac2bc197b3a7dba34f7a4540f62d0da9 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Thu, 19 Jan 2012 22:04:27 +0100 Subject: [PATCH 09/22] 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', From b49e110cc831fd13c591cb64aafcb813b65e618d Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Thu, 19 Jan 2012 22:21:36 +0100 Subject: [PATCH 10/22] Whoops. --- 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 697732903..390432caa 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -3025,7 +3025,7 @@ thumb = this.previousSibling; imgExpand.contract(thumb); src = href.split('/'); - if (src[2] === 'images.4chan.org' && (url = redirect.image(src[3], src[5]))) { + if (this.src.split('/')[2] === 'images.4chan.org' && (url = redirect.image(src[3], src[5]))) { setTimeout(imgExpand.expand, 10000, thumb, url); return; } diff --git a/script.coffee b/script.coffee index 3eaf57b90..8200e5902 100644 --- a/script.coffee +++ b/script.coffee @@ -2342,7 +2342,7 @@ imgExpand = thumb = @previousSibling imgExpand.contract thumb src = href.split '/' - if src[2] is 'images.4chan.org' and url = redirect.image src[3], src[5] + if @src.split('/')[2] is 'images.4chan.org' and url = redirect.image src[3], src[5] setTimeout imgExpand.expand, 10000, thumb, url return url = href + '?' + Date.now() From 36102e4927ac52283b2cb6d52c833e44f1aef91e Mon Sep 17 00:00:00 2001 From: seaweed Date: Thu, 19 Jan 2012 20:05:36 -0700 Subject: [PATCH 11/22] Bottom padding added to iHover --- script.coffee | 1 + 1 file changed, 1 insertion(+) diff --git a/script.coffee b/script.coffee index 8200e5902..1cd6ac8c1 100644 --- a/script.coffee +++ b/script.coffee @@ -2626,6 +2626,7 @@ Main = #ihover { max-height: 100%; max-width: 75%; + padding-bottom: 18px; } #navlinks { From 8cc25cd32ad3940dec8dfb69109b1024b6ccf0ca Mon Sep 17 00:00:00 2001 From: ahodesuka Date: Thu, 19 Jan 2012 21:20:41 -0600 Subject: [PATCH 12/22] Scroll to top of reply instead of anchor --- 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 cf7704076..f0619043f 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2994,7 +2994,7 @@ var rect, thumb; thumb = a.firstChild; if (thumb.hidden) { - rect = a.getBoundingClientRect(); + rect = a.parentNode.getBoundingClientRect(); if (rect.top < 0) d.body.scrollTop += rect.top; if (rect.left < 0) d.body.scrollLeft += rect.left; return imgExpand.contract(thumb); diff --git a/script.coffee b/script.coffee index c5e22e0bf..813abb1ed 100644 --- a/script.coffee +++ b/script.coffee @@ -2316,7 +2316,7 @@ imgExpand = toggle: (a) -> thumb = a.firstChild if thumb.hidden - rect = a.getBoundingClientRect() + rect = a.parentNode.getBoundingClientRect() d.body.scrollTop += rect.top if rect.top < 0 d.body.scrollLeft += rect.left if rect.left < 0 imgExpand.contract thumb From 6ba290514126871d9f8f1aa0cc188a9fce5d21ad Mon Sep 17 00:00:00 2001 From: e Date: Thu, 19 Jan 2012 23:34:19 -0500 Subject: [PATCH 13/22] Added cooldown sanity check -- properly. --- script.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script.coffee b/script.coffee index 0b00eb3bd..eb45abb37 100644 --- a/script.coffee +++ b/script.coffee @@ -1096,7 +1096,7 @@ cooldown = start: -> cooldown.duration = Math.ceil ($.get(g.BOARD+'/cooldown', 0) - Date.now()) / 1000 - return unless cooldown.duration > 0 + return unless 60 >= cooldown.duration > 0 for submit in $$ '#com_submit' submit.value = cooldown.duration submit.disabled = true From 8af14aee77705dec46cf7316718ba6d37c7977b1 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Fri, 20 Jan 2012 05:43:20 +0100 Subject: [PATCH 14/22] Update changelog and contributors; build. --- 4chan_x.user.js | 13 ++++++++----- Cakefile | 2 ++ changelog | 6 ++++++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index e25da3052..4ea5f2889 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -49,6 +49,8 @@ * * CONTRIBUTORS * + * e000 - cooldown sanity check + * ahokadesuka - scroll back when unexpanding images * Shou- - pentadactyl fixes * ferongr - new favicons * xat- - new favicons @@ -1455,12 +1457,12 @@ if (g.REPLY) return $('.postarea form').action += '?cooldown'; }, start: function() { - var submit, _i, _len, _ref; + var submit, _i, _len, _ref, _ref2; cooldown.duration = Math.ceil(($.get(g.BOARD + '/cooldown', 0) - Date.now()) / 1000); - if (!(cooldown.duration > 0)) return; - _ref = $$('#com_submit'); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - submit = _ref[_i]; + if (!((60 >= (_ref = cooldown.duration) && _ref > 0))) return; + _ref2 = $$('#com_submit'); + for (_i = 0, _len = _ref2.length; _i < _len; _i++) { + submit = _ref2[_i]; submit.value = cooldown.duration; submit.disabled = true; } @@ -3276,6 +3278,7 @@ #ihover {\ max-height: 100%;\ max-width: 75%;\ + padding-bottom: 18px;\ }\ \ #navlinks {\ diff --git a/Cakefile b/Cakefile index b95e2b2c5..905ebb561 100644 --- a/Cakefile +++ b/Cakefile @@ -56,6 +56,8 @@ HEADER = """ * * CONTRIBUTORS * + * e000 - cooldown sanity check + * ahokadesuka - scroll back when unexpanding images * Shou- - pentadactyl fixes * ferongr - new favicons * xat- - new favicons diff --git a/changelog b/changelog index 4af786053..0cccbf08a 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,10 @@ master +- ahokadesuka + Scroll back up when unexpanding images. +- e000 + Prevent absurd cooldown durations. +- Mayhem + Better image expanding reload, should fool CloudFlare's cache. 2.24.3 - Mayhem From 8c85a768cf792a274abc82e048810f145082d8c2 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Fri, 20 Jan 2012 05:46:08 +0100 Subject: [PATCH 15/22] Release 2.24.4. --- 4chan_x.user.js | 6 +++--- Cakefile | 2 +- changelog | 2 ++ latest.js | 2 +- script.coffee | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 4ea5f2889..83da74aae 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1,6 +1,6 @@ // ==UserScript== // @name 4chan x -// @version 2.24.3 +// @version 2.24.4 // @namespace aeosynth // @description Adds various features. // @copyright 2009-2011 James Campos @@ -18,7 +18,7 @@ * Copyright (c) 2009-2011 James Campos * Copyright (c) 2012 Nicolas Stepien * http://mayhemydg.github.com/4chan-x/ - * 4chan X 2.24.3 + * 4chan X 2.24.4 * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation @@ -202,7 +202,7 @@ NAMESPACE = '4chan_x.'; - VERSION = '2.24.3'; + VERSION = '2.24.4'; SECOND = 1000; diff --git a/Cakefile b/Cakefile index 905ebb561..0a2a0a0ea 100644 --- a/Cakefile +++ b/Cakefile @@ -2,7 +2,7 @@ {exec} = require 'child_process' fs = require 'fs' -VERSION = '2.24.3' +VERSION = '2.24.4' HEADER = """ // ==UserScript== diff --git a/changelog b/changelog index 0cccbf08a..d5257a6be 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,6 @@ master + +2.24.4 - ahokadesuka Scroll back up when unexpanding images. - e000 diff --git a/latest.js b/latest.js index 219917673..639387181 100644 --- a/latest.js +++ b/latest.js @@ -1 +1 @@ -postMessage({version:'2.24.3'},'*'); +postMessage({version:'2.24.4'},'*'); diff --git a/script.coffee b/script.coffee index 5a587ac5b..9c6fb4728 100644 --- a/script.coffee +++ b/script.coffee @@ -121,7 +121,7 @@ conf = {} ) null, config NAMESPACE = '4chan_x.' -VERSION = '2.24.3' +VERSION = '2.24.4' SECOND = 1000 MINUTE = 60*SECOND HOUR = 60*MINUTE From 10ba4513e998f7c5706ea61d4e4e83f0f478ba54 Mon Sep 17 00:00:00 2001 From: ahodesuka Date: Sat, 21 Jan 2012 03:33:45 -0600 Subject: [PATCH 16/22] Make expand [ + ], icon-able --- 4chan_x.user.js | 23 ++++++++++++++--------- script.coffee | 4 ++-- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 83da74aae..071045f36 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -69,7 +69,7 @@ (function() { var $, $$, DAY, Favicon, HOUR, MINUTE, Main, NAMESPACE, Recaptcha, SECOND, Time, VERSION, anonymize, conf, config, cooldown, d, engine, expandComment, expandThread, filter, flatten, g, getTitle, imgExpand, imgGif, imgHover, key, keybinds, log, nav, options, qr, quoteBacklink, quoteDR, quoteInline, quoteOP, quotePreview, redirect, replyHiding, reportButton, revealSpoilers, sauce, strikethroughQuotes, threadHiding, threadStats, threading, titlePost, ui, unread, updater, val, watcher, _base, - __slice = Array.prototype.slice; + __slice = [].slice; config = { main: { @@ -294,6 +294,7 @@ not chainable */ + $ = function(selector, root) { if (root == null) root = d.body; return root.querySelector(selector); @@ -449,6 +450,7 @@ 0200 EST (UTC-05) = 0700 UTC 0200 EDT (UTC-04) = 0600 UTC */ + var D, date, day, hours, month, sunday; D = new Date(); date = D.getUTCDate(); @@ -851,7 +853,7 @@ name = $('.commentpostername', reply).textContent; trip = ((_ref = $('.postertrip', reply)) != null ? _ref.textContent : void 0) || ''; a = $.el('a', { - textContent: "[ + ] " + name + " " + trip, + innerHTML: "[ + ] " + name + " " + trip, href: 'javascript:;' }); $.on(a, 'click', replyHiding.cb.show); @@ -1166,10 +1168,10 @@ }, threads: [], getThread: function(full) { - var bottom, i, rect, thread, _len, _ref; + var bottom, i, rect, thread, _i, _len, _ref; nav.threads = $$('div.thread:not([hidden])'); _ref = nav.threads; - for (i = 0, _len = _ref.length; i < _len; i++) { + for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { thread = _ref[i]; rect = thread.getBoundingClientRect(); bottom = rect.bottom; @@ -1638,6 +1640,7 @@ captchas expire after 30 minutes, see window.RecaptchaState.timeout. cutoff 5 minutes before then, b/c posting takes time. */ + cutoff = Date.now() - 25 * MINUTE; captchas = $.get('captchas', []); while (captcha = captchas.shift()) { @@ -1739,6 +1742,7 @@ To access the parent, we have to break out of the sandbox and evaluate in the global context. */ + $.globalEval(function() { var data, node, _ref; data = {}; @@ -1904,7 +1908,7 @@ name = $('.postername', thread).textContent; trip = ((_ref = $('.postername + .postertrip', thread)) != null ? _ref.textContent : void 0) || ''; a = $.el('a', { - textContent: "[ + ] " + name + trip + " (" + text + ")", + innerHTML: "[ + ] " + name + trip + " (" + text + ")", href: 'javascript:;' }); $.on(a, 'click', threadHiding.cb.show); @@ -2034,6 +2038,7 @@ This saves bandwidth for both the user and the servers, avoid unnecessary computation, and won't load images and scripts when parsing the response. */ + if (this.status === 304) { if (conf['Verbose']) { updater.count.textContent = '+0'; @@ -2236,12 +2241,12 @@ return prefix.match(/(\w+)\./)[1]; }); return g.callbacks.push(function(root) { - var i, link, prefix, span, suffix, _len, _ref, _results; + var i, link, prefix, span, suffix, _i, _len, _ref, _results; if (root.className === 'inline' || !(span = $('.filesize', root))) return; suffix = $('a', span).href; _ref = sauce.prefixes; _results = []; - for (i = 0, _len = _ref.length; i < _len; i++) { + for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { prefix = _ref[i]; link = $.el('a', { textContent: sauce.names[i], @@ -2759,11 +2764,11 @@ if (unread.replies.length === 1) return Favicon.update(); }, scroll: function() { - var bottom, height, i, reply, _len, _ref; + var bottom, height, i, reply, _i, _len, _ref; updater.focus = true; height = d.body.clientHeight; _ref = unread.replies; - for (i = 0, _len = _ref.length; i < _len; i++) { + for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { reply = _ref[i]; bottom = reply.getBoundingClientRect().bottom; if (bottom > height) break; diff --git a/script.coffee b/script.coffee index 9c6fb4728..0099ea17f 100644 --- a/script.coffee +++ b/script.coffee @@ -619,7 +619,7 @@ replyHiding = name = $('.commentpostername', reply).textContent trip = $('.postertrip', reply)?.textContent or '' a = $.el 'a', - textContent: "[ + ] #{name} #{trip}" + innerHTML: "[ + ] #{name} #{trip}" href: 'javascript:;' $.on a, 'click', replyHiding.cb.show @@ -1519,7 +1519,7 @@ threadHiding = trip = $('.postername + .postertrip', thread)?.textContent or '' a = $.el 'a', - textContent: "[ + ] #{name}#{trip} (#{text})" + innerHTML: "[ + ] #{name}#{trip} (#{text})" href: 'javascript:;' $.on a, 'click', threadHiding.cb.show From 215cfc4af5e754e7c07acfd7f158bf774810c857 Mon Sep 17 00:00:00 2001 From: ahodesuka Date: Sat, 21 Jan 2012 03:40:40 -0600 Subject: [PATCH 17/22] Undo coffeescript derps --- 4chan_x.user.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 071045f36..4899ef455 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -69,7 +69,7 @@ (function() { var $, $$, DAY, Favicon, HOUR, MINUTE, Main, NAMESPACE, Recaptcha, SECOND, Time, VERSION, anonymize, conf, config, cooldown, d, engine, expandComment, expandThread, filter, flatten, g, getTitle, imgExpand, imgGif, imgHover, key, keybinds, log, nav, options, qr, quoteBacklink, quoteDR, quoteInline, quoteOP, quotePreview, redirect, replyHiding, reportButton, revealSpoilers, sauce, strikethroughQuotes, threadHiding, threadStats, threading, titlePost, ui, unread, updater, val, watcher, _base, - __slice = [].slice; + __slice = Array.prototype.slice; config = { main: { @@ -1168,10 +1168,10 @@ }, threads: [], getThread: function(full) { - var bottom, i, rect, thread, _i, _len, _ref; + var bottom, i, rect, thread, _len, _ref; nav.threads = $$('div.thread:not([hidden])'); _ref = nav.threads; - for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { + for (i = 0, _len = _ref.length; i < _len; i++) { thread = _ref[i]; rect = thread.getBoundingClientRect(); bottom = rect.bottom; @@ -2241,12 +2241,12 @@ return prefix.match(/(\w+)\./)[1]; }); return g.callbacks.push(function(root) { - var i, link, prefix, span, suffix, _i, _len, _ref, _results; + var i, link, prefix, span, suffix, _len, _ref, _results; if (root.className === 'inline' || !(span = $('.filesize', root))) return; suffix = $('a', span).href; _ref = sauce.prefixes; _results = []; - for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { + for (i = 0, _len = _ref.length; i < _len; i++) { prefix = _ref[i]; link = $.el('a', { textContent: sauce.names[i], @@ -2764,11 +2764,11 @@ if (unread.replies.length === 1) return Favicon.update(); }, scroll: function() { - var bottom, height, i, reply, _i, _len, _ref; + var bottom, height, i, reply, _len, _ref; updater.focus = true; height = d.body.clientHeight; _ref = unread.replies; - for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { + for (i = 0, _len = _ref.length; i < _len; i++) { reply = _ref[i]; bottom = reply.getBoundingClientRect().bottom; if (bottom > height) break; From 2068ddccb57a5360ccb7ed5ab21cc39c02fe2529 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Sat, 21 Jan 2012 18:13:35 +0100 Subject: [PATCH 18/22] Build --- 4chan_x.user.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 4899ef455..984d1fc84 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -294,7 +294,6 @@ not chainable */ - $ = function(selector, root) { if (root == null) root = d.body; return root.querySelector(selector); @@ -450,7 +449,6 @@ 0200 EST (UTC-05) = 0700 UTC 0200 EDT (UTC-04) = 0600 UTC */ - var D, date, day, hours, month, sunday; D = new Date(); date = D.getUTCDate(); @@ -1640,7 +1638,6 @@ captchas expire after 30 minutes, see window.RecaptchaState.timeout. cutoff 5 minutes before then, b/c posting takes time. */ - cutoff = Date.now() - 25 * MINUTE; captchas = $.get('captchas', []); while (captcha = captchas.shift()) { @@ -1742,7 +1739,6 @@ To access the parent, we have to break out of the sandbox and evaluate in the global context. */ - $.globalEval(function() { var data, node, _ref; data = {}; @@ -2038,7 +2034,6 @@ This saves bandwidth for both the user and the servers, avoid unnecessary computation, and won't load images and scripts when parsing the response. */ - if (this.status === 304) { if (conf['Verbose']) { updater.count.textContent = '+0'; From eee2defe4d746dd60d6717553fb5f0a4a6a5e52a Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Sun, 22 Jan 2012 22:15:44 +0100 Subject: [PATCH 19/22] Completely forgot about that. --- 4chan_x.user.js | 1 + Cakefile | 1 + changelog | 2 ++ 3 files changed, 4 insertions(+) diff --git a/4chan_x.user.js b/4chan_x.user.js index 984d1fc84..b587b6b9d 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -49,6 +49,7 @@ * * CONTRIBUTORS * + * seaweed - bottom padding for image hover * e000 - cooldown sanity check * ahokadesuka - scroll back when unexpanding images * Shou- - pentadactyl fixes diff --git a/Cakefile b/Cakefile index 0a2a0a0ea..35575dfb0 100644 --- a/Cakefile +++ b/Cakefile @@ -56,6 +56,7 @@ HEADER = """ * * CONTRIBUTORS * + * seaweed - bottom padding for image hover * e000 - cooldown sanity check * ahokadesuka - scroll back when unexpanding images * Shou- - pentadactyl fixes diff --git a/changelog b/changelog index d5257a6be..8fc026f91 100644 --- a/changelog +++ b/changelog @@ -7,6 +7,8 @@ master Prevent absurd cooldown durations. - Mayhem Better image expanding reload, should fool CloudFlare's cache. +- seaweed + Prevent the hover image to be partially masked by the url preview/status bar. 2.24.3 - Mayhem From 48afb6d880aa1ad0316a0814b2b0905f49648c7c Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Mon, 23 Jan 2012 23:47:31 +0100 Subject: [PATCH 20/22] Do not cycle through board pages with Index Navigation or See next/previous thread keybinds. --- 4chan_x.user.js | 46 ++++++++++++++++------------------------------ changelog | 2 ++ script.coffee | 40 +++++++++++++--------------------------- 3 files changed, 31 insertions(+), 57 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index b587b6b9d..18a06fa11 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -947,13 +947,15 @@ keybinds.img(thread); break; case conf.nextThread: - nav.next(); + if (g.REPLY) return; + nav.scroll(+1); break; case conf.openThreadTab: keybinds.open(thread, true); break; case conf.previousThread: - nav.prev(); + if (g.REPLY) return; + nav.scroll(-1); break; case conf.update: updater.update(); @@ -1160,10 +1162,18 @@ return $.add(d.body, span); }, prev: function() { - return nav.scroll(-1); + if (g.REPLY) { + return window.scrollTo(0, 0); + } else { + return nav.scroll(-1); + } }, next: function() { - return nav.scroll(+1); + if (g.REPLY) { + return window.scrollTo(0, d.body.scrollHeight); + } else { + return nav.scroll(+1); + } }, threads: [], getThread: function(full) { @@ -1182,37 +1192,13 @@ return null; }, scroll: function(delta) { - var i, rect, thread, top, _ref; - if (g.REPLY) { - if (delta === -1) { - window.scrollTo(0, 0); - } else { - window.scrollTo(0, d.body.scrollHeight); - } - return; - } + var i, rect, thread, top, _ref, _ref2; _ref = nav.getThread(true), thread = _ref[0], i = _ref[1], rect = _ref[2]; top = rect.top; if (!((delta === -1 && Math.ceil(top) < 0) || (delta === +1 && top > 1))) { i += delta; } - if (i === -1) { - if (g.PAGENUM === 0) { - window.scrollTo(0, 0); - } else { - window.location = "" + (g.PAGENUM - 1) + "#0"; - } - return; - } - if (delta === +1) { - if (i === nav.threads.length || (innerHeight + pageYOffset === d.body.scrollHeight)) { - if ($('table.pages input[value="Next"]')) { - window.location = "" + (g.PAGENUM + 1) + "#0"; - return; - } - } - } - top = nav.threads[i].getBoundingClientRect().top; + top = (_ref2 = nav.threads[i]) != null ? _ref2.getBoundingClientRect().top : void 0; return window.scrollBy(0, top); } }; diff --git a/changelog b/changelog index 8fc026f91..e71d58f30 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,6 @@ master +- Mayhem + Index Navigation and the See next/previous thread keybinds will not cycle through board pages anymore. 2.24.4 - ahokadesuka diff --git a/script.coffee b/script.coffee index 0099ea17f..5f8dd3ccd 100644 --- a/script.coffee +++ b/script.coffee @@ -692,11 +692,13 @@ keybinds = when conf.expandImages keybinds.img thread when conf.nextThread - nav.next() + return if g.REPLY + nav.scroll +1 when conf.openThreadTab keybinds.open thread, true when conf.previousThread - nav.prev() + return if g.REPLY + nav.scroll -1 when conf.update updater.update() when conf.watch @@ -828,10 +830,16 @@ nav = $.add d.body, span prev: -> - nav.scroll -1 + if g.REPLY + window.scrollTo 0, 0 + else + nav.scroll -1 next: -> - nav.scroll +1 + if g.REPLY + window.scrollTo 0, d.body.scrollHeight + else + nav.scroll +1 threads: [] @@ -847,13 +855,6 @@ nav = return null scroll: (delta) -> - if g.REPLY - if delta is -1 - window.scrollTo 0,0 - else - window.scrollTo 0, d.body.scrollHeight - return - [thread, i, rect] = nav.getThread true {top} = rect @@ -863,22 +864,7 @@ nav = unless (delta is -1 and Math.ceil(top) < 0) or (delta is +1 and top > 1) i += delta - if i is -1 - if g.PAGENUM is 0 - window.scrollTo 0, 0 - else - window.location = "#{g.PAGENUM - 1}#0" - return - if delta is +1 - # if we're at the last thread, or we're at the bottom of the page. - # kind of hackish, what we really need to do is make nav.getThread smarter. - if i is nav.threads.length or (innerHeight + pageYOffset == d.body.scrollHeight) - if $ 'table.pages input[value="Next"]' - window.location = "#{g.PAGENUM + 1}#0" - return - #TODO sfx - - {top} = nav.threads[i].getBoundingClientRect() + {top} = nav.threads[i]?.getBoundingClientRect() window.scrollBy 0, top options = From 87c1fcc0fd6e118c2e33ad5c11729ec84d78f900 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Sat, 28 Jan 2012 19:47:58 +0100 Subject: [PATCH 21/22] Fix $.ready for Opera as it loads userscripts on window.onload and not document-start. --- 4chan_x.user.js | 2 +- changelog | 1 + script.coffee | 4 +++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 18a06fa11..b458cf5a5 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -312,7 +312,7 @@ $.extend($, { ready: function(fc) { var cb; - if (/interactive|complete/.test(d.readyState)) return fc(); + if (/interactive|complete/.test(d.readyState)) return setTimeout(fc); cb = function() { $.off(d, 'DOMContentLoaded', cb); return fc(); diff --git a/changelog b/changelog index e71d58f30..5f56e4552 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,7 @@ master - Mayhem Index Navigation and the See next/previous thread keybinds will not cycle through board pages anymore. + Fix archive redirection in Opera. 2.24.4 - ahokadesuka diff --git a/script.coffee b/script.coffee index 5f8dd3ccd..3eb398ebe 100644 --- a/script.coffee +++ b/script.coffee @@ -223,7 +223,9 @@ $.extend = (object, properties) -> $.extend $, ready: (fc) -> if /interactive|complete/.test d.readyState - return fc() + # Execute the functions in parallel. + # If one fails, do not stop the others. + return setTimeout fc cb = -> $.off d, 'DOMContentLoaded', cb fc() From 0dce1dd7a98a877cc06bc2b52fd6f25a8b41594c Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Sat, 28 Jan 2012 19:50:29 +0100 Subject: [PATCH 22/22] Release 2.24.5. Opera support on hold. --- 4chan_x.user.js | 6 +++--- Cakefile | 2 +- changelog | 4 ++++ latest.js | 2 +- script.coffee | 2 +- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index b458cf5a5..821f2eab4 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1,6 +1,6 @@ // ==UserScript== // @name 4chan x -// @version 2.24.4 +// @version 2.24.5 // @namespace aeosynth // @description Adds various features. // @copyright 2009-2011 James Campos @@ -18,7 +18,7 @@ * Copyright (c) 2009-2011 James Campos * Copyright (c) 2012 Nicolas Stepien * http://mayhemydg.github.com/4chan-x/ - * 4chan X 2.24.4 + * 4chan X 2.24.5 * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation @@ -203,7 +203,7 @@ NAMESPACE = '4chan_x.'; - VERSION = '2.24.4'; + VERSION = '2.24.5'; SECOND = 1000; diff --git a/Cakefile b/Cakefile index 35575dfb0..140d5d3cb 100644 --- a/Cakefile +++ b/Cakefile @@ -2,7 +2,7 @@ {exec} = require 'child_process' fs = require 'fs' -VERSION = '2.24.4' +VERSION = '2.24.5' HEADER = """ // ==UserScript== diff --git a/changelog b/changelog index 5f56e4552..83fb8f7e9 100644 --- a/changelog +++ b/changelog @@ -1,7 +1,11 @@ master + +2.24.5 - Mayhem Index Navigation and the See next/previous thread keybinds will not cycle through board pages anymore. Fix archive redirection in Opera. + Opera support will now be temporarily on hold. + see https://github.com/MayhemYDG/4chan-x/issues/136 2.24.4 - ahokadesuka diff --git a/latest.js b/latest.js index 639387181..150273f8c 100644 --- a/latest.js +++ b/latest.js @@ -1 +1 @@ -postMessage({version:'2.24.4'},'*'); +postMessage({version:'2.24.5'},'*'); diff --git a/script.coffee b/script.coffee index 3eb398ebe..3fba9ad66 100644 --- a/script.coffee +++ b/script.coffee @@ -121,7 +121,7 @@ conf = {} ) null, config NAMESPACE = '4chan_x.' -VERSION = '2.24.4' +VERSION = '2.24.5' SECOND = 1000 MINUTE = 60*SECOND HOUR = 60*MINUTE