-
Notifications
You must be signed in to change notification settings - Fork 1
/
content_script.js
74 lines (64 loc) · 2.38 KB
/
content_script.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
63
64
65
66
67
68
69
70
71
72
73
74
(function () {
// http://bgrins.github.io/devtools-snippets/#console-save
var saveToFile = function (data, filename) {
if (!data) {
console.error('Console.save: No data');
return;
}
if (!filename) {
filename = 'console.json';
}
if (typeof data === "object") {
data = JSON.stringify(data, undefined, 4);
}
var blob = new Blob([data], { type: 'text/json' }),
e = document.createEvent('MouseEvents'),
a = document.createElement('a');
a.download = filename;
a.href = window.URL.createObjectURL(blob);
a.dataset.downloadurl = ['text/json', a.download, a.href].join(':');
e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
a.dispatchEvent(e);
};
var name = ''
for (var img of document.querySelectorAll("[aria-label=Messages] img[alt]")) {
const alt = img.getAttribute('alt')
if (alt.length > name.length && alt.indexOf('Seen by') === -1) {
name = alt
}
}
var me = document.querySelector("h5._ih3.accessible_elem").innerText;
var nodes = Array.from(document.querySelectorAll("[aria-label=Messages] [data-hover=tooltip]"))
var content = nodes.filter(n => n.textContent.length > 0)
.filter(e => e.getAttribute('data-tooltip-position') != null) // Filter out reactions
.filter(e => e.querySelector("div[tabindex]") != null)
.map(e => ({
name: e.getAttribute("data-tooltip-position") === "left" ? name : me,
time: e.getAttribute("data-tooltip-content"),
content: e.querySelector("div[tabindex]").textContent
}))
content = content.reduce((result, msg) => {
if (result.length === 0 || result[result.length - 1].name !== msg.name) {
result.push(msg)
} else {
result[result.length - 1].content += '\n' + msg.content
}
return result
}, [])
const result = content.map(function (msg) {
var content = "**" + msg.name + "**" + " *" + msg.time + "*\n" + msg.content;
return content.split("\n").map(function (l) { return "> " + l; }).join("\n");
}).join("\n>\n")
function copyTextToClipboard(text) {
const input = document.createElement('textarea')
document.body.appendChild(input)
input.value = text
input.focus()
input.select()
const result = document.execCommand('copy')
input.remove()
return result
}
copyTextToClipboard(result)
alert('Copied to clipboard')
})()