-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathcontent.js
More file actions
33 lines (32 loc) · 1.29 KB
/
Copy pathcontent.js
File metadata and controls
33 lines (32 loc) · 1.29 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
var idRegex = /^wm:mid.([0-9]+):.*/;
// Note that this DOM parser heavily depends on the layout of https://facebook.com/messages/
// and is not robust at all!!
chrome.runtime.onMessage.addListener(function(msg, sender, sendResponse) {
if (msg.text && msg.text === 'getMessages' && !msg.oppName.includes('?')) {
// oppName: friend id
// messageNumber: number of currently lodaded messages
// messages: parsed messages with source and time info
sendResponse({
oppName: msg.oppName,
messageNumber: document.getElementsByClassName("webMessengerMessageGroup").length,
messages: Array.from(document.getElementById("webMessengerRecentMessages").childNodes).map(function(n) {
if (n.className.includes('webMessengerMessageGroup')) {
// A regular message
return {
// The message should either come from friend (opp) or the user (self)
source: n.childNodes[1].firstChild.firstChild.href.includes(msg.oppName) ? 'opp' : 'self',
type: 'msg',
time: parseInt(n.id.match(idRegex)[1], 10)
};
} else {
// Separator usually means the start of a convo session
return {
source: '',
type: 'separator',
time: ''
};
}
})
});
}
});