From 5720a30dcf1eaf197b9f79a4b5d9b52470d91acd Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Thu, 29 Sep 2011 18:28:05 +0200 Subject: [PATCH 1/5] Hide asap. --- 4chan_x.user.js | 12 ++++++------ script.coffee | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index fd728ae0c..6a001197d 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -3066,6 +3066,9 @@ if (conf['Filter']) { filter.init(); } + if (conf['Reply Hiding']) { + replyHiding.init(); + } if (conf['Image Expansion']) { imgExpand.init(); } @@ -3087,9 +3090,6 @@ if (conf['Image Hover']) { imgHover.init(); } - if (conf['Reply Hiding']) { - replyHiding.init(); - } if (conf['Quick Reply']) { QR.init(); } @@ -3134,12 +3134,12 @@ nav.init(); } } else { - if (conf['Index Navigation']) { - nav.init(); - } if (conf['Thread Hiding']) { threadHiding.init(); } + if (conf['Index Navigation']) { + nav.init(); + } if (conf['Thread Expansion']) { expandThread.init(); } diff --git a/script.coffee b/script.coffee index 9abc1e96c..2b8a048e0 100644 --- a/script.coffee +++ b/script.coffee @@ -2282,6 +2282,9 @@ Main = if conf['Filter'] filter.init() + if conf['Reply Hiding'] + replyHiding.init() + if conf['Image Expansion'] imgExpand.init() @@ -2303,9 +2306,6 @@ Main = if conf['Image Hover'] imgHover.init() - if conf['Reply Hiding'] - replyHiding.init() - if conf['Quick Reply'] QR.init() @@ -2350,12 +2350,12 @@ Main = nav.init() else #not reply - if conf['Index Navigation'] - nav.init() - if conf['Thread Hiding'] threadHiding.init() + if conf['Index Navigation'] + nav.init() + if conf['Thread Expansion'] expandThread.init() From 0bd570e375f8ca51ca743c87f02976ec9dd04229 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Thu, 29 Sep 2011 21:25:13 +0200 Subject: [PATCH 2/5] Shorter selectors. --- 4chan_x.user.js | 26 +++++++++++++------------- script.coffee | 26 +++++++++++++------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 6a001197d..323018650 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -632,7 +632,7 @@ expandComment = { init: function() { var a, _i, _len, _ref, _results; - _ref = $$('span.abbr a'); + _ref = $$('.abbr a'); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { a = _ref[_i]; @@ -696,7 +696,7 @@ expandThread = { init: function() { var a, span, _i, _len, _ref, _results; - _ref = $$('span.omittedposts'); + _ref = $$('.omittedposts'); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { span = _ref[_i]; @@ -803,7 +803,7 @@ init: function() { return g.callbacks.push(function(root) { var a, dd, id, reply; - if (!(dd = $('td.doubledash', root))) { + if (!(dd = $('.doubledash', root))) { return; } dd.className = 'replyhider'; @@ -845,8 +845,8 @@ table = reply.parentNode.parentNode.parentNode; table.hidden = true; if (conf['Show Stubs']) { - name = $('span.commentpostername', reply).textContent; - trip = ((_ref = $('span.postertrip', reply)) != null ? _ref.textContent : void 0) || ''; + name = $('.commentpostername', reply).textContent; + trip = ((_ref = $('.postertrip', reply)) != null ? _ref.textContent : void 0) || ''; a = $.el('a', { textContent: "[ + ] " + name + " " + trip }); @@ -1881,8 +1881,8 @@ } num += $$('table', thread).length; text = num === 1 ? "1 reply" : "" + num + " replies"; - name = $('span.postername', thread).textContent; - trip = ((_ref = $('span.postername + span.postertrip', thread)) != null ? _ref.textContent : void 0) || ''; + name = $('.postername', thread).textContent; + trip = ((_ref = $('.postername + .postertrip', thread)) != null ? _ref.textContent : void 0) || ''; a = $.el('a', { textContent: "[ + ] " + name + trip + " (" + text + ")" }); @@ -2163,9 +2163,9 @@ init: function() { return g.callbacks.push(function(root) { var name, trip; - name = $('span.commentpostername, span.postername', root); + name = $('.commentpostername, .postername', root); name.textContent = 'Anonymous'; - if (trip = $('span.postertrip', root)) { + if (trip = $('.postertrip', root)) { if (trip.parentNode.nodeName === 'A') { return $.rm(trip.parentNode); } else { @@ -2205,7 +2205,7 @@ if (root.className === 'inline') { return; } - if (span = $('span.filesize', root)) { + if (span = $('.filesize', root)) { suffix = $('a', span).href; _ref = sauce.prefixes; _results = []; @@ -2336,11 +2336,11 @@ }; getTitle = function(thread) { var el, span; - el = $('span.filetitle', thread); + el = $('.filetitle', thread); if (!el.textContent) { el = $('blockquote', thread); if (!el.textContent) { - el = $('span.postername', thread); + el = $('.postername', thread); } } span = $.el('span', { @@ -2941,7 +2941,7 @@ src: a.href }); if (a.parentNode.className !== 'op') { - filesize = $('span.filesize', a.parentNode); + filesize = $('.filesize', a.parentNode); _ref = filesize.textContent.match(/(\d+)x/), _ = _ref[0], max = _ref[1]; img.style.maxWidth = "-moz-calc(" + max + "px)"; } diff --git a/script.coffee b/script.coffee index 2b8a048e0..30e5a2b5c 100644 --- a/script.coffee +++ b/script.coffee @@ -439,7 +439,7 @@ filter = expandComment = init: -> - for a in $$ 'span.abbr a' + for a in $$ '.abbr a' $.bind a, 'click', expandComment.expand expand: (e) -> e.preventDefault() @@ -480,7 +480,7 @@ expandComment = expandThread = init: -> - for span in $$ 'span.omittedposts' + for span in $$ '.omittedposts' a = $.el 'a', textContent: "+ #{span.textContent}" className: 'omittedposts' @@ -555,7 +555,7 @@ expandThread = replyHiding = init: -> g.callbacks.push (root) -> - return unless dd = $ 'td.doubledash', root + return unless dd = $ '.doubledash', root dd.className = 'replyhider' a = $.el 'a', textContent: '[ - ]' @@ -591,8 +591,8 @@ replyHiding = table.hidden = true if conf['Show Stubs'] - name = $('span.commentpostername', reply).textContent - trip = $('span.postertrip', reply)?.textContent or '' + name = $('.commentpostername', reply).textContent + trip = $('.postertrip', reply)?.textContent or '' a = $.el 'a', textContent: "[ + ] #{name} #{trip}" $.bind a, 'click', replyHiding.cb.show @@ -1396,8 +1396,8 @@ threadHiding = num = 0 num += $$('table', thread).length text = if num is 1 then "1 reply" else "#{num} replies" - name = $('span.postername', thread).textContent - trip = $('span.postername + span.postertrip', thread)?.textContent or '' + name = $('.postername', thread).textContent + trip = $('.postername + .postertrip', thread)?.textContent or '' a = $.el 'a', textContent: "[ + ] #{name}#{trip} (#{text})" @@ -1635,9 +1635,9 @@ watcher = anonymize = init: -> g.callbacks.push (root) -> - name = $ 'span.commentpostername, span.postername', root + name = $ '.commentpostername, .postername', root name.textContent = 'Anonymous' - if trip = $ 'span.postertrip', root + if trip = $ '.postertrip', root if trip.parentNode.nodeName is 'A' $.rm trip.parentNode else @@ -1649,7 +1649,7 @@ sauce = sauce.names = (prefix.match(/(\w+)\./)[1] for prefix in sauce.prefixes) g.callbacks.push (root) -> return if root.className is 'inline' - if span = $ 'span.filesize', root + if span = $ '.filesize', root suffix = $('a', span).href for prefix, i in sauce.prefixes link = $.el 'a', @@ -1734,11 +1734,11 @@ Time = y: -> Time.date.getFullYear() - 2000 getTitle = (thread) -> - el = $ 'span.filetitle', thread + el = $ '.filetitle', thread if not el.textContent el = $ 'blockquote', thread if not el.textContent - el = $ 'span.postername', thread + el = $ '.postername', thread span = $.el 'span', innerHTML: el.innerHTML.replace /
/g, ' ' "/#{g.BOARD}/ - #{span.textContent}" @@ -2112,7 +2112,7 @@ imgExpand = img = $.el 'img', src: a.href unless a.parentNode.className is 'op' - filesize = $ 'span.filesize', a.parentNode + filesize = $ '.filesize', a.parentNode [_, max] = filesize.textContent.match /(\d+)x/ img.style.maxWidth = "-moz-calc(#{max}px)" $.bind img, 'error', imgExpand.error From 599b24e7f26e31398fbd135c7b7b86305d33017e Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Thu, 29 Sep 2011 21:27:26 +0200 Subject: [PATCH 3/5] Don't add filtered/hidden posts to the unread count. --- 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 323018650..33d89e52b 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2681,7 +2681,7 @@ return g.callbacks.push(unread.node); }, node: function(root) { - if (root.className) { + if (root.hidden || root.className) { return; } unread.replies.push(root); diff --git a/script.coffee b/script.coffee index 30e5a2b5c..d2bdce529 100644 --- a/script.coffee +++ b/script.coffee @@ -1956,7 +1956,7 @@ unread = g.callbacks.push unread.node node: (root) -> - return if root.className + return if root.hidden or root.className unread.replies.push root unread.updateTitle() Favicon.update() From b25a4fcbc2a2ff928bff095679439c865703f2de Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Tue, 4 Oct 2011 19:05:09 +0200 Subject: [PATCH 4/5] quoteInline refactor --- 4chan_x.user.js | 56 ++++++++++++++++++++++++++++--------------------- script.coffee | 43 +++++++++++++++++++++---------------- 2 files changed, 57 insertions(+), 42 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 6aecf61b8..1a84eacc9 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2428,36 +2428,33 @@ }); }, toggle: function(e) { - var el, hidden, id, inline, inlined, root, table, threadID, _i, _len, _ref; + var id; if (e.shiftKey || e.altKey || e.ctrlKey || e.button !== 0) { return; } e.preventDefault(); id = this.hash.slice(1); - if (table = $("#i" + id, $.x('ancestor::td[1]', this))) { - $.rm(table); - $.removeClass(this, 'inlined'); - _ref = $$('input', table); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - inlined = _ref[_i]; - if (hidden = $.id(inlined.name)) { - $.x('ancestor::table[1]', hidden).hidden = false; - } + if (this.classList.contains('inlined')) { + quoteInline.rm(this, id); + } else { + if ($.x('ancestor::td[@id]', this).id === id) { + return; } - return; + quoteInline.add(this, id); } - root = this.parentNode.nodeName === 'FONT' ? this.parentNode : this.nextSibling ? this.nextSibling : this; + return this.classList.toggle('inlined'); + }, + add: function(q, id) { + var el, inline, root, threadID; + root = q.parentNode.nodeName === 'FONT' ? q.parentNode : q.nextSibling ? q.nextSibling : q; if (el = $.id(id)) { inline = quoteInline.table(id, el.innerHTML); - if (this.className === 'backlink') { - if ($("a.backlink[href='#" + id + "']", el)) { - return; - } - $.after(this.parentNode, inline); - $.x('ancestor::table[1]', el).hidden = true; - } else { - $.after(root, inline); + if (q.className === 'backlink') { + $.after(q.parentNode, inline); + $.x('ancestor::table', el).hidden = true; + return; } + return $.after(root, inline); } else { inline = $.el('td', { className: 'reply inline', @@ -2465,13 +2462,24 @@ innerHTML: "Loading " + id + "..." }); $.after(root, inline); - pathname = this.pathname; + pathname = q.pathname; threadID = pathname.split('/').pop(); - $.cache(pathname, (function() { + return $.cache(pathname, (function() { return quoteInline.parse(this, pathname, id, threadID, inline); })); } - return $.addClass(this, 'inlined'); + }, + rm: function(q, id) { + var hidden, inlined, table, _i, _len, _ref; + table = $.x("following::*[@id='i" + id + "']", q); + _ref = $$('input', table); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + inlined = _ref[_i]; + if (hidden = $.id(inlined.name)) { + $.x('ancestor::table[1]', hidden).hidden = false; + } + } + return $.rm(table); }, parse: function(req, pathname, id, threadID, inline) { var body, href, html, link, newInline, op, quote, reply, _i, _j, _len, _len2, _ref, _ref2; @@ -2486,7 +2494,7 @@ innerHTML: req.responseText }); if (id === threadID) { - op = threading.op($('form[name=delform] > *', body)); + op = threading.op($('body > form', body).firstChild); html = op.innerHTML; } else { _ref = $$('td.reply', body); diff --git a/script.coffee b/script.coffee index c9ec262b9..f7e4e121a 100644 --- a/script.coffee +++ b/script.coffee @@ -1792,35 +1792,42 @@ quoteInline = $.bind quote, 'click', quoteInline.toggle toggle: (e) -> return if e.shiftKey or e.altKey or e.ctrlKey or e.button isnt 0 - e.preventDefault() id = @hash[1..] - if table = $ "#i#{id}", $.x 'ancestor::td[1]', @ - $.rm table - $.removeClass @, 'inlined' - for inlined in $$ 'input', table - if hidden = $.id inlined.name - $.x('ancestor::table[1]', hidden).hidden = false - return - root = if @parentNode.nodeName is 'FONT' then @parentNode else if @nextSibling then @nextSibling else @ + if @classList.contains 'inlined' + quoteInline.rm @, id + else + return if $.x('ancestor::td[@id]', @).id is id + quoteInline.add @, id + @classList.toggle 'inlined' + + add: (q, id) -> + root = if q.parentNode.nodeName is 'FONT' then q.parentNode else if q.nextSibling then q.nextSibling else q if el = $.id id inline = quoteInline.table id, el.innerHTML - if @className is 'backlink' - return if $("a.backlink[href='##{id}']", el) - $.after @parentNode, inline - $.x('ancestor::table[1]', el).hidden = true - else - $.after root, inline + if q.className is 'backlink' + $.after q.parentNode, inline + $.x('ancestor::table', el).hidden = true + return + $.after root, inline else inline = $.el 'td', className: 'reply inline' id: "i#{id}" innerHTML: "Loading #{id}..." $.after root, inline - {pathname} = @ + {pathname} = q threadID = pathname.split('/').pop() $.cache pathname, (-> quoteInline.parse @, pathname, id, threadID, inline) - $.addClass @, 'inlined' + + rm: (q, id) -> + #select the corresponding table or loading td + table = $.x "following::*[@id='i#{id}']", q + for inlined in $$ 'input', table + if hidden = $.id inlined.name + $.x('ancestor::table[1]', hidden).hidden = false + $.rm table + parse: (req, pathname, id, threadID, inline) -> return unless inline.parentNode @@ -1831,7 +1838,7 @@ quoteInline = body = $.el 'body', innerHTML: req.responseText if id == threadID #OP - op = threading.op $ 'form[name=delform] > *', body + op = threading.op $('body > form', body).firstChild html = op.innerHTML else for reply in $$ 'td.reply', body From eaed3c281f7c8aaa76869d46ee797c6a34f68a76 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Tue, 4 Oct 2011 22:47:20 +0200 Subject: [PATCH 5/5] Fuck yeah, parseInt with base 10. --- 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 1a84eacc9..ffbac6c78 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1958,7 +1958,7 @@ } } else if (input.name === 'Interval') { $.bind(input, 'change', function() { - return conf['Interval'] = this.value = parseInt(this.value) || conf['Interval']; + return conf['Interval'] = this.value = parseInt(this.value, 10) || conf['Interval']; }); $.bind(input, 'change', $.cb.value); } else if (input.type === 'button') { diff --git a/script.coffee b/script.coffee index f7e4e121a..b495bf3fd 100644 --- a/script.coffee +++ b/script.coffee @@ -1466,7 +1466,7 @@ updater = $.bind input, 'click', updater.cb.autoUpdate updater.cb.autoUpdate.call input else if input.name is 'Interval' - $.bind input, 'change', -> conf['Interval'] = @value = parseInt(@value) or conf['Interval'] + $.bind input, 'change', -> conf['Interval'] = @value = parseInt(@value, 10) or conf['Interval'] $.bind input, 'change', $.cb.value else if input.type is 'button' $.bind input, 'click', updater.updateNow