-
Notifications
You must be signed in to change notification settings - Fork 1
/
content.js
88 lines (65 loc) · 2.05 KB
/
content.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
// content.js
// Add event listeners for visibilitychange and focus events
document.addEventListener("visibilitychange", handleVisibilityChange);
window.addEventListener("focus", handleTabSwitch);
// Function to handle visibility change
function handleVisibilityChange() {
if (document.hidden) {
// Tab or window is hidden (switched to another tab)
const buttons = document.getElementsByTagName('button');
let buttonExists = false;
for (let i = 0; i < buttons.length; i++) {
// Turn on microphone (ctrl + d) = mic is off
if (buttons[i].getAttribute('aria-label') === 'Turn on microphone (ctrl + d)') {
buttonExists = true;
break;
}
}
if(buttonExists){
console.log("Mic is Off");
} else {
const ctrlD = new KeyboardEvent("keydown", {
key: "d",
ctrlKey: true,
});
document.dispatchEvent(ctrlD);
}
// console.log("Mute On");
} else {
// const buttons = document.getElementsByTagName('button');
// let buttonExists = false;
// for (let i = 0; i < buttons.length; i++) {
// // Turn on microphone (ctrl + d) = mic is off
// if (buttons[i].getAttribute('aria-label') === 'Turn on microphone (ctrl + d)') {
// buttonExists = true;
// break;
// }
// }
// if(buttonExists){
// const ctrlD = new KeyboardEvent("keydown", {
// key: "d",
// ctrlKey: true,
// });
// document.dispatchEvent(ctrlD);
// console.log("Mic is On");
// } else {
// console.log("Mic is Off");
// }
}
}
// Function to handle tab switch
function handleTabSwitch() {
if (document.hidden) {
// Tab or window is hidden (switched to another tab)
// alert("You switched to another tab!");
}
}
// // Get the current URL
// const currentUrl = window.location.href;
// // Log the URL to the console
// console.log("Current URL:", currentUrl);
// content.js
// Get the current URL
const currentUrl = window.location.href;
// Send message to background script with the current URL
chrome.runtime.sendMessage({ url: currentUrl });