From cb8b3fb898bba6595ba8fa36ef683553ceb84b8c Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Wed, 18 May 2011 19:53:25 +0200 Subject: [PATCH 1/8] Fix cross-quotes inlining and addEventListener error. --- 4chan_x.js | 42 +++++++++++++++++++++++------------------- script.coffee | 31 ++++++++++++++++--------------- 2 files changed, 39 insertions(+), 34 deletions(-) diff --git a/4chan_x.js b/4chan_x.js index 48e6dfe29..8ecd194e1 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -1744,40 +1744,41 @@ } return; } - inline = $.el('table', { - className: 'inline', - innerHTML: "" - }); - td = $('td', inline); if (el = d.getElementById(id)) { - td.innerHTML = el.innerHTML; + inline = $.el('table', { + className: 'inline', + innerHTML: "" + el.innerHTML + "" + }); + if (this.className === 'backlink') { + $.after($('td > br:first-of-type, td > a:last-of-type', this.parentNode), inline); + return $.hide($.x('ancestor::table[1]', el)); + } else { + return $.after(this.parentNode, inline); + } } else { - td.innerHTML = "Loading " + id + "..."; + inline = $.el('div', { + className: 'reply inline', + innerHTML: "Loading " + id + "..." + }); + $.after(this.parentNode, inline); threadID = this.pathname.split('/').pop() || $.x('ancestor::div[@class="thread"]/div', this).id; if (req = g.requests[threadID]) { if (req.readyState === 4) { - quoteInline.parse(req, id, threadID, inline); + return quoteInline.parse(req, id, threadID, inline); } } else { - g.requests[threadID] = $.get(this.href, (function() { + return g.requests[threadID] = $.get(this.href, (function() { return quoteInline.parse(this, id, threadID, inline); })); } } - if (this.className === 'backlink') { - $.after($('td > br:first-of-type, td > a:last-of-type', this.parentNode), inline); - return $.hide($.x('ancestor::table[1]', el)); - } else { - return $.after(this.parentNode, inline); - } }, parse: function(req, id, threadID, inline) { - var body, clone, html, op, reply, _i, _len, _ref; + var body, html, newInline, op, reply, _i, _len, _ref; if (req.status !== 200) { inline.innerHTML = "" + req.status + " " + req.statusText; return; } - clone = inline.cloneNode(true); body = $.el('body', { innerHTML: req.responseText }); @@ -1794,8 +1795,11 @@ } } } - $('td', clone).innerHTML = html; - return $.replace(inline, clone); + newInline = $.el('table', { + className: 'inline', + innerHTML: "" + html + "" + }); + return $.replace(inline, newInline); } }; quotePreview = { diff --git a/script.coffee b/script.coffee index 4da2cbb1e..3ae555371 100644 --- a/script.coffee +++ b/script.coffee @@ -1393,16 +1393,21 @@ quoteInline = if @className is 'backlink' $.show $.x 'ancestor::table[1]', d.getElementById id return - inline = $.el 'table', - className: 'inline' - innerHTML: "" - td = $ 'td', inline if el = d.getElementById id - td.innerHTML = el.innerHTML + inline = $.el 'table', + className: 'inline' + innerHTML: "#{el.innerHTML}" + if @className is 'backlink' + $.after $('td > br:first-of-type, td > a:last-of-type', @parentNode), inline + $.hide $.x 'ancestor::table[1]', el + else + $.after @parentNode, inline else - td.innerHTML = "Loading #{id}..." + inline = $.el 'div', + className: 'reply inline' + innerHTML: "Loading #{id}..." + $.after @parentNode, inline # or ... is for index page new posts. - # FIXME x-thread quotes threadID = @pathname.split('/').pop() or $.x('ancestor::div[@class="thread"]/div', this).id if req = g.requests[threadID] if req.readyState is 4 @@ -1410,17 +1415,11 @@ quoteInline = else #FIXME need an array of callbacks g.requests[threadID] = $.get @href, (-> quoteInline.parse this, id, threadID, inline) - if @className is 'backlink' - $.after $('td > br:first-of-type, td > a:last-of-type', @parentNode), inline - $.hide $.x 'ancestor::table[1]', el - else - $.after @parentNode, inline parse: (req, id, threadID, inline) -> if req.status isnt 200 inline.innerHTML = "#{req.status} #{req.statusText}" return - clone = inline.cloneNode true body = $.el 'body', innerHTML: req.responseText if id == threadID #OP @@ -1431,8 +1430,10 @@ quoteInline = if reply.id == id html = reply.innerHTML break - $('td', clone).innerHTML = html - $.replace inline, clone + newInline = $.el 'table', + className: 'inline' + innerHTML: "#{html}" + $.replace inline, newInline quotePreview = init: -> From b2328eacc622a5a5c5b8fdb2b42643f8a48aaf7c Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Wed, 18 May 2011 20:03:40 +0200 Subject: [PATCH 2/8] Keep some consistent look. --- 4chan_x.js | 2 +- script.coffee | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/4chan_x.js b/4chan_x.js index 8ecd194e1..9fa5874ad 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -1756,7 +1756,7 @@ return $.after(this.parentNode, inline); } } else { - inline = $.el('div', { + inline = $.el('td', { className: 'reply inline', innerHTML: "Loading " + id + "..." }); diff --git a/script.coffee b/script.coffee index 3ae555371..a3cdc4226 100644 --- a/script.coffee +++ b/script.coffee @@ -1403,7 +1403,7 @@ quoteInline = else $.after @parentNode, inline else - inline = $.el 'div', + inline = $.el 'td', className: 'reply inline' innerHTML: "Loading #{id}..." $.after @parentNode, inline From dc0ce7e7d2430ffc8f802fd1be52bb8af28f50bd Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Wed, 18 May 2011 20:24:49 +0200 Subject: [PATCH 3/8] Put some sauce in the newborn. --- 4chan_x.js | 3 ++- script.coffee | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/4chan_x.js b/4chan_x.js index 9fa5874ad..5da59956e 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -1796,9 +1796,10 @@ } } newInline = $.el('table', { - className: 'inline', innerHTML: "" + html + "" }); + sauce.cb.node(newInline); + newInline.className = 'inline'; return $.replace(inline, newInline); } }; diff --git a/script.coffee b/script.coffee index a3cdc4226..775aaeb62 100644 --- a/script.coffee +++ b/script.coffee @@ -1431,8 +1431,9 @@ quoteInline = html = reply.innerHTML break newInline = $.el 'table', - className: 'inline' innerHTML: "#{html}" + sauce.cb.node newInline + newInline.className = 'inline' $.replace inline, newInline quotePreview = From ef6937f6893b1c88e8f20e12e26a70cc85374733 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Wed, 18 May 2011 20:53:42 +0200 Subject: [PATCH 4/8] Less retarded saucing. --- 4chan_x.js | 5 ++--- script.coffee | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/4chan_x.js b/4chan_x.js index 5da59956e..2df11f24e 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -1798,9 +1798,8 @@ newInline = $.el('table', { innerHTML: "" + html + "" }); - sauce.cb.node(newInline); - newInline.className = 'inline'; - return $.replace(inline, newInline); + $.replace(inline, newInline); + return newInline.className = 'inline'; } }; quotePreview = { diff --git a/script.coffee b/script.coffee index 775aaeb62..8e805dc95 100644 --- a/script.coffee +++ b/script.coffee @@ -1432,9 +1432,8 @@ quoteInline = break newInline = $.el 'table', innerHTML: "#{html}" - sauce.cb.node newInline - newInline.className = 'inline' $.replace inline, newInline + newInline.className = 'inline' quotePreview = init: -> From 696b25c29032c2616e1303adc670dc78571e096e Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Wed, 18 May 2011 22:00:33 +0200 Subject: [PATCH 5/8] Function, make sauce work without ++unread --- 4chan_x.js | 17 +++++++++-------- script.coffee | 15 ++++++++------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/4chan_x.js b/4chan_x.js index 2df11f24e..73a206169 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -1595,7 +1595,7 @@ cb: { node: function(root) { var i, link, names, prefix, prefixes, s, span, suffix, _len, _results; - if (root.className === 'inline') { + if (root.className === 'inline' && root.className !== 'crossquote') { return; } prefixes = (function() { @@ -1745,10 +1745,7 @@ return; } if (el = d.getElementById(id)) { - inline = $.el('table', { - className: 'inline', - innerHTML: "" + el.innerHTML + "" - }); + inline = quoteInline.table(id, el.innerHTML); if (this.className === 'backlink') { $.after($('td > br:first-of-type, td > a:last-of-type', this.parentNode), inline); return $.hide($.x('ancestor::table[1]', el)); @@ -1795,11 +1792,15 @@ } } } - newInline = $.el('table', { + newInline = quoteInline.table(id, html); + $.addClass(newInline, 'crossquote'); + return $.replace(inline, newInline); + }, + table: function(id, html) { + return $.el('table', { + className: 'inline', innerHTML: "" + html + "" }); - $.replace(inline, newInline); - return newInline.className = 'inline'; } }; quotePreview = { diff --git a/script.coffee b/script.coffee index 8e805dc95..88669da0d 100644 --- a/script.coffee +++ b/script.coffee @@ -1306,7 +1306,7 @@ sauce = g.callbacks.push sauce.cb.node cb: node: (root) -> - return if root.className is 'inline' + return if root.className is 'inline' and root.className isnt 'crossquote' prefixes = (s for s in ($.config('flavors').split '\n') when s[0] != '#') names = (prefix.match(/(\w+)\./)[1] for prefix in prefixes) if span = $ 'span.filesize', root @@ -1394,9 +1394,7 @@ quoteInline = $.show $.x 'ancestor::table[1]', d.getElementById id return if el = d.getElementById id - inline = $.el 'table', - className: 'inline' - innerHTML: "#{el.innerHTML}" + inline = quoteInline.table id, el.innerHTML if @className is 'backlink' $.after $('td > br:first-of-type, td > a:last-of-type', @parentNode), inline $.hide $.x 'ancestor::table[1]', el @@ -1430,10 +1428,13 @@ quoteInline = if reply.id == id html = reply.innerHTML break - newInline = $.el 'table', - innerHTML: "#{html}" + newInline = quoteInline.table id, html + $.addClass newInline, 'crossquote' $.replace inline, newInline - newInline.className = 'inline' + table: (id, html) -> + $.el 'table', + className: 'inline' + innerHTML: "#{html}" quotePreview = init: -> From 91cb3f12f6839d1c2c8dea4e494743eb4156cd0f Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Wed, 18 May 2011 22:19:35 +0200 Subject: [PATCH 6/8] Ahem. --- 4chan_x.js | 2 +- script.coffee | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/4chan_x.js b/4chan_x.js index 73a206169..48d4f65bd 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -1595,7 +1595,7 @@ cb: { node: function(root) { var i, link, names, prefix, prefixes, s, span, suffix, _len, _results; - if (root.className === 'inline' && root.className !== 'crossquote') { + if (root.className === 'inline') { return; } prefixes = (function() { diff --git a/script.coffee b/script.coffee index 88669da0d..418d24f7f 100644 --- a/script.coffee +++ b/script.coffee @@ -1306,7 +1306,7 @@ sauce = g.callbacks.push sauce.cb.node cb: node: (root) -> - return if root.className is 'inline' and root.className isnt 'crossquote' + return if root.className is 'inline' prefixes = (s for s in ($.config('flavors').split '\n') when s[0] != '#') names = (prefix.match(/(\w+)\./)[1] for prefix in prefixes) if span = $ 'span.filesize', root From 3de7ee04b56d779df6abfd041e7847c2a81486ef Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Wed, 18 May 2011 22:49:02 +0200 Subject: [PATCH 7/8] Fix unread count on inlining, don't inline multiple loading TDs. --- 4chan_x.js | 12 +++++++----- script.coffee | 10 ++++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/4chan_x.js b/4chan_x.js index 48d4f65bd..3ee162adb 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -1731,14 +1731,14 @@ return _results; }, toggle: function(e) { - var el, id, inline, req, root, td, threadID; + var el, id, inline, req, root, table, threadID; e.preventDefault(); if (!(id = this.hash.slice(1))) { return; } root = $.x('ancestor::td[1]', this); - if (td = $("#i" + id, root)) { - $.rm($.x('ancestor::table[1]', td)); + if (table = $("#i" + id, root)) { + $.rm(table); if (this.className === 'backlink') { $.show($.x('ancestor::table[1]', d.getElementById(id))); } @@ -1755,6 +1755,7 @@ } else { inline = $.el('td', { className: 'reply inline', + id: "i" + id, innerHTML: "Loading " + id + "..." }); $.after(this.parentNode, inline); @@ -1799,7 +1800,8 @@ table: function(id, html) { return $.el('table', { className: 'inline', - innerHTML: "" + html + "" + id: "i" + id, + innerHTML: "" + html + "" }); } }; @@ -1919,7 +1921,7 @@ }, cb: { node: function(root) { - if (root.className === 'inline') { + if (root.className) { return; } unread.replies.push(root); diff --git a/script.coffee b/script.coffee index 418d24f7f..18a9ab228 100644 --- a/script.coffee +++ b/script.coffee @@ -1388,8 +1388,8 @@ quoteInline = e.preventDefault() return unless id = @hash[1..] root = $.x 'ancestor::td[1]', this - if td = $ "#i#{id}", root - $.rm $.x 'ancestor::table[1]', td + if table = $ "#i#{id}", root + $.rm table if @className is 'backlink' $.show $.x 'ancestor::table[1]', d.getElementById id return @@ -1403,6 +1403,7 @@ quoteInline = else inline = $.el 'td', className: 'reply inline' + id: "i#{id}" innerHTML: "Loading #{id}..." $.after @parentNode, inline # or ... is for index page new posts. @@ -1434,7 +1435,8 @@ quoteInline = table: (id, html) -> $.el 'table', className: 'inline' - innerHTML: "#{html}" + id: "i#{id}" + innerHTML: "#{html}" quotePreview = init: -> @@ -1515,7 +1517,7 @@ unread = cb: node: (root) -> - return if root.className is 'inline' + return if root.className unread.replies.push root unread.updateTitle() Favicon.update() From 6114c7f1bbdd419d9e26f23e68da92c24f3c1de4 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Wed, 18 May 2011 23:09:20 +0200 Subject: [PATCH 8/8] Fix inception. --- 4chan_x.js | 2 +- script.coffee | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/4chan_x.js b/4chan_x.js index 3ee162adb..1ece8ac43 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -1674,7 +1674,7 @@ }, node: function(root) { var el, id, link, qid, quote, quotes, tid, _i, _len, _ref, _results; - if (root.className === 'inline') { + if (root.className) { return; } id = root.id || $('td[id]', root).id; diff --git a/script.coffee b/script.coffee index 18a9ab228..04981b09e 100644 --- a/script.coffee +++ b/script.coffee @@ -1352,7 +1352,7 @@ quoteBacklink = init: -> g.callbacks.push quoteBacklink.node node: (root) -> - return if root.className is 'inline' + return if root.className #better coffee-script way of doing this? id = root.id or $('td[id]', root).id quotes = {}