-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathmessage.js
More file actions
36 lines (29 loc) · 1.31 KB
/
message.js
File metadata and controls
36 lines (29 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Message Listener
async function messageListener(Meet) {
async function getRecentMessage() {
var message = await Meet.page.evaluate(() => {
chat = document.querySelector('.z38b6').lastChild;
return {
author: chat.firstChild.firstChild.innerText,
time: chat.firstChild.lastChild.innerText,
content: chat.lastChild.lastChild.innerText
}; // See div.html
})
if (message.author !== "You") {
await Meet.emit('message', message);
Meet.recentMessage = message;
return message;
}
}
await Meet.page.waitForSelector('.GDhqjd', { timeout: 0 }); getRecentMessage();
await Meet.page.exposeFunction('getRecentMessage', getRecentMessage)
await Meet.page.evaluate(() => {
// https://stackoverflow.com/questions/47903954/how-to-inject-mutationobserver-to-puppeteer
// https://stackoverflow.com/questions/54109078/puppeteer-wait-for-page-dom-updates-respond-to-new-items-that-are-added-after/54110446#54110446
messageObserver = new MutationObserver(() => {getRecentMessage();});
messageObserver.observe(document.querySelector('.z38b6'), { subtree: true, childList: true });
});
}
module.exports = {
messageListener: messageListener
}