Use d.implementation.createHTMLDocument() to parse ajax thread responses.
Doing so prevents the browser from loading every single elements such as images/scripts/css/etc, which means less network/cache IO, which is good.
This commit is contained in:
parent
07e313b5cb
commit
9c00ad71a4
@ -838,21 +838,21 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
parse: function(req, pathname, thread, a) {
|
parse: function(req, pathname, thread, a) {
|
||||||
var body, href, link, next, nodes, quote, reply, _i, _j, _len, _len2, _ref, _ref2;
|
var doc, href, link, next, nodes, quote, reply, table, _i, _j, _len, _len2, _ref, _ref2;
|
||||||
if (req.status !== 200) {
|
if (req.status !== 200) {
|
||||||
a.textContent = "" + req.status + " " + req.statusText;
|
a.textContent = "" + req.status + " " + req.statusText;
|
||||||
$.off(a, 'click', ExpandThread.cb.toggle);
|
$.off(a, 'click', ExpandThread.cb.toggle);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
a.textContent = a.textContent.replace('\u00d7 Loading...', '-');
|
a.textContent = a.textContent.replace('\u00d7 Loading...', '-');
|
||||||
body = $.el('body', {
|
doc = d.implementation.createHTMLDocument(null);
|
||||||
innerHTML: req.responseText
|
doc.documentElement.innerHTML = req.responseText;
|
||||||
});
|
|
||||||
nodes = [];
|
nodes = [];
|
||||||
_ref = $$('.reply', body);
|
_ref = $$('.reply', doc);
|
||||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||||
reply = _ref[_i];
|
reply = _ref[_i];
|
||||||
_ref2 = $$('.quotelink', reply);
|
table = d.importNode(reply.parentNode.parentNode.parentNode);
|
||||||
|
_ref2 = $$('.quotelink', table);
|
||||||
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
|
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
|
||||||
quote = _ref2[_j];
|
quote = _ref2[_j];
|
||||||
if ((href = quote.getAttribute('href')) === quote.hash) {
|
if ((href = quote.getAttribute('href')) === quote.hash) {
|
||||||
@ -861,10 +861,10 @@
|
|||||||
quote.href = "res/" + href;
|
quote.href = "res/" + href;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
link = $('.quotejs', reply);
|
link = $('.quotejs', table);
|
||||||
link.href = "res/" + thread.firstChild.id + "#" + reply.id;
|
link.href = "res/" + thread.firstChild.id + "#" + reply.id;
|
||||||
link.nextSibling.href = "res/" + thread.firstChild.id + "#q" + reply.id;
|
link.nextSibling.href = "res/" + thread.firstChild.id + "#q" + reply.id;
|
||||||
nodes.push(reply.parentNode.parentNode.parentNode);
|
nodes.push(table);
|
||||||
}
|
}
|
||||||
while ((next = a.nextSibling) && !next.clear) {
|
while ((next = a.nextSibling) && !next.clear) {
|
||||||
$.rm(next);
|
$.rm(next);
|
||||||
@ -2562,7 +2562,7 @@
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
update: function() {
|
update: function() {
|
||||||
var body, id, newPosts, nodes, reply, scroll, _i, _len, _ref;
|
var doc, id, newPosts, nodes, reply, scroll, _i, _len, _ref;
|
||||||
if (this.status === 404) {
|
if (this.status === 404) {
|
||||||
Updater.timer.textContent = '';
|
Updater.timer.textContent = '';
|
||||||
Updater.count.textContent = 404;
|
Updater.count.textContent = 404;
|
||||||
@ -2598,12 +2598,11 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Updater.lastModified = this.getResponseHeader('Last-Modified');
|
Updater.lastModified = this.getResponseHeader('Last-Modified');
|
||||||
body = $.el('body', {
|
doc = d.implementation.createHTMLDocument(null);
|
||||||
innerHTML: this.responseText
|
doc.documentElement.innerHTML = this.responseText;
|
||||||
});
|
|
||||||
id = $('input', Updater.br.previousElementSibling).name;
|
id = $('input', Updater.br.previousElementSibling).name;
|
||||||
nodes = [];
|
nodes = [];
|
||||||
_ref = $$('.reply', body).reverse();
|
_ref = $$('.reply', doc).reverse();
|
||||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||||
reply = _ref[_i];
|
reply = _ref[_i];
|
||||||
if (reply.id <= id) break;
|
if (reply.id <= id) break;
|
||||||
|
|||||||
@ -721,20 +721,21 @@ ExpandThread =
|
|||||||
|
|
||||||
a.textContent = a.textContent.replace '\u00d7 Loading...', '-'
|
a.textContent = a.textContent.replace '\u00d7 Loading...', '-'
|
||||||
|
|
||||||
body = $.el 'body',
|
doc = d.implementation.createHTMLDocument null
|
||||||
innerHTML: req.responseText
|
doc.documentElement.innerHTML = req.responseText
|
||||||
|
|
||||||
nodes = []
|
nodes = []
|
||||||
for reply in $$ '.reply', body
|
for reply in $$ '.reply', doc
|
||||||
for quote in $$ '.quotelink', reply
|
table = d.importNode reply.parentNode.parentNode.parentNode
|
||||||
|
for quote in $$ '.quotelink', table
|
||||||
if (href = quote.getAttribute('href')) is quote.hash #add pathname to normal quotes
|
if (href = quote.getAttribute('href')) is quote.hash #add pathname to normal quotes
|
||||||
quote.pathname = pathname
|
quote.pathname = pathname
|
||||||
else if href isnt quote.href #fix x-thread links, not x-board ones
|
else if href isnt quote.href #fix x-thread links, not x-board ones
|
||||||
quote.href = "res/#{href}"
|
quote.href = "res/#{href}"
|
||||||
link = $ '.quotejs', reply
|
link = $ '.quotejs', table
|
||||||
link.href = "res/#{thread.firstChild.id}##{reply.id}"
|
link.href = "res/#{thread.firstChild.id}##{reply.id}"
|
||||||
link.nextSibling.href = "res/#{thread.firstChild.id}#q#{reply.id}"
|
link.nextSibling.href = "res/#{thread.firstChild.id}#q#{reply.id}"
|
||||||
nodes.push reply.parentNode.parentNode.parentNode
|
nodes.push table
|
||||||
# eat everything, then replace with fresh full posts
|
# eat everything, then replace with fresh full posts
|
||||||
while (next = a.nextSibling) and not next.clear #br[clear]
|
while (next = a.nextSibling) and not next.clear #br[clear]
|
||||||
$.rm next
|
$.rm next
|
||||||
@ -2201,12 +2202,12 @@ Updater =
|
|||||||
return
|
return
|
||||||
Updater.lastModified = @getResponseHeader 'Last-Modified'
|
Updater.lastModified = @getResponseHeader 'Last-Modified'
|
||||||
|
|
||||||
body = $.el 'body',
|
doc = d.implementation.createHTMLDocument null
|
||||||
innerHTML: @responseText
|
doc.documentElement.innerHTML = @responseText
|
||||||
|
|
||||||
id = $('input', Updater.br.previousElementSibling).name
|
id = $('input', Updater.br.previousElementSibling).name
|
||||||
nodes = []
|
nodes = []
|
||||||
for reply in $$('.reply', body).reverse()
|
for reply in $$('.reply', doc).reverse()
|
||||||
break if reply.id <= id #make sure to not insert older posts
|
break if reply.id <= id #make sure to not insert older posts
|
||||||
nodes.push reply.parentNode.parentNode.parentNode #table
|
nodes.push reply.parentNode.parentNode.parentNode #table
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user