This repository was archived by the owner on May 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontentscript.js
94 lines (84 loc) · 3.4 KB
/
contentscript.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
window.onload = (event) => {
document.head.innerHTML += '<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">'
meetChat()
$(document).on('click', '#barra_btn', function() {
colorSwitch()
});
addObserverIfDesiredNodeAvailable();
};
var estado = false;
var data = "";
const fileName = 'file.txt';
var lastName = "";
const observer = new MutationObserver((mutationList) => {
mutationList.forEach((mutation) => {
if (estado) {
if (mutation.addedNodes.length) {
//console.log('Añadidos', mutation.addedNodes[0])
var chat = document.querySelectorAll('.oIy2qc')
var names = document.querySelectorAll('.YTbUzc')
lastName = names[names.length - 1].innerText;
names[names.length - 1].setAttribute('data-timestamp', timestamp);
for (var i = 0; i < chat.length; i++) {
//console.log('chat', i)
if (!chat[i].getAttribute('data-timestamp')) {
console.log(chat[i].getAttribute('data-message-text'))
var timestamp = new Date();
chat[i].setAttribute('data-timestamp', timestamp);
data += lastName + " " + chat[i].getAttribute('data-message-text') + "\n";
//data += chat[i].getAttribute('data-sender-name') + "\n";
}
}
}
}
})
});
function addObserverIfDesiredNodeAvailable() {
var cambios = document.querySelector('.z38b6.CnDs7d.hPqowe');
if (!cambios) {
window.setTimeout(addObserverIfDesiredNodeAvailable, 500);
return;
}
const obsercerOptions = {
atributes: true,
childList: true,
subtree: true
};
observer.observe(cambios, obsercerOptions);
}
async function meetChat() {
var chat = document.querySelector('.NSvDmb.cM3h5d')
if (chat) {
var cc = document.querySelector('.f0WtFf')
var button = '<div class="uArJ5e UQuaGc kCyAyd kW31ib SyIese M9Bg4d transcribechat" id="transcribechat" " ><div class="n8i9t "id="barra_btn"><div class="XFtqNb "><i class="google-material-icons " aria-hidden="true" id= "logo_btn">chat</i></div><div class="I98jWb " id="texto_btn">' + "save cc" + '</div></div></div>'
cc.insertAdjacentHTML('beforebegin', button)
colorSwitch()
} else {
var sl = setTimeout(function() {
meetChat();
}, 1000);
}
}
function colorSwitch() {
console.log("cambio")
if (!estado) {
document.getElementById("logo_btn").style.color = "#00796b";
document.getElementById("texto_btn").style.color = "#00796b";
estado = true;
} else {
document.getElementById("logo_btn").style.color = "#3c4043";
document.getElementById("texto_btn").style.color = "#3c4043";
estado = false;
download(fileName, data);
}
}
function download(filename, text) {
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
data = "";
}