-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontentScript.js
More file actions
240 lines (187 loc) · 7.24 KB
/
Copy pathcontentScript.js
File metadata and controls
240 lines (187 loc) · 7.24 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
var divMessage = `
<span class="pulsate-container">
<span class="pulsate">🔴</span>
</span> Recording starting soon.
<input type="button" class="contained-button" id="remind_button" value="Remind me in a few minutes" />
<input type="button" class="text-button" id="cancel_button" value="Don't record this call" />
<span class="gmar_feedback"><a target="blank" href="https://docs.google.com/forms/d/e/1FAIpQLSeP-tkkIEhBZLgbB6zqE5saXULplaXin_uWR6XKR7YvIMzuvA/viewform">Feedback</a></span>
`;
function init(){
console.log('init()');
if (typeof shouldRecordNow === 'undefined') {
console.log('init(): shouldRecordNow is undefined. Setting to false');
shouldRecordNow = true;
}
else{
console.log('init(): shouldRecordNow is defined. Value = ' + shouldRecordNow);
}
}
function startRecording() {
return new Promise((resolve, reject) => {
console.log('startRecording() entered.');
clickGoogleMaterialIconElementWithText('more_vert');
setTimeout(() => {
clickElementByText('span','Manage recording');
setTimeout(() => {
clickElementByText('label','Also start a transcript (English only)');
clickElementByText('span','Start recording');
setTimeout(() => {
let isStarted = clickElementByText('span','Start');
if(isStarted){
console.log('Recording started');
hideMessageDiv();
resolve(true);
} else {
reject('Failed to start recording');
}
}, 1000);
}, 600);
}, 400);
console.log('startRecording() exit.');
});
}
function clickGoogleMaterialIconElementWithText(text){
const icons = document.querySelectorAll('i.google-material-icons[aria-hidden="true"]');
// Loop through the collection of icons in reverse order as the multiple buttons often exist and we generally want the last one.
for (let i = icons.length - 1; i >= 0; i--) {
//for (let icon of icons) {
// Check if the text content of the icon is 'more_vert'
const icon = icons[i];
if (icon.textContent.trim() === text) {
icon.click(); // Click the icon if it matches
console.log('Clicked');
return true;
}
}
return false;
}
function clickElementByText(elementType, text) {
const spans = document.querySelectorAll(elementType);
// Loop through each span to find the one with the matching text content
for (let span of spans) {
if (span.textContent.trim() === text) {
span.click(); // Click the span if the text matches
console.log('Clicked div with text:', text);
return true;
}
}
// Log if the span was not found
console.log('Div with text "' + text + '" not found');
return false;
}
function divExists(text) {
console.log('divExists() entered');
const divs = document.querySelectorAll('div');
for (let div of divs) {
if (div.textContent.trim() === text) {
console.log('div exists.');
if(div.style.display !== 'none'){
console.log('div is visible.');
console.log('divExists() exit. Returning true');
return true;
}
}
}
console.log('divExists() exit. Returning false');
return false;
}
function spanExists(text) {
console.log('spanExists() entered');
const spans = document.querySelectorAll('span');
for (let span of spans) {
if (span.textContent.trim() === text) {
console.log('span exists.');
if(span.style.display !== 'none'){
console.log('span is visible.');
console.log('spanExists() exit. Returning true');
return true;
}
}
}
console.log('spanExists() exit. Returning false');
return false;
}
function onWaitingScreen() {
console.log('onWaitingScreen() entered');
return spanExists('Join now');
}
/* Warning DIV setup */
function createNode() {
let newDiv = document.createElement('div');
newDiv.textContent = divMessage;
newDiv.innerHTML = divMessage;
newDiv.className = "message_div material-paper"
newDiv.id = "message_div";
return newDiv;
}
function isRecording(){
console.log('isRecording() entered');
const divs = document.querySelectorAll('div');
for (let div of divs) {
if (div.getAttribute('aria-label') === 'This meeting is being recorded'
&& div.style.display !== 'none') {
console.log('isRecording() exit. Returning true');
return true;
}
}
console.log('isRecording() exit. Returning false');
return false;
}
function setUpDiv() {
const maindiv = document.getElementsByTagName("body")[0].getElementsByTagName('div')[0];
const newNode = createNode();
maindiv.prepend(newNode);
// document.getElementById('cancel_button').addEventListener('click', cancel_button_clicked);
document.getElementById('cancel_button').addEventListener('click', cancel_button_clicked);
document.getElementById('remind_button').addEventListener('click', remind_button_clicked);
}
function hideMessageDiv() {
console.log('hideMessageDiv() entered');
document.getElementById('message_div').style.display = 'none';
}
function cancel_button_clicked() {
console.log('Cancel button clicked');
hideMessageDiv();
shouldRecordNow = false;
}
function remind_button_clicked() {
console.log('Remind button clicked');
hideMessageDiv();
shouldRecordNow = false;
setTimeout(() => {
console.log('Maybe Re-showing div');
if(!isRecording()){
console.log('Re-showing div');
document.getElementById('message_div').style.display = 'flex';
shouldRecordNow = true;
}
}, 1000 * 180);
}
/* */
init();
document.addEventListener('DOMContentLoaded', setUpDiv, false)
window.addEventListener('load', () => {
console.log('Page loaded');
const interval = setInterval(() => {
var recording_started = isRecording();
console.log('recording_started = ' + recording_started);
if(recording_started){
hideMessageDiv();
clearInterval(interval);
return;
}
let isOnWaitingScreen = onWaitingScreen();
console.log('isOnWaitingScreen = ' + isOnWaitingScreen);
console.log('shouldRecordNow = ' + shouldRecordNow);
console.log(shouldRecordNow && !recording_started);
if (shouldRecordNow && !recording_started && !isOnWaitingScreen) {
startRecording().then(started => {
console.log('Recording has started');
clearInterval(interval);
}).catch(error => {
console.log('Error starting recording:', error);
});
}
}, 8 * 1000);
});