-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathgenerate-udemy-ai-explanations.js
More file actions
78 lines (68 loc) · 2.38 KB
/
Copy pathgenerate-udemy-ai-explanations.js
File metadata and controls
78 lines (68 loc) · 2.38 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
// Function to simulate clicking elements by selector
function clickElementBySelector(selector) {
const element = document.querySelector(selector);
if (element) {
element.click();
return true;
} else {
console.warn(`Element with selector '${selector}' not found.`);
return false;
}
}
// Function to simulate clicking elements by text
function clickElementByText(tag, text) {
const elements = document.getElementsByTagName(tag);
for (let element of elements) {
if (element.textContent.trim() === text) {
element.click();
return true;
}
}
console.warn(`Element with tag '${tag}' and text '${text}' not found.`);
return false;
}
// Function to perform the sequence of actions
function performSequence() {
const divSelector = '.left-area--item-wrapper--FMMrx';
const divElements = document.querySelectorAll(divSelector);
let index = 0;
function clickNextDiv() {
if (index >= divElements.length) {
console.log('All div elements have been processed.');
return;
}
divElements[index].click();
setTimeout(() => {
if (clickElementByText('button', 'Generate all answer explanations with AI')) {
// Wait 15 seconds before clicking "Accept and edit" spans
setTimeout(() => {
const spanSelector = 'span';
const spanText = 'Accept and edit';
const saveText = 'Save question';
// Click all "Accept and edit" spans
const acceptAndEditSpans = document.querySelectorAll(`${spanSelector}`);
for (let span of acceptAndEditSpans) {
if (span.textContent.trim() === spanText) {
span.click();
}
}
// Click the "Save question" span
setTimeout(() => {
clickElementByText(spanSelector, saveText);
// Move to the next div and repeat the process
index++;
setTimeout(clickNextDiv, 10000); // Adjust delay as necessary
}, 10000); // Adjust delay as necessary
}, 15000); // Wait 15 seconds before finding "Accept and edit" spans
} else {
console.log('Failed to click "Generate all answer explanations with AI" button.');
index++;
setTimeout(clickNextDiv, 1000); // Adjust delay as necessary
}
}, 500); // Adjust delay as necessary
}
// Start the sequence
clickNextDiv();
}
// Start the process
performSequence();