diff --git a/4chan_x.js b/4chan_x.js index 01ac64089..8a2999551 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -1689,14 +1689,23 @@ return _results; }, mouseover: function(e) { - var el, id, qp; + var el, html, id, qp, threadID; id = this.textContent.replace(">>", ''); qp = $('#qp'); if (el = d.getElementById(id)) { qp.innerHTML = el.innerHTML; } else { - qp.innerHTML = 'Loading...'; - quotePreview.get(this, id); + threadID = this.pathname.split('/').pop(); + if (html = g.cache[threadID]) { + quotePreview.get(id, threadID, html); + } else { + qp.innerHTML = 'Loading...'; + $.get(this.href, (function() { + html = this.responseText; + g.cache[threadID] = html; + return quotePreview.get(id, threadID, html); + })); + } } $.show(qp); return ui.el = qp; @@ -1704,26 +1713,24 @@ mouseout: function(e) { return $.hide(ui.el); }, - get: function(link, id) { - return $.get(link.href, (function() { - return quotePreview.get2(link, id, this); - })); - }, - get2: function(link, id, xhr) { - var body, reply, _i, _len, _ref, _results; + get: function(id, threadID, innerHTML) { + var body, html, reply, _i, _len, _ref; body = $.el('body', { - innerHTML: xhr.responseText + innerHTML: innerHTML }); - _ref = $$('td.reply', body); - _results = []; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - reply = _ref[_i]; - if (reply.id === id) { - ui.el.innerHTML = reply.innerHTML; - break; + if (id === threadID) { + html = $('blockquote', body).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; + } } } - return _results; + return ui.el.innerHTML = html; } }; quickReport = { diff --git a/script.coffee b/script.coffee index 06fdb125e..779aaa399 100644 --- a/script.coffee +++ b/script.coffee @@ -1352,22 +1352,32 @@ quotePreview = if el = d.getElementById id qp.innerHTML = el.innerHTML else - qp.innerHTML = 'Loading...' - quotePreview.get this, id + threadID = @pathname.split('/').pop() + if html = g.cache[threadID] + quotePreview.get id, threadID, html + else + qp.innerHTML = 'Loading...' + $.get @href, (-> + html = @responseText + g.cache[threadID] = html + quotePreview.get id, threadID, html + ) $.show qp ui.el = qp mouseout: (e) -> $.hide ui.el - get: (link, id) -> - $.get link.href, (-> quotePreview.get2 link, id, this) - get2: (link, id, xhr) -> - body = $.el 'body', - innerHTML: xhr.responseText + get: (id, threadID, innerHTML) -> + body = $.el 'body', {innerHTML} - for reply in $$ 'td.reply', body - if reply.id == id - ui.el.innerHTML = reply.innerHTML - break + if id == threadID #OP + html = $('blockquote', body).innerHTML + else + for reply in $$ 'td.reply', body + if reply.id == id + html = reply.innerHTML + break + + ui.el.innerHTML = html quickReport = init: ->