[+] Backup issue #261 analysis code

This commit is contained in:
Azalea 2024-05-16 19:52:15 +08:00
parent a2abe13b86
commit d70baebbf0
5 changed files with 577 additions and 0 deletions

View file

@ -0,0 +1,18 @@
function trimSpaces(s) {
return s.replaceAll("\n", "").replace(/\s+/g, ' ').trim();
}
const cmts = $("shreddit-comment")
const out = []
// Parse comments from html
cmts.each((i, cmt) => {
const $cmt = $(cmt)
// Author: slot="commentMeta" (use the first one)
const author = trimSpaces($cmt.find("[slot=commentMeta]").first().text())
// Content: slot="comment"
const content = trimSpaces($cmt.find("[slot=comment]").first().text())
// Upvotes: score attribute of shreddit-comment-action-row
const upvotes = parseInt($cmt.find("shreddit-comment-action-row").attr("score"))
out.push({ author, content, upvotes })
})
out