Last active
June 27, 2021 06:06
-
-
Save ngseke/018ff069160df9912309d85726a948f9 to your computer and use it in GitHub Desktop.
Observe Youtube Chat Room Items
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
var $chatList = document | |
.querySelector('#chatframe') | |
.contentWindow | |
.document | |
.querySelector('#item-offset #items') | |
var observer = new MutationObserver(([{ target }]) => { | |
const items = [...target.querySelectorAll('yt-live-chat-text-message-renderer')] | |
.map($el => ({ | |
img: $el.querySelector('#img').getAttribute('src'), | |
timestamp: $el.querySelector('#timestamp').innerText, | |
authorName: $el.querySelector('#author-name').innerText, | |
})) | |
console.log(items[items.length - 1]) // 印出列表的最後一項 | |
}) | |
observer.observe($chatList, { childList: true }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment