[+] Backup issue #261 analysis code
This commit is contained in:
parent
a2abe13b86
commit
d70baebbf0
5 changed files with 577 additions and 0 deletions
18
tools/2024-05-16-reddit/reddit.js
Normal file
18
tools/2024-05-16-reddit/reddit.js
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue