Thread Expansions fix and improvement.

This commit is contained in:
Nicolas Stepien 2012-05-01 18:41:44 +02:00
parent 6ffa33bd67
commit 7751f7abd1
2 changed files with 16 additions and 14 deletions

View File

@ -837,12 +837,12 @@
return _results; return _results;
}, },
toggle: function(thread) { toggle: function(thread) {
var a, backlink, container, div, next, num, pathname, _i, _len, _ref, _results; var a, backlink, container, num, pathname, replies, reply, _i, _j, _len, _len1, _ref, _results;
pathname = "/" + g.BOARD + "/res/" + thread.id.slice(1); pathname = "/" + g.BOARD + "/res/" + thread.id.slice(1);
a = $('.summary', thread); a = $('.summary', thread);
switch (a.textContent[0]) { switch (a.textContent[0]) {
case '+': case '+':
if (container = $('.container', thread.firstElementChild)) { if (container = $('.container', a.previousElementSibling)) {
$.rm(container); $.rm(container);
} }
a.textContent = a.textContent.replace('+', '\u00d7 Loading...'); a.textContent = a.textContent.replace('+', '\u00d7 Loading...');
@ -865,14 +865,16 @@
return 5; return 5;
} }
})(); })();
div = $.x("following-sibling::div[last()]/preceding-sibling::div[" + (num - 1) + "]", a); replies = $$('.replyContainer', thread);
while ((next = a.nextSibling) && next !== div) { replies.splice(replies.length - num, num);
$.rm(next); for (_i = 0, _len = replies.length; _i < _len; _i++) {
reply = replies[_i];
$.rm(reply);
} }
_ref = $$('.backlink', a.previousElementSibling); _ref = $$('.backlink', a.previousElementSibling);
_results = []; _results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
backlink = _ref[_i]; backlink = _ref[_j];
if (!$.id(backlink.hash.slice(1))) { if (!$.id(backlink.hash.slice(1))) {
_results.push($.rm(backlink)); _results.push($.rm(backlink));
} else { } else {
@ -4130,7 +4132,7 @@
}, },
preParse: function(node) { preParse: function(node) {
var el, fileInfo, img, klass, post; var el, fileInfo, img, klass, post;
el = node.lastElementChild; el = $('.post', node);
klass = el.className; klass = el.className;
post = { post = {
root: node, root: node,

View File

@ -667,7 +667,7 @@ ExpandThread =
switch a.textContent[0] switch a.textContent[0]
when '+' when '+'
if container = $ '.container', thread.firstElementChild if container = $ '.container', a.previousElementSibling
$.rm container $.rm container
a.textContent = a.textContent.replace '+', '\u00d7 Loading...' a.textContent = a.textContent.replace '+', '\u00d7 Loading...'
$.cache pathname, -> ExpandThread.parse @, pathname, thread, a $.cache pathname, -> ExpandThread.parse @, pathname, thread, a
@ -683,13 +683,13 @@ ExpandThread =
when 'b', 'vg' then 3 when 'b', 'vg' then 3
when 't' then 1 when 't' then 1
else 5 else 5
div = $.x "following-sibling::div[last()]/preceding-sibling::div[#{num - 1}]", a replies = $$ '.replyContainer', thread
while (next = a.nextSibling) and next isnt div replies.splice replies.length - num, num
$.rm next for reply in replies
$.rm reply
for backlink in $$ '.backlink', a.previousElementSibling for backlink in $$ '.backlink', a.previousElementSibling
$.rm backlink unless $.id backlink.hash[1..] $.rm backlink unless $.id backlink.hash[1..]
parse: (req, pathname, thread, a) -> parse: (req, pathname, thread, a) ->
if req.status isnt 200 if req.status isnt 200
a.textContent = "#{req.status} #{req.statusText}" a.textContent = "#{req.status} #{req.statusText}"
@ -3171,7 +3171,7 @@ Main =
window.location = "https://raw.github.com/mayhemydg/4chan-x/#{version}/4chan_x.user.js" window.location = "https://raw.github.com/mayhemydg/4chan-x/#{version}/4chan_x.user.js"
preParse: (node) -> preParse: (node) ->
el = node.lastElementChild el = $ '.post', node
klass = el.className klass = el.className
post = post =
root: node root: node