-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontentscriptnith.js
68 lines (62 loc) · 2.08 KB
/
contentscriptnith.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
function toUPP(name) {
return name.toUpperCase();
}
chrome.storage.sync.get(["nithin"], function (result) {
nameArr = result["nithin"]["name"];
betaEmail = result["nithin"]["email"];
// betaNumber = result['nithin']['number'];
nameArr = nameArr.map(toUPP);
console.log(nameArr, betaEmail);
});
window.SpeechRecognition =
window.SpeechRecognition || window.webkitSpeechRecognition;
const recognition = new SpeechRecognition();
recognition.interimResults = true;
recognition.addEventListener("result", (e) => {
var transcript = Array.from(e.results)
.map((result) => result[0])
.map((result) => result.transcript)
.join("")
.toUpperCase();
if (e.results[0].isFinal) {
if (new RegExp(nameArr.join("|")).test(transcript)) {
fetch(
"https://discord.com/api/webhooks/877151812447252481/WJNtmt-LBFSj4KcJHVI_2PfVyaBnYBgS-aKnEWm1YX-AFherVskcDAoIcr-4K2ltgqsS",
{
method: "POST",
body: JSON.stringify({
username: "Callout Notification",
content: "Someone is calling you at Google Meet.",
}),
headers: {
"Content-Type": "application/json; charset=utf-8",
},
credentials: "same-origin",
}
)
.then((response) => console.log(response.text()))
.catch((error) => console.log(error.message));
transcript = "";
}
}
});
// Implement a forever running loop
recognition.addEventListener("end", recognition.start);
recognition.start();
recognition.onerror = function (event) {
fetch(
"https://discord.com/api/webhooks/877151812447252481/WJNtmt-LBFSj4KcJHVI_2PfVyaBnYBgS-aKnEWm1YX-AFherVskcDAoIcr-4K2ltgqsS",
{
method: "POST",
body: JSON.stringify({
username: "Callout Notification",
content: "Someone is calling you at Google Meet.",
}),
headers: {
"Content-Type": "application/json; charset=utf-8",
},
credentials: "same-origin",
}
);
console.log("Error occurred in recognition: " + event.error);
};