Clean up comment parsing code a little

This commit is contained in:
Alex Corn 2021-07-30 00:39:46 -04:00
parent d09f18f055
commit ad095605b6
No known key found for this signature in database
GPG Key ID: E51989A3E7A27FDF

View File

@ -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);
});