-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpayload.js
62 lines (51 loc) · 1.8 KB
/
payload.js
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// send the page title as a chrome message
chrome.runtime.sendMessage(sendChat());
function sendChat() {
var links = document.createElement("span");
var threads = document.getElementsByClassName("ts-message-list-item");
if (threads.length == 0) {
window.alert("This does not appear to be a Microsoft Teams Chat window");
return null;
}
for (let i = 0; i < threads.length; i++) {
var thread = threads[i];
var messages = thread.querySelectorAll("div.message-body");
var divider = thread.querySelector('div.message-list-divider');
var node = document.createElement("div");
// only display threaded view if in team chat
for (let index = 0; index < messages.length; index++) {
var message = messages[index];
var name = message.querySelector('div.ts-msg-name');
var timestamp = message.querySelector('span.message-datetime');
var content = message.querySelector('div.message-body-content');
var hidden = message.querySelector('.ts-collapsed-string > div[aria-hidden="true"]');
var p = document.createElement("p");
if(index > 0) {
p.classList.add("reply");
}
if(name) {
p.innerHTML += "<b>" + name.innerText + "</b>";
}
if(timestamp) {
p.innerHTML += " " + timestamp.innerText;
}
if(content) {
p.innerHTML += "<br>" + content.innerText;
}
if(hidden && hidden.innerText != "Collapse all") {
p.classList.add("collapsed");
p.innerHTML += hidden.innerText;
}
node.appendChild(p)
}
node.classList.add("thread");
links.appendChild(node);
if(divider) {
var div = document.createElement("h2");
div.innerText = divider.innerText;
div.className = "divider";
links.appendChild(div);
}
}
return links.innerHTML;
}