From 387c6b33b565765a7de3e6ee14477a765634b92c Mon Sep 17 00:00:00 2001 From: James Campos Date: Fri, 13 May 2011 17:14:27 -0700 Subject: [PATCH 01/14] fix qr on expanded posts --- 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 c67b91530..395284b9b 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -1144,7 +1144,7 @@ dialog: function(link) { var MAX_FILE_SIZE, THREAD_ID, clone, dialog, el, html, mail, name, pass, spoiler; MAX_FILE_SIZE = $('input[name="MAX_FILE_SIZE"]').value; - THREAD_ID = g.THREAD_ID || link.pathname.split('/').pop(); + THREAD_ID = g.THREAD_ID || $.x('preceding::div[@class="op"][1]', link).id; name = $('input[name=name]').value; mail = $('input[name=email]').value; pass = $('input[name=pwd]').value; diff --git a/script.coffee b/script.coffee index 5ab2639af..53ff64f8d 100644 --- a/script.coffee +++ b/script.coffee @@ -892,7 +892,7 @@ qr = dialog: (link) -> #maybe should be global MAX_FILE_SIZE = $('input[name="MAX_FILE_SIZE"]').value - THREAD_ID = g.THREAD_ID or link.pathname.split('/').pop() + THREAD_ID = g.THREAD_ID or $.x('preceding::div[@class="op"][1]', link).id name = $('input[name=name]').value mail = $('input[name=email]').value pass = $('input[name=pwd]').value From c638042de49476a1c509beb6c3c160aa323a4e44 Mon Sep 17 00:00:00 2001 From: James Campos Date: Sat, 14 May 2011 07:49:00 -0700 Subject: [PATCH 02/14] $.remove -> $.rm --- 4chan_x.js | 26 +++++++++++++------------- script.coffee | 26 +++++++++++++------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/4chan_x.js b/4chan_x.js index 395284b9b..4dc9677be 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -263,7 +263,7 @@ textContent: "(" + code + ")()" }); $.append(d.head, script); - return $.remove(script); + return $.rm(script); }, get: function(url, cb) { var r; @@ -322,7 +322,7 @@ removeClass: function(el, className) { return el.className = el.className.replace(' ' + className, ''); }, - remove: function(el) { + rm: function(el) { return el.parentNode.removeChild(el); }, append: function() { @@ -567,7 +567,7 @@ table = $.x("following::br[@clear][1]/preceding::table[" + num + "]", a); _results = []; while ((prev = table.previousSibling) && (prev.nodeName === 'TABLE')) { - _results.push($.remove(prev)); + _results.push($.rm(prev)); } return _results; } @@ -576,7 +576,7 @@ var body, br, next, table, tables, _i, _len, _results; a.textContent = a.textContent.replace('X Loading...', '-'); while ((next = a.nextSibling) && !next.clear) { - $.remove(next); + $.rm(next); } br = next; body = $.el('body', { @@ -624,7 +624,7 @@ div = this.parentNode; table = div.nextSibling; replyHiding.show(table); - return $.remove(div); + return $.rm(div); } }, hide: function(reply) { @@ -694,7 +694,7 @@ switch (keybinds.key) { case '': e.preventDefault(); - return $.remove($('#qr')); + return $.rm($('#qr')); case '^s': ta = d.activeElement; if (ta.nodeName !== 'TEXTAREA') { @@ -920,7 +920,7 @@ toggle: function() { var dialog; if (dialog = $('#options')) { - return $.remove(dialog); + return $.rm(dialog); } else { return options.dialog(); } @@ -1017,7 +1017,7 @@ if ($.config('Persistent QR')) { qr.refresh(dialog); } else { - $.remove(dialog); + $.rm(dialog); } } if ($.config('Cooldown')) { @@ -1328,7 +1328,7 @@ }, show: function(thread) { var hiddenThreads, id; - $.remove($('div.block', thread)); + $.rm($('div.block', thread)); $.removeClass(thread, 'stub'); $.show(thread); $.show(thread.nextSibling); @@ -1505,7 +1505,7 @@ _ref = $$('div:not(.move)', dialog); for (_i = 0, _len = _ref.length; _i < _len; _i++) { div = _ref[_i]; - $.remove(div); + $.rm(div); } for (board in watched) { _ref2 = watched[board]; @@ -1588,9 +1588,9 @@ name.textContent = 'Anonymous'; if (trip = $('span.postertrip', root)) { if (trip.parentNode.nodeName === 'A') { - return $.remove(trip.parentNode); + return $.rm(trip.parentNode); } else { - return $.remove(trip); + return $.rm(trip); } } } @@ -2100,7 +2100,7 @@ }, contract: function(thumb) { $.show(thumb); - return $.remove(thumb.nextSibling); + return $.rm(thumb.nextSibling); }, expand: function(thumb) { var a, img; diff --git a/script.coffee b/script.coffee index 53ff64f8d..9f091374d 100644 --- a/script.coffee +++ b/script.coffee @@ -178,7 +178,7 @@ $.extend $, script = $.el 'script', textContent: "(#{code})()" $.append d.head, script - $.remove script + $.rm script get: (url, cb) -> r = new XMLHttpRequest() r.onload = cb @@ -214,7 +214,7 @@ $.extend $, el.className += ' ' + className removeClass: (el, className) -> el.className = el.className.replace ' ' + className, '' - remove: (el) -> + rm: (el) -> el.parentNode.removeChild el append: (parent, children...) -> for child in children @@ -401,14 +401,14 @@ expandThread = num = if g.BOARD is 'b' then 3 else 5 table = $.x "following::br[@clear][1]/preceding::table[#{num}]", a while (prev = table.previousSibling) and (prev.nodeName is 'TABLE') - $.remove prev + $.rm prev expand: (html, thread, a) -> a.textContent = a.textContent.replace 'X Loading...', '-' # eat everything, then replace with fresh full posts while (next = a.nextSibling) and not next.clear #br[clear] - $.remove next + $.rm next br = next body = $.el 'body', @@ -446,7 +446,7 @@ replyHiding = table = div.nextSibling replyHiding.show table - $.remove div + $.rm div hide: (reply) -> table = reply.parentNode.parentNode.parentNode @@ -506,7 +506,7 @@ keybinds = switch keybinds.key when '' e.preventDefault() - $.remove $ '#qr' + $.rm $ '#qr' when '^s' ta = d.activeElement return unless ta.nodeName is 'TEXTAREA' @@ -701,7 +701,7 @@ options = toggle: -> if dialog = $ '#options' - $.remove dialog + $.rm dialog else options.dialog() @@ -780,7 +780,7 @@ qr = if $.config 'Persistent QR' qr.refresh dialog else - $.remove dialog + $.rm dialog if $.config 'Cooldown' qr.cooldown true @@ -1073,7 +1073,7 @@ threadHiding = $.hide thread.nextSibling show: (thread) -> - $.remove $ 'div.block', thread + $.rm $ 'div.block', thread $.removeClass thread, 'stub' $.show thread $.show thread.nextSibling @@ -1227,7 +1227,7 @@ watcher = refresh: (watched) -> dialog = $ '#watcher' for div in $$ 'div:not(.move)', dialog - $.remove div + $.rm div for board of watched for id, props of watched[board] div = $.el 'div' @@ -1295,9 +1295,9 @@ anonymize = name.textContent = 'Anonymous' if trip = $ 'span.postertrip', root if trip.parentNode.nodeName is 'A' - $.remove trip.parentNode + $.rm trip.parentNode else - $.remove trip + $.rm trip sauce = init: -> @@ -1613,7 +1613,7 @@ imgExpand = contract: (thumb) -> $.show thumb - $.remove thumb.nextSibling + $.rm thumb.nextSibling expand: (thumb) -> $.hide thumb From da42517019f0670f1a537ba5228e2b462179bbf8 Mon Sep 17 00:00:00 2001 From: James Campos Date: Sat, 14 May 2011 09:30:31 -0700 Subject: [PATCH 03/14] stupid quote inlining --- 4chan_x.js | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++- script.coffee | 60 ++++++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+), 1 deletion(-) diff --git a/4chan_x.js b/4chan_x.js index 4dc9677be..2673f5e5a 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -58,7 +58,7 @@ */ (function() { - var $, $$, Favicon, NAMESPACE, Recaptcha, anonymize, config, d, expandComment, expandThread, g, imageHover, imgExpand, imgGif, imgPreloading, keybinds, localize, log, main, nav, nodeInserted, options, qr, quoteBacklink, quotePreview, redirect, replyHiding, reportButton, sauce, threadHiding, threading, titlePost, ui, unread, updater, watcher, _config, _ref; + var $, $$, Favicon, NAMESPACE, Recaptcha, anonymize, config, d, expandComment, expandThread, g, imageHover, imgExpand, imgGif, imgPreloading, keybinds, localize, log, main, nav, nodeInserted, options, qr, quoteBacklink, quoteInline, quotePreview, redirect, replyHiding, reportButton, sauce, threadHiding, threading, titlePost, ui, unread, updater, watcher, _config, _ref; var __slice = Array.prototype.slice; if (typeof console !== "undefined" && console !== null) { log = function(arg) { @@ -84,6 +84,7 @@ 'Post in Title': [true, 'Show the op\'s post in the tab title'], 'Quick Reply': [true, 'Reply without leaving the page'], 'Quote Backlinks': [false, 'Add quote backlinks'], + 'Quote Inline': [false, 'Show quoted post inline on quote click'], 'Quote Preview': [false, 'Show quote content on hover'], 'Reply Hiding': [true, 'Hide single replies'], 'Report Button': [true, 'Add report buttons'], @@ -1715,6 +1716,85 @@ return _results; } }; + quoteInline = { + init: function() { + return g.callbacks.push(quoteInline.node); + }, + node: function(root) { + var quote, _i, _len, _ref, _results; + _ref = $$('a.quotelink', root); + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + quote = _ref[_i]; + quote.removeAttribute('onclick'); + _results.push($.bind(quote, 'click', quoteInline.toggle)); + } + return _results; + }, + toggle: function(e) { + var el, id, inline, next, req, td, threadID; + e.preventDefault(); + if (!(id = this.hash.slice(1))) { + return; + } + if ((next = this.parentNode.nextSibling) && (next.nodeName === 'TABLE')) { + $.rm(next); + return; + } + inline = $.el('table', { + className: 'inline', + innerHTML: '' + }); + td = $('td', inline); + if (el = d.getElementById(id)) { + td.innerHTML = el.innerHTML; + } else { + td.innerHTML = "Loading " + id + "..."; + 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); + } + } else { + g.requests[threadID] = $.get(this.href, (function() { + return quoteInline.parse(this, id, threadID, inline); + })); + } + } + return $.after(this.parentNode, inline); + }, + parse: function(req, id, threadID, oldInline) { + var body, html, inline, op, reply, td, _i, _len, _ref; + inline = $.el('table', { + className: 'inline', + innerHTML: '' + }); + td = $('td', inline); + if (req.status !== 200) { + td.innerHTML = "" + req.status + " " + req.statusText; + $.replace(oldInline, inline); + return; + } + body = $.el('body', { + innerHTML: req.responseText + }); + if (id === threadID) { + op = threading.op($('form[name=delform] > *', body)); + html = op.innerHTML; + } else { + _ref = $$('td.reply', body); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + reply = _ref[_i]; + if (reply.id === id) { + html = reply.innerHTML; + break; + } + } + } + td.innerHTML = html; + return $.replace(oldInline, inline); + } + }; quotePreview = { init: function() { var preview; @@ -2267,6 +2347,9 @@ if ($.config('Quote Backlinks')) { quoteBacklink.init(); } + if ($.config('Quote Inline')) { + quoteInline.init(); + } if ($.config('Quote Preview')) { quotePreview.init(); } diff --git a/script.coffee b/script.coffee index 9f091374d..18cc4fcef 100644 --- a/script.coffee +++ b/script.coffee @@ -28,6 +28,7 @@ config = 'Post in Title': [true, 'Show the op\'s post in the tab title'] 'Quick Reply': [true, 'Reply without leaving the page'] 'Quote Backlinks': [false, 'Add quote backlinks'] + 'Quote Inline': [false, 'Show quoted post inline on quote click'] 'Quote Preview': [false, 'Show quote content on hover'] 'Reply Hiding': [true, 'Hide single replies'] 'Report Button': [true, 'Add report buttons'] @@ -1372,6 +1373,62 @@ quoteBacklink = $.bind link, 'mouseout', ui.hoverend $.before $('td > br, blockquote', el), link +quoteInline = + init: -> + g.callbacks.push quoteInline.node + node: (root) -> + for quote in $$ 'a.quotelink', root + quote.removeAttribute 'onclick' + $.bind quote, 'click', quoteInline.toggle + toggle: (e) -> + e.preventDefault() + return unless id = @hash[1..] + if (next = @parentNode.nextSibling) and (next.nodeName is 'TABLE') + $.rm next + return + inline = $.el 'table', + className: 'inline' + innerHTML: '' + td = $ 'td', inline + if el = d.getElementById id + td.innerHTML = el.innerHTML + else + td.innerHTML = "Loading #{id}..." + # 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 + quoteInline.parse req, id, threadID, inline + else + #FIXME need an array of callbacks + g.requests[threadID] = $.get @href, (-> quoteInline.parse this, id, threadID, inline) + $.after @parentNode, inline + parse: (req, id, threadID, oldInline) -> + #this is fucking stupid + inline = $.el 'table', + className: 'inline' + innerHTML: '' + td = $ 'td', inline + + if req.status isnt 200 + td.innerHTML = "#{req.status} #{req.statusText}" + $.replace oldInline, inline + return + + body = $.el 'body', + innerHTML: req.responseText + if id == threadID #OP + op = threading.op $ 'form[name=delform] > *', body + html = op.innerHTML + else + for reply in $$ 'td.reply', body + if reply.id == id + html = reply.innerHTML + break + td.innerHTML = html + $.replace oldInline, inline + quotePreview = init: -> g.callbacks.push quotePreview.node @@ -1770,6 +1827,9 @@ main = if $.config 'Quote Backlinks' quoteBacklink.init() + if $.config 'Quote Inline' + quoteInline.init() + if $.config 'Quote Preview' quotePreview.init() From 2101e7cdf0fd98558f41e344bb15cbd0862f1daf Mon Sep 17 00:00:00 2001 From: James Campos Date: Sat, 14 May 2011 09:43:19 -0700 Subject: [PATCH 04/14] tweaks for inline root --- 4chan_x.js | 24 ++++++++++++++++-------- script.coffee | 15 +++++++++------ 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/4chan_x.js b/4chan_x.js index 2673f5e5a..adfe98434 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -1604,6 +1604,9 @@ cb: { node: function(root) { var i, link, names, prefix, prefixes, s, span, suffix, _len, _results; + if (root.className === 'inline') { + return; + } prefixes = (function() { var _i, _len, _ref, _results; _ref = $.config('flavors').split('\n'); @@ -1880,14 +1883,16 @@ cb: { node: function(root) { var a, span; - span = $('span[id^=no]', root); - a = $.el('a', { - className: 'reportbutton', - innerHTML: '[ ! ]' - }); - $.bind(a, 'click', reportButton.cb.report); - $.after(span, a); - return $.after(span, $.tn(' ')); + if (!(a = $('a.reportbutton', root))) { + span = $('span[id^=no]', root); + a = $.el('a', { + className: 'reportbutton', + innerHTML: '[ ! ]' + }); + $.after(span, a); + $.after(span, $.tn(' ')); + } + return $.bind(a, 'click', reportButton.cb.report); }, report: function(e) { return reportButton.report(this); @@ -1910,6 +1915,9 @@ }, cb: { node: function(root) { + if (root.className === 'inline') { + return; + } unread.replies.push(root); unread.updateTitle(); return Favicon.update(); diff --git a/script.coffee b/script.coffee index 18cc4fcef..7b92c6dd2 100644 --- a/script.coffee +++ b/script.coffee @@ -1305,6 +1305,7 @@ sauce = g.callbacks.push sauce.cb.node cb: node: (root) -> + 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 @@ -1484,13 +1485,14 @@ reportButton = g.callbacks.push reportButton.cb.node cb: node: (root) -> - span = $ 'span[id^=no]', root - a = $.el 'a', - className: 'reportbutton' - innerHTML: '[ ! ]' + if not a = $ 'a.reportbutton', root + span = $ 'span[id^=no]', root + a = $.el 'a', + className: 'reportbutton' + innerHTML: '[ ! ]' + $.after span, a + $.after span, $.tn(' ') $.bind a, 'click', reportButton.cb.report - $.after span, a - $.after span, $.tn(' ') report: (e) -> reportButton.report this report: (target) -> @@ -1508,6 +1510,7 @@ unread = cb: node: (root) -> + return if root.className is 'inline' unread.replies.push root unread.updateTitle() Favicon.update() From 4ce920bff14df52cb80da93a7dc7ca5a91511154 Mon Sep 17 00:00:00 2001 From: James Campos Date: Sat, 14 May 2011 09:57:22 -0700 Subject: [PATCH 05/14] expandComment: g.cache -> g.requests --- 4chan_x.js | 31 +++++++++++++++++++------------ script.coffee | 32 ++++++++++++++++++-------------- 2 files changed, 37 insertions(+), 26 deletions(-) diff --git a/4chan_x.js b/4chan_x.js index adfe98434..0ed28b461 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -472,27 +472,34 @@ _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { a = _ref[_i]; - _results.push($.bind(a, 'click', expandComment.cb.expand)); + _results.push($.bind(a, 'click', expandComment.expand)); } return _results; }, - cb: { - expand: function(e) { - var a, href, replyID, threadID, _, _ref; - e.preventDefault(); + expand: function(e) { + var a, replyID, req, threadID, _, _ref; + e.preventDefault(); + _ref = this.href.match(/(\d+)#(\d+)/), _ = _ref[0], threadID = _ref[1], replyID = _ref[2]; + this.textContent = "Loading " + replyID + "..."; + if (req = g.requests[threadID]) { + if (req.readyState === 4) { + return expandComment.parse(req, this, threadID, replyID); + } + } else { a = this; - a.textContent = 'Loading...'; - href = a.getAttribute('href'); - _ref = href.match(/(\d+)#(\d+)/), _ = _ref[0], threadID = _ref[1], replyID = _ref[2]; - return g.cache[threadID] = $.get(href, (function() { - return expandComment.load(this, a, threadID, replyID); + return g.requests[threadID] = $.get(this.href, (function() { + return expandComment.parse(this, a, threadID, replyID); })); } }, - load: function(xhr, a, threadID, replyID) { + parse: function(req, a, threadID, replyID) { var body, bq, reply, _i, _len, _ref; + if (req.status !== 200) { + a.textContent = "" + req.status + " " + req.statusText; + return; + } body = $.el('body', { - innerHTML: xhr.responseText + innerHTML: req.responseText }); if (threadID === replyID) { bq = $('blockquote', body); diff --git a/script.coffee b/script.coffee index 7b92c6dd2..29e058890 100644 --- a/script.coffee +++ b/script.coffee @@ -329,22 +329,26 @@ $$ = (selector, root=d.body) -> expandComment = init: -> for a in $$ 'span.abbr a' - $.bind a, 'click', expandComment.cb.expand - - cb: - expand: (e) -> - e.preventDefault() + $.bind a, 'click', expandComment.expand + expand: (e) -> + e.preventDefault() + [_, threadID, replyID] = @href.match /(\d+)#(\d+)/ + @textContent = "Loading #{replyID}..." + if req = g.requests[threadID] + if req.readyState is 4 + expandComment.parse req, this, threadID, replyID + else a = this - a.textContent = 'Loading...' - href = a.getAttribute 'href' - [_, threadID, replyID] = href.match /(\d+)#(\d+)/ - g.cache[threadID] = $.get href, (-> - expandComment.load this, a, threadID, replyID) - load: (xhr, a, threadID, replyID) -> - body = $.el 'body', - innerHTML: xhr.responseText + g.requests[threadID] = $.get @href, (-> expandComment.parse this, a, threadID, replyID) + parse: (req, a, threadID, replyID) -> + if req.status isnt 200 + a.textContent = "#{req.status} #{req.statusText}" + return - if threadID is replyID + body = $.el 'body', + innerHTML: req.responseText + + if threadID is replyID #OP bq = $ 'blockquote', body else #css selectors don't like ids starting with numbers, From 749732accc0558cff4b61e578d2667126d580ad9 Mon Sep 17 00:00:00 2001 From: James Campos Date: Sat, 14 May 2011 10:11:52 -0700 Subject: [PATCH 06/14] expandThread: g.cache -> g.requests --- 4chan_x.js | 35 +++++++++++++++-------------------- script.coffee | 29 ++++++++++++----------------- 2 files changed, 27 insertions(+), 37 deletions(-) diff --git a/4chan_x.js b/4chan_x.js index 0ed28b461..cea6cf21b 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -537,32 +537,22 @@ var thread; thread = this.parentNode; return expandThread.toggle(thread); - }, - load: function(xhr, thread, a) { - var html, id; - if (xhr.status === 404) { - a.textContent.replace('X Loading...', '404'); - return $.unbind(a, 'click', expandThread.cb.toggle); - } else { - html = xhr.responseText; - id = thread.firstChild.id; - g.cache[id] = html; - return expandThread.expand(html, thread, a); - } } }, toggle: function(thread) { - var a, html, id, num, prev, table, _results; - id = thread.firstChild.id; + var a, num, prev, req, table, threadID, _results; + threadID = thread.firstChild.id; a = $('a.omittedposts', thread); switch (a.textContent[0]) { case '+': a.textContent = a.textContent.replace('+', 'X Loading...'); - if (html = g.cache[id]) { - return expandThread.expand(html, thread, a); + if (req = g.requests[threadID]) { + if (req.readyState === 4) { + return expandThread.parse(req, thread, a); + } } else { - return g.requests[id] = $.get("res/" + id, (function() { - return expandThread.cb.load(this, thread, a); + return g.requests[threadID] = $.get("res/" + threadID, (function() { + return expandThread.parse(this, thread, a); })); } break; @@ -580,15 +570,20 @@ return _results; } }, - expand: function(html, thread, a) { + parse: function(req, thread, a) { var body, br, next, table, tables, _i, _len, _results; + if (req.status !== 200) { + a.textContent = "" + req.status + " " + req.statusText; + $.unbind(a, 'click', expandThread.cb.toggle); + return; + } a.textContent = a.textContent.replace('X Loading...', '-'); while ((next = a.nextSibling) && !next.clear) { $.rm(next); } br = next; body = $.el('body', { - innerHTML: html + innerHTML: req.responseText }); tables = $$('form[name=delform] table', body); tables.pop(); diff --git a/script.coffee b/script.coffee index 29e058890..722ab5d0b 100644 --- a/script.coffee +++ b/script.coffee @@ -373,28 +373,18 @@ expandThread = thread = @parentNode expandThread.toggle thread - load: (xhr, thread, a) -> - if xhr.status is 404 - a.textContent.replace 'X Loading...', '404' - $.unbind a, 'click', expandThread.cb.toggle - else - html = xhr.responseText - id = thread.firstChild.id - g.cache[id] = html - expandThread.expand html, thread, a - toggle: (thread) -> - id = thread.firstChild.id + threadID = thread.firstChild.id a = $ 'a.omittedposts', thread switch a.textContent[0] when '+' a.textContent = a.textContent.replace '+', 'X Loading...' - if html = g.cache[id] - expandThread.expand html, thread, a + if req = g.requests[threadID] + if req.readyState is 4 + expandThread.parse req, thread, a else - g.requests[id] = - $.get "res/#{id}", (-> expandThread.cb.load this, thread, a) + g.requests[threadID] = $.get "res/#{threadID}", (-> expandThread.parse this, thread, a) when 'X' a.textContent = a.textContent.replace 'X Loading...', '+' @@ -408,7 +398,12 @@ expandThread = while (prev = table.previousSibling) and (prev.nodeName is 'TABLE') $.rm prev - expand: (html, thread, a) -> + parse: (req, thread, a) -> + if req.status isnt 200 + a.textContent = "#{req.status} #{req.statusText}" + $.unbind a, 'click', expandThread.cb.toggle + return + a.textContent = a.textContent.replace 'X Loading...', '-' # eat everything, then replace with fresh full posts @@ -417,7 +412,7 @@ expandThread = br = next body = $.el 'body', - innerHTML: html + innerHTML: req.responseText tables = $$ 'form[name=delform] table', body tables.pop() From aaa74623850e5f634f042721b811db652412b61b Mon Sep 17 00:00:00 2001 From: James Campos Date: Sat, 14 May 2011 10:12:11 -0700 Subject: [PATCH 07/14] rm g.cache --- 4chan_x.js | 1 - script.coffee | 1 - 2 files changed, 2 deletions(-) diff --git a/4chan_x.js b/4chan_x.js index cea6cf21b..316224efb 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -2265,7 +2265,6 @@ }; NAMESPACE = 'AEOS.4chan_x.'; g = { - cache: {}, requests: {}, callbacks: [] }; diff --git a/script.coffee b/script.coffee index 722ab5d0b..a4945dbd2 100644 --- a/script.coffee +++ b/script.coffee @@ -1740,7 +1740,6 @@ imgExpand = #main NAMESPACE = 'AEOS.4chan_x.' g = - cache: {} requests: {} callbacks: [] From 484b2f4eb9b94c0a192311fce2f3c006b68be283 Mon Sep 17 00:00:00 2001 From: James Campos Date: Sat, 14 May 2011 10:23:40 -0700 Subject: [PATCH 08/14] comment --- script.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script.coffee b/script.coffee index a4945dbd2..c2dc07cde 100644 --- a/script.coffee +++ b/script.coffee @@ -54,7 +54,7 @@ config = 'Interval': 30 # FIXME this is fucking horrible -# create 'global' options, no namespacing +# flatten the config _config = {} ((parent, obj) -> if obj.length #array From 71beb609d35457de2c7827d0720d3acf38653faf Mon Sep 17 00:00:00 2001 From: James Campos Date: Sat, 14 May 2011 10:29:12 -0700 Subject: [PATCH 09/14] ui.dialog: rm string position aliases --- 4chan_x.js | 26 +------------------------- script.coffee | 20 +------------------- 2 files changed, 2 insertions(+), 44 deletions(-) diff --git a/4chan_x.js b/4chan_x.js index 316224efb..6ca55ab67 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -136,31 +136,7 @@ el.className = 'reply dialog'; el.innerHTML = html; el.id = id; - if (typeof position === 'object') { - left = position.left, top = position.top; - } else { - switch (position) { - case 'topleft': - left = '0px'; - top = '0px'; - break; - case 'topright': - left = null; - top = '0px'; - break; - case 'bottomleft': - left = '0px'; - top = null; - break; - case 'bottomright': - left = null; - top = null; - break; - case 'center': - left = '50%'; - top = '25%'; - } - } + left = position.left, top = position.top; left = (_ref = localStorage["" + id + "Left"]) != null ? _ref : left; top = (_ref2 = localStorage["" + id + "Top"]) != null ? _ref2 : top; if (left) { diff --git a/script.coffee b/script.coffee index c2dc07cde..6b118a3bf 100644 --- a/script.coffee +++ b/script.coffee @@ -75,25 +75,7 @@ ui = el.className = 'reply dialog' el.innerHTML = html el.id = id - if typeof position is 'object' - {left, top} = position - else - switch position - when 'topleft' - left = '0px' - top = '0px' - when 'topright' - left = null - top = '0px' - when 'bottomleft' - left = '0px' - top = null - when 'bottomright' - left = null - top = null - when 'center' - left = '50%' - top = '25%' + {left, top} = position left = localStorage["#{id}Left"] ? left top = localStorage["#{id}Top"] ? top if left then el.style.left = left else el.style.right = '0px' From 4767e982719ec37c705bb1a866000df103516866 Mon Sep 17 00:00:00 2001 From: James Campos Date: Sat, 14 May 2011 10:52:04 -0700 Subject: [PATCH 10/14] return sooner --- 4chan_x.js | 9 ++++----- script.coffee | 9 ++++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/4chan_x.js b/4chan_x.js index 6ca55ab67..6e0015bc8 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -1746,16 +1746,15 @@ }, parse: function(req, id, threadID, oldInline) { var body, html, inline, op, reply, td, _i, _len, _ref; + if (req.status !== 200) { + oldInline.innerHTML = "" + req.status + " " + req.statusText; + return; + } inline = $.el('table', { className: 'inline', innerHTML: '' }); td = $('td', inline); - if (req.status !== 200) { - td.innerHTML = "" + req.status + " " + req.statusText; - $.replace(oldInline, inline); - return; - } body = $.el('body', { innerHTML: req.responseText }); diff --git a/script.coffee b/script.coffee index 6b118a3bf..11b86accf 100644 --- a/script.coffee +++ b/script.coffee @@ -1387,17 +1387,16 @@ quoteInline = g.requests[threadID] = $.get @href, (-> quoteInline.parse this, id, threadID, inline) $.after @parentNode, inline parse: (req, id, threadID, oldInline) -> + if req.status isnt 200 + oldInline.innerHTML = "#{req.status} #{req.statusText}" + return + #this is fucking stupid inline = $.el 'table', className: 'inline' innerHTML: '' td = $ 'td', inline - if req.status isnt 200 - td.innerHTML = "#{req.status} #{req.statusText}" - $.replace oldInline, inline - return - body = $.el 'body', innerHTML: req.responseText if id == threadID #OP From 81280dd5485c5b3e9a42c49f27a2042bbb0f2afc Mon Sep 17 00:00:00 2001 From: James Campos Date: Sat, 14 May 2011 10:57:26 -0700 Subject: [PATCH 11/14] hash[1..] --- 4chan_x.js | 6 ++---- script.coffee | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/4chan_x.js b/4chan_x.js index 6e0015bc8..df5464068 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -1667,10 +1667,9 @@ _ref = $$('a.quotelink', root); for (_i = 0, _len = _ref.length; _i < _len; _i++) { quote = _ref[_i]; - if (!(qid = quote.textContent.match(/\d+/))) { + if (!(qid = quote.hash.slice(1))) { continue; } - qid = qid[0]; if (qid === tid) { continue; } @@ -1800,10 +1799,9 @@ }, mouseover: function(e) { var el, id, qp, req, threadID; - if (!(id = this.textContent.match(/\d+/))) { + if (!(id = this.hash.slice(1))) { return; } - id = id[0]; qp = $('#qp'); if (el = d.getElementById(id)) { qp.innerHTML = el.innerHTML; diff --git a/script.coffee b/script.coffee index 11b86accf..66f4a9ade 100644 --- a/script.coffee +++ b/script.coffee @@ -1337,8 +1337,7 @@ quoteBacklink = quotes = {} tid = g.THREAD_ID for quote in $$ 'a.quotelink', root - continue unless qid = quote.textContent.match /\d+/ - [qid] = qid + continue unless qid = quote.hash[1..] #don't backlink the op continue if qid == tid #duplicate quotes get overwritten @@ -1424,8 +1423,7 @@ quotePreview = $.bind quote, 'mousemove', ui.hover $.bind quote, 'mouseout', ui.hoverend mouseover: (e) -> - return unless id = @textContent.match /\d+/ - [id] = id + return unless id = @hash[1..] qp = $ '#qp' if el = d.getElementById id qp.innerHTML = el.innerHTML From ed9d2770ff7b56ccf13323fbf70c3ff97004b7c5 Mon Sep 17 00:00:00 2001 From: James Campos Date: Sat, 14 May 2011 11:29:58 -0700 Subject: [PATCH 12/14] ihover fit height, thank you anonymous --- 4chan_x.js | 5 +++++ script.coffee | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/4chan_x.js b/4chan_x.js index df5464068..d3aca177c 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -2440,6 +2440,11 @@ #qp, #iHover {\ position: fixed;\ }\ +\ + #iHover {\ + width: auto;\ + max-height: 100%;\ + }\ \ #navlinks {\ position: fixed;\ diff --git a/script.coffee b/script.coffee index 66f4a9ade..39a2f34f5 100644 --- a/script.coffee +++ b/script.coffee @@ -1908,6 +1908,11 @@ main = position: fixed; } + #iHover { + width: auto; + max-height: 100%; + } + #navlinks { position: fixed; top: 25px; From 59ce7274b82e37401e7b6ed3bd69a0eb6a55b006 Mon Sep 17 00:00:00 2001 From: James Campos Date: Sat, 14 May 2011 12:34:26 -0700 Subject: [PATCH 13/14] inline backlinks, pig disgusting xpath --- 4chan_x.js | 30 +++++++++++++++++++++++------- script.coffee | 23 +++++++++++++++++------ 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/4chan_x.js b/4chan_x.js index d3aca177c..7586543c3 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -1661,6 +1661,9 @@ }, node: function(root) { var el, id, link, qid, quote, quotes, tid, _i, _len, _ref, _results; + if (root.className === 'inline') { + return; + } id = root.id || $('td[id]', root).id; quotes = {}; tid = g.THREAD_ID; @@ -1691,6 +1694,9 @@ $.bind(link, 'mousemove', ui.hover); $.bind(link, 'mouseout', ui.hoverend); } + if ($.config('Quote Inline')) { + $.bind(link, 'click', quoteInline.toggle); + } _results.push($.before($('td > br, blockquote', el), link)); } return _results; @@ -1702,7 +1708,7 @@ }, node: function(root) { var quote, _i, _len, _ref, _results; - _ref = $$('a.quotelink', root); + _ref = $$('a.quotelink, a.backlink', root); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { quote = _ref[_i]; @@ -1712,18 +1718,22 @@ return _results; }, toggle: function(e) { - var el, id, inline, next, req, td, threadID; + var el, id, inline, req, root, td, threadID; e.preventDefault(); if (!(id = this.hash.slice(1))) { return; } - if ((next = this.parentNode.nextSibling) && (next.nodeName === 'TABLE')) { - $.rm(next); + root = $.x('ancestor::td[1]', this); + if (td = $("#i" + id, root)) { + $.rm($.x('ancestor::table[1]', td)); + if (this.className === 'backlink') { + $.show($.x('ancestor::table[1]', d.getElementById(id))); + } return; } inline = $.el('table', { className: 'inline', - innerHTML: '' + innerHTML: "" }); td = $('td', inline); if (el = d.getElementById(id)) { @@ -1741,7 +1751,13 @@ })); } } - return $.after(this.parentNode, inline); + if (this.className === 'backlink') { + root = $('table, blockquote', root); + $.before(root, inline); + return $.hide($.x('ancestor::table[1]', el)); + } else { + return $.after(this.parentNode, inline); + } }, parse: function(req, id, threadID, oldInline) { var body, html, inline, op, reply, td, _i, _len, _ref; @@ -1787,7 +1803,7 @@ }, node: function(root) { var quote, _i, _len, _ref, _results; - _ref = $$('a.quotelink', root); + _ref = $$('a.quotelink, a.backlink', root); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { quote = _ref[_i]; diff --git a/script.coffee b/script.coffee index 39a2f34f5..b346738e6 100644 --- a/script.coffee +++ b/script.coffee @@ -1332,6 +1332,7 @@ quoteBacklink = init: -> g.callbacks.push quoteBacklink.node node: (root) -> + return if root.className is 'inline' #better coffee-script way of doing this? id = root.id or $('td[id]', root).id quotes = {} @@ -1352,24 +1353,29 @@ quoteBacklink = $.bind link, 'mouseover', quotePreview.mouseover $.bind link, 'mousemove', ui.hover $.bind link, 'mouseout', ui.hoverend + if $.config 'Quote Inline' + $.bind link, 'click', quoteInline.toggle $.before $('td > br, blockquote', el), link quoteInline = init: -> g.callbacks.push quoteInline.node node: (root) -> - for quote in $$ 'a.quotelink', root + for quote in $$ 'a.quotelink, a.backlink', root quote.removeAttribute 'onclick' $.bind quote, 'click', quoteInline.toggle toggle: (e) -> e.preventDefault() return unless id = @hash[1..] - if (next = @parentNode.nextSibling) and (next.nodeName is 'TABLE') - $.rm next + root = $.x 'ancestor::td[1]', this + if td = $ "#i#{id}", root + $.rm $.x 'ancestor::table[1]', td + if @className is 'backlink' + $.show $.x 'ancestor::table[1]', d.getElementById id return inline = $.el 'table', className: 'inline' - innerHTML: '' + innerHTML: "" td = $ 'td', inline if el = d.getElementById id td.innerHTML = el.innerHTML @@ -1384,7 +1390,12 @@ quoteInline = else #FIXME need an array of callbacks g.requests[threadID] = $.get @href, (-> quoteInline.parse this, id, threadID, inline) - $.after @parentNode, inline + if @className is 'backlink' + root = $ 'table, blockquote', root + $.before root, inline + $.hide $.x 'ancestor::table[1]', el + else + $.after @parentNode, inline parse: (req, id, threadID, oldInline) -> if req.status isnt 200 oldInline.innerHTML = "#{req.status} #{req.statusText}" @@ -1418,7 +1429,7 @@ quotePreview = $.hide preview $.append d.body, preview node: (root) -> - for quote in $$ 'a.quotelink', root + for quote in $$ 'a.quotelink, a.backlink', root $.bind quote, 'mouseover', quotePreview.mouseover $.bind quote, 'mousemove', ui.hover $.bind quote, 'mouseout', ui.hoverend From 31ae62313f6a6d01184942b48ddfa94834318b2a Mon Sep 17 00:00:00 2001 From: James Campos Date: Sat, 14 May 2011 12:38:43 -0700 Subject: [PATCH 14/14] 2.7.0 --- 4chan_x.js | 2 +- changelog | 10 ++++++++++ header | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/4chan_x.js b/4chan_x.js index 7586543c3..ae84350f9 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -2,7 +2,7 @@ // @name 4chan x // @namespace aeosynth // @description Adds various features. -// @version 2.6.0 +// @version 2.7.0 // @copyright 2009-2011 James Campos // @license MIT; http://en.wikipedia.org/wiki/Mit_license // @include http://boards.4chan.org/* diff --git a/changelog b/changelog index 2a93e56bd..349cfb1aa 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,13 @@ +2.7.0 +- mayhem: + add class to reply hider and report buttons + fix anonymizer +- inline quoting +- don't break on >>>/board/ links (links w/o an id) +- remove op backlinking +- fix qr on expanded posts +- image hover: fit height + 2.6.0 - mayhem: start backlinks diff --git a/header b/header index 6fd6fa7eb..938ab80b1 100644 --- a/header +++ b/header @@ -2,7 +2,7 @@ // @name 4chan x // @namespace aeosynth // @description Adds various features. -// @version 2.6.0 +// @version 2.7.0 // @copyright 2009-2011 James Campos // @license MIT; http://en.wikipedia.org/wiki/Mit_license // @include http://boards.4chan.org/*