mirror of
https://github.com/DoctorMcKay/node-steamcommunity.git
synced 2025-03-14 15:00:07 +08:00
Clean up comment parsing code a little
This commit is contained in:
parent
d09f18f055
commit
ad095605b6
@ -552,19 +552,18 @@ SteamCommunity.prototype.getAllGroupComments = function(gid, from, count, callba
|
||||
|
||||
let $ = Cheerio.load(JSON.parse(body).comments_html);
|
||||
|
||||
// !! DO NOT replace this function with an arrow function. We depend on the `this` context inside the function,
|
||||
// which is the comment element.
|
||||
$('.commentthread_comment_content').each(function() {
|
||||
$('.commentthread_comment_content').each((i, element) => {
|
||||
let comment = {};
|
||||
|
||||
let $selector = $(this).find('.commentthread_author_link');
|
||||
comment.authorName = $($selector).find('bdi').text();
|
||||
comment.authorId = $($selector).attr('href').replace(/https?:\/\/steamcommunity.com\/(id|profiles)\//, '');
|
||||
let $element = $(element);
|
||||
let $selector = $($element.find('.commentthread_author_link'));
|
||||
comment.authorName = $selector.find('bdi').text();
|
||||
comment.authorId = $selector.attr('href').replace(/https?:\/\/steamcommunity.com\/(id|profiles)\//, '');
|
||||
comment.date = Helpers.decodeSteamTime($(this).find('.commentthread_comment_timestamp').text().trim());
|
||||
|
||||
$selector = $(this).find('.commentthread_comment_text');
|
||||
comment.commentId = $($selector).attr('id').replace('comment_content_', '');
|
||||
comment.text = $($selector).html().trim();
|
||||
$selector = $($element.find('.commentthread_comment_text'));
|
||||
comment.commentId = $selector.attr('id').replace('comment_content_', '');
|
||||
comment.text = $selector.html().trim();
|
||||
|
||||
comments.push(comment);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user