-
Notifications
You must be signed in to change notification settings - Fork 33
/
main.js
131 lines (106 loc) · 3.96 KB
/
main.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
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
const puppeteer = require('puppeteer');
let username = '';
let password = '';
let duocode = '';
let course = [];
process.argv.forEach(function(val, index, array) {
if (index == 2) {
username = val;
}
if (index == 3) {
password = val;
}
if (index == 4) {
duocode = val;
}
if (index == 5) {
course.push(val);
}
});
console.log('INFO - username: ' + username);
console.log('INFO - password: ' + password);
console.log('INFO - duo_code: ' + duocode);
console.log('INFO - courses['+ course.length +']: ' + course);
(async () => {
const browser = await puppeteer.launch({
headless: true,
args: [
'--disable-web-security',
'--disable-features=IsolateOrigins,site-per-process',
'--no-sandbox',
'--disable-dev-shm-usage',
]
});
//init
const page = await browser.newPage();
await page.setDefaultNavigationTimeout(0);
await page.goto('https://wrem.sis.yorku.ca/Apps/WebObjects/REM.woa/wa/DirectAction/rem');
await page.setViewport({ width: 1080, height: 1024 });
await login(page);
flag = true;
while (flag) {
//loop slect course
if (course.length == 0) {
console.log("INFO - No more courses to add");
break;
} else {
//random choose index
var index = Math.floor(Math.random() * course.length);
}
await page.waitForTimeout(15000);
await page.waitForSelector('input[name="5.1.27.1.23"]');
await page.click('input[name="5.1.27.1.23"]');
await page.waitForTimeout(15000);
await page.type('input[name="5.1.27.7.7"]', course[index]);
await page.click('input[name="5.1.27.7.9"]');
await page.waitForSelector('input[name="5.1.27.11.11"]');
await page.click('input[name="5.1.27.11.11"]');
const result = await page.waitForSelector('body > form > div:nth-child(1) > table > tbody > tr:nth-child(4) > td:nth-child(2) > table > tbody > tr > td > table:nth-child(4) > tbody > tr:nth-child(1) > td:nth-child(2) > span > font > b');
let text = await result.evaluate(result => result.textContent);
text = text.trim();
var today = new Date();
var time = today.getHours() + ":" + today.getMinutes();
if (text === 'The course has been successfully added.') {
flag = false;
console.log(text);
console.log("INFO - Course added: " + course.pop() + " " + username + " " + time);
} else {
resultText = text + " INFO: " + course[index] + " add fail " + username + " " + time + " left courses: " + course.length;
console.log(resultText);
}
await page.waitForTimeout(15000);
await page.waitForSelector('input[name="5.1.27.27.11"]');
await page.click('input[name="5.1.27.27.11"]');
// wait for 5 mins * 12 = 1 hour
for (let i = 0; i < 12; i++) {
await page.waitForTimeout(200000);
await page.reload();
}
}
})();
async function login(page) {
//login
await page.type('#mli', username);
await page.type('#password', password)
const btn = '.btn.btn-lg.btn-primary';
await page.waitForSelector(btn);
await page.click(btn);
//duo
await page.waitForTimeout(10000);
const frames = page.frames();
const duoF = frames[1];
if (duoF) {
await duoF.$eval('#passcode', el => el.click());
await duoF.$eval('.passcode-input', (el, duocode) => { el.value = duocode }, duocode); // YOUR DUO CODE GOES HERE
await duoF.$eval('#passcode', el => el.click());
}
console.log("Login Successed");
//select term
await selectTerm(page);
}
async function selectTerm(page) {
await page.waitForTimeout(10000);
await page.select('select[name="5.5.1.27.1.11.0"]', '0'); //summer
await page.waitForSelector('input[type=submit]');
await page.click('input[type=submit]');
}