Untitled

mail@pastecode.io avatar
unknown
plain_text
5 months ago
2.0 kB
1
Indexable
# display top level comments thing id:

// Select all elements that have a `thingid` attribute and are top-level comments
const topLevelComments = document.querySelectorAll('[thingid]');

// Create an array to store top-level comment IDs
let topLevelCommentIds = [];

// Iterate through the selected elements
topLevelComments.forEach(comment => {
    // Check if the comment is a top-level comment (depth is 0)
    if (!comment.closest('[depth]') || comment.closest('[depth]').getAttribute('depth') === '0') {
        topLevelCommentIds.push(comment.getAttribute('thingid'));
    }
});

// Display the top-level comment IDs in the console
console.log("Top-Level Comment IDs:", topLevelCommentIds);




---------------------------------------------------


#display top 10 comment and replies:

// Array of specific thingids to target
const targetThingIds = [
    't1_l037zoy', 't1_l03ahxv', 't1_l040qln', 
    't1_l05py9z', 't1_l06bcqm', 't1_l039nzt', 
    't1_l03c1zw', 't1_l03f5p6', 't1_l04ojmj', 
    't1_l04u890'
];

// Function to display a comment and its replies
function displayCommentAndReplies(thingid) {
    const comment = document.querySelector(`[thingid="${thingid}"]`);
    
    if (comment) {
        console.log(`Comment ID: ${thingid}`);
        console.log(comment.textContent.trim());

        // Assuming replies are nested within the parent comment
        const replies = comment.querySelectorAll('[thingid]');
        if (replies.length > 0) {
            console.log('Replies:');
            replies.forEach(reply => {
                console.log(`- ${reply.getAttribute('thingid')}: ${reply.textContent.trim()}`);
            });
        } else {
            console.log('No replies.');
        }
    } else {
        console.log(`No comment found for thingid: ${thingid}`);
    }

    console.log('--------------------------');
}

// Iterate over each target thingid and display the comment and its replies
targetThingIds.forEach(thingid => displayCommentAndReplies(thingid));


Leave a Comment