Use 4chan's API for comment expansion.
This commit is contained in:
parent
d846449d19
commit
d94d09ebaa
@ -858,24 +858,35 @@
|
|||||||
var a, replyID, threadID, _, _ref;
|
var a, replyID, threadID, _, _ref;
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
_ref = this.href.match(/(\d+)#p(\d+)/), _ = _ref[0], threadID = _ref[1], replyID = _ref[2];
|
_ref = this.href.match(/(\d+)#p(\d+)/), _ = _ref[0], threadID = _ref[1], replyID = _ref[2];
|
||||||
this.textContent = "Loading " + replyID + "...";
|
this.textContent = "Loading No." + replyID + "...";
|
||||||
a = this;
|
a = this;
|
||||||
return $.cache(this.pathname, function() {
|
return $.cache("//api.4chan.org" + this.pathname + ".json", function() {
|
||||||
return ExpandComment.parse(this, a, threadID, replyID);
|
return ExpandComment.parse(this, a, threadID, replyID);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
parse: function(req, a, threadID, replyID) {
|
parse: function(req, a, threadID, replyID) {
|
||||||
var doc, href, node, post, quote, quotes, _i, _len;
|
var bq, href, post, posts, quote, quotes, _i, _j, _len, _len1;
|
||||||
if (req.status !== 200) {
|
if (req.status !== 200) {
|
||||||
a.textContent = "" + req.status + " " + req.statusText;
|
a.textContent = "" + req.status + " " + req.statusText;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
doc = d.implementation.createHTMLDocument('');
|
posts = JSON.parse(req.response).posts;
|
||||||
doc.documentElement.innerHTML = req.response;
|
replyID = +replyID;
|
||||||
node = d.importNode(doc.getElementById("m" + replyID), true);
|
for (_i = 0, _len = posts.length; _i < _len; _i++) {
|
||||||
quotes = node.getElementsByClassName('quotelink');
|
post = posts[_i];
|
||||||
for (_i = 0, _len = quotes.length; _i < _len; _i++) {
|
if (post.no === replyID) {
|
||||||
quote = quotes[_i];
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (post.no !== replyID) {
|
||||||
|
a.textContent = 'No.#{replyID} not found.';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
bq = $.id("m" + replyID);
|
||||||
|
bq.innerHTML = post.com;
|
||||||
|
quotes = bq.getElementsByClassName('quotelink');
|
||||||
|
for (_j = 0, _len1 = quotes.length; _j < _len1; _j++) {
|
||||||
|
quote = quotes[_j];
|
||||||
href = quote.getAttribute('href');
|
href = quote.getAttribute('href');
|
||||||
if (href[0] === '/') {
|
if (href[0] === '/') {
|
||||||
continue;
|
continue;
|
||||||
@ -883,7 +894,7 @@
|
|||||||
quote.href = "res/" + href;
|
quote.href = "res/" + href;
|
||||||
}
|
}
|
||||||
post = {
|
post = {
|
||||||
blockquote: node,
|
blockquote: bq,
|
||||||
threadID: threadID,
|
threadID: threadID,
|
||||||
quotes: quotes,
|
quotes: quotes,
|
||||||
backlinks: []
|
backlinks: []
|
||||||
@ -903,8 +914,7 @@
|
|||||||
if (Conf['Indicate Cross-thread Quotes']) {
|
if (Conf['Indicate Cross-thread Quotes']) {
|
||||||
QuoteCT.node(post);
|
QuoteCT.node(post);
|
||||||
}
|
}
|
||||||
$.replace(a.parentNode.parentNode, node);
|
return Main.prettify(bq);
|
||||||
return Main.prettify(node);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,7 @@ master
|
|||||||
- Thread Updater.
|
- Thread Updater.
|
||||||
- Quote Inlining.
|
- Quote Inlining.
|
||||||
- Quote Previewing.
|
- Quote Previewing.
|
||||||
|
- Comment Expansion.
|
||||||
|
|
||||||
2.34.10
|
2.34.10
|
||||||
- Mayhem
|
- Mayhem
|
||||||
|
|||||||
@ -706,28 +706,32 @@ ExpandComment =
|
|||||||
expand: (e) ->
|
expand: (e) ->
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
[_, threadID, replyID] = @href.match /(\d+)#p(\d+)/
|
[_, threadID, replyID] = @href.match /(\d+)#p(\d+)/
|
||||||
@textContent = "Loading #{replyID}..."
|
@textContent = "Loading No.#{replyID}..."
|
||||||
a = @
|
a = @
|
||||||
$.cache @pathname, -> ExpandComment.parse @, a, threadID, replyID
|
$.cache "//api.4chan.org#{@pathname}.json", -> ExpandComment.parse @, a, threadID, replyID
|
||||||
parse: (req, a, threadID, replyID) ->
|
parse: (req, a, threadID, replyID) ->
|
||||||
if req.status isnt 200
|
if req.status isnt 200
|
||||||
a.textContent = "#{req.status} #{req.statusText}"
|
a.textContent = "#{req.status} #{req.statusText}"
|
||||||
return
|
return
|
||||||
|
|
||||||
doc = d.implementation.createHTMLDocument ''
|
posts = JSON.parse(req.response).posts
|
||||||
doc.documentElement.innerHTML = req.response
|
replyID = +replyID
|
||||||
|
|
||||||
# Import the node to fix quote.hashes
|
for post in posts
|
||||||
# as they're empty when in a different document.
|
break if post.no is replyID
|
||||||
node = d.importNode doc.getElementById("m#{replyID}"), true
|
if post.no isnt replyID
|
||||||
|
a.textContent = 'No.#{replyID} not found.'
|
||||||
|
return
|
||||||
|
|
||||||
quotes = node.getElementsByClassName 'quotelink'
|
bq = $.id "m#{replyID}"
|
||||||
|
bq.innerHTML = post.com
|
||||||
|
quotes = bq.getElementsByClassName 'quotelink'
|
||||||
for quote in quotes
|
for quote in quotes
|
||||||
href = quote.getAttribute 'href'
|
href = quote.getAttribute 'href'
|
||||||
continue if href[0] is '/' # Cross-board quote
|
continue if href[0] is '/' # Cross-board quote
|
||||||
quote.href = "res/#{href}" # Fix pathnames
|
quote.href = "res/#{href}" # Fix pathnames
|
||||||
post =
|
post =
|
||||||
blockquote: node
|
blockquote: bq
|
||||||
threadID: threadID
|
threadID: threadID
|
||||||
quotes: quotes
|
quotes: quotes
|
||||||
backlinks: []
|
backlinks: []
|
||||||
@ -741,8 +745,7 @@ ExpandComment =
|
|||||||
QuoteOP.node post
|
QuoteOP.node post
|
||||||
if Conf['Indicate Cross-thread Quotes']
|
if Conf['Indicate Cross-thread Quotes']
|
||||||
QuoteCT.node post
|
QuoteCT.node post
|
||||||
$.replace a.parentNode.parentNode, node
|
Main.prettify bq
|
||||||
Main.prettify node
|
|
||||||
|
|
||||||
ExpandThread =
|
ExpandThread =
|
||||||
init: ->
|
init: ->
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user