-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
74 lines (73 loc) · 2.46 KB
/
index.js
File metadata and controls
74 lines (73 loc) · 2.46 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
class sendToAll {
constructor() {
new Promise((resolve, reject) => {
// Add jQuery to Page
// - Check if jQuery is already loaded
if(window.jQuery){
resolve()
}
const $jquery = document.createElement('script');
$jquery.onload = resolve;
$jquery.src = `https://code.jquery.com/jquery-2.2.4.js`;
document.head.appendChild($jquery);
}).then(() => {
// Creating An Array of Students
const cssClass = 'student-row--flex-row--rD3Y-';
this.studentArray = $(`.${cssClass}`).toArray();
this.last = this.studentArray.length -1;
// First Time mainHandler should be called manually
this.mainHandler();
})
}
/* Utils */
getFirstName(name) {
return name.split(" ")[0];
}
createTemplate(name) {
return `
>**WEEKLY CHECK IN**
\n
Hey ${name}! How are you doing and how's the learning going?
\n
What are your goals for the coming week?
\n
Are you currently stuck on anything? If so, what are you facing?
`;
}
chatOpened(name) {
return $('.index--wrapper--2Hiva').length !== 0
}
mainHandler() {
if (this.studentArray.length === 0) {
return;
}
// Selecting the last element of Array
const student = this.studentArray[this.last];
// Get Name of Student
const name = $(student).text();
const firstName = this.getFirstName(name);
// Open Student Chat
new Promise((resolve, reject) => {
$(student).click();
const loop = () => {
if (this.chatOpened(name)) {
return resolve();
}
setTimeout(loop, 100);
}
loop();
}).then(() => {
// Adding Text to Input Field
const text = this.createTemplate(firstName);
// Select the Input Field
const textarea = $('.send-input--form--25WLV textarea') // Need to find a way to emulate the enter press.
// On ENTER the response would be sent as well as mainHandler should be called again.
textarea.keyup((e) => {
if (e.which == 13) {
this.mainHandler();
}
});
textarea.val(text)
})
}
}