Created
December 2, 2017 09:22
-
-
Save heypoom/532b0e66ea49c870bbd30359bf328265 to your computer and use it in GitHub Desktop.
I'm lazy to use graph api and I just wanted to know what do people comment on FB, so here it is.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getCommentsWithTime = () => [...document.querySelectorAll('.UFIComment')].map(comment => { | |
const body = comment.querySelector('.UFICommentActorAndBody') | |
if (body) { | |
return { | |
user: body.querySelector('.UFICommentActorName').innerText, | |
text: body.querySelector('span:nth-child(2)').innerText, | |
timestamp: comment.querySelector('.livetimestamp').innerText | |
} | |
} | |
}).filter(item => item) | |
const getUsers = comments => comments.map(x => x.user).filter((v, i, a) => a.indexOf(v) === i) | |
const getUsersComments = comments => getUsers(comments).map(user => ({ | |
user, comments: comments.filter(x => x.user === user).map(x => x.text) | |
})) | |
function matchKeywordFromComment(keyword) { | |
const comments = getCommentsWithTime() | |
const uca = getUsersComments(comments) | |
return uca | |
.map(x => ({ | |
user: x.user, | |
match: x.comments.filter(x => x.indexOf(keyword) > -1) | |
})) | |
.filter(x => x.match.length > 0) | |
.reduce((prev, cur) => [...prev, {[cur.user]: cur.match}], []) | |
.reduce((prev, cur) => ({...prev, ...cur})) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment