-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cousera_tricks_nobutterfly.js
466 lines (385 loc) · 16.4 KB
/
Cousera_tricks_nobutterfly.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
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
//completed
var link_pelement,category_txts,crumbs,w_now,s_now,read_btn,media,completed_txt,try_start_resume_btn,questions,options,option_type,agree_btn,submit_btn,feedback,options_text,attempt_btn,spans,NOanswer,styles,styleSheet,anim_elm,box,flies;
var w,x,p,l,h,k,j,m,o,s,y,z,r=0;
details = {};
answers=[];
q_count=0,q_other=0, repeated=false;
function anim(){
styles = `h1{-webkit-animation:tracking-in-contract-bck 2s cubic-bezier(.215,.61,.355,1.000) both;animation:tracking-in-contract-bck 2s cubic-bezier(.215,.61,.355,1.000) both}@-webkit-keyframes tracking-in-contract-bck{0%{letter-spacing:1em;-webkit-transform:translateZ(400px);transform:translateZ(400px);opacity:0}40%{opacity:.6}100%{-webkit-transform:translateZ(0);transform:translateZ(0);opacity:1}}@keyframes tracking-in-contract-bck{0%{letter-spacing:1em;-webkit-transform:translateZ(400px);transform:translateZ(400px);opacity:0}40%{opacity:.6}100%{-webkit-transform:translateZ(0);transform:translateZ(0);opacity:1}} .breadcrumb-list{-webkit-animation:slide-in-left 2s cubic-bezier(.25,.46,.45,.94) both;animation:slide-in-left 2s cubic-bezier(.25,.46,.45,.94) both}@-webkit-keyframes slide-in-left{0%{-webkit-transform:translateX(-1000px);transform:translateX(-1000px);opacity:0}100%{-webkit-transform:translateX(0);transform:translateX(0);opacity:1}}@keyframes slide-in-left{0%{-webkit-transform:translateX(-1000px);transform:translateX(-1000px);opacity:0}100%{-webkit-transform:translateX(0);transform:translateX(0);opacity:1}} #bf,#box{width:45px;height:45px;margin-radius:50%;z-index:100}#box{transition:20s;transition-origin:top right;}#bf{transition:1s;transition-origin:top right;}`;
styleSheet = document.createElement("style");
styleSheet.innerText = styles;
document.head.appendChild(styleSheet);
var box = document.createElement("div");
box.id = "box";
box.innerHTML = `<img id="bf" src="https://media.tenor.com/ymJxN50WiYUAAAAi/fly.gif" alt="butterfly" >`;
document.body.appendChild(box);
document.onmousemove = function(e) {
if(y>e.clientX){
document.getElementById('bf').style.transform ="rotateY(180deg)" ;
}else if(y<e.clientX){
document.getElementById('bf').style.transform ="rotateY(360deg)" ;
}
y = e.clientX;
z = e.clientY;
// console.log(x+","+y);
document.getElementById('box').style.marginLeft = y+"px";
document.getElementById('box').style.marginTop = z+"px";
}//mousemove
}//anim
anim();
//worked - looped through all weeks
const weeks = document.querySelectorAll('a[data-test="rc-WeekNavigationItem"]');
//const weeks = document.querySelector('div[title="Course Material"]').querySelectorAll('li');
console.log(weeks);
async function complete() {
for ( w = weeks.length-1; w>=0 ; w--) {
weeks[w].click();
await new Promise(r => setTimeout(r,10000));
console.log("weeks "+ w);
// weeks[j].childNodes[0].click();
// worked - got all topics and their category
link_pelement= document.querySelectorAll('div[role="presentation"]');
//console.log(link_pelement);
category_txts = document.querySelectorAll('.rc-WeekItemAnnotations');
//console.log(category_txts);
for ( x = 0; x < category_txts.length; x++) {
// console.log(link_pelement[x+4]);
// console.log(category_txts[x]);
//when selecting [role="presentation"] it has some other extra elements ,to eliminate that start from four by se+4
details["link"+w+x]= link_pelement[x+4].childNodes[0];
details["category"+w+x]=category_txts[x].textContent.split("•",1)[0];
details["name"+w+x]=link_pelement[x+4].childNodes[0].querySelector("p[data-test='rc-ItemName']").textContent;
}//for
console.log(details);
}//for-weeks
//console.log(details["link00"]);
details["link00"].click();
//selecting the section from the same week opened, does change the whole html so it stays in the page so you can continue inspect element
solve();
async function solve() {
await new Promise(r => setTimeout(r,20000));
crumbs=document.getElementsByClassName('breadcrumb-item');
w_now=crumbs[1].textContent.match(/\d+/);
w_now=w_now[0]-1; //-1 to start from zero index
s_now=crumbs[2].textContent;
//console.log(w_now);
//console.log(s_now);
for (p = 0;p < category_txts.length;p++) {
if(s_now==details["name"+w_now+p]){
break;
}//if
}//for
console.log(p);
console.log(details["name"+w_now+p]);
next_btn=document.querySelector("a[aria-label='Next Item']");
if(details["category"+w_now+p]=="Video"){
console.log("Video");
media = document.querySelector("video");
console.log(media);
media.play();
await new Promise(r => setTimeout(r,2000));
//The HTMLMediaElement API is used for video controls
// time is calculated in seconds
//console.log(media.currentTime);
//console.log(media.duration);
anime_jello();
/* media.currentTime = Math.floor(media.duration-50);
await new Promise(r => setTimeout(r,1000));
media.currentTime = Math.floor(media.duration-5);
await new Promise(r => setTimeout(r,1000)); */
media.currentTime = Math.floor(media.duration);
console.log("Video played");
await new Promise(r => setTimeout(r,10000));
next_btn.click();
solve();
}else if(details["category"+w_now+p]=="Reading"){
console.log("Reading");
read_btn = document.querySelector('button[data-testid="mark-complete"]');
if(read_btn){
//anime
read_btn.click();
await new Promise(r => setTimeout(r,10000));
}
completed_txt = document.querySelector('div[data-testid="completed-text"]');
if(completed_txt){
console.log("Completed reading"); }
next_btn.click();
solve();
}else if(details["category"+w_now+p].includes("Quiz")){
console.log("Quiz");
answers=[]; //empty answer array before every quiz
if(parseInt(document.querySelector("div[data-test='grade-percent']").textContent)>=80){
next_btn.click();
solve();
}else{
quiz();
}
}else if(details["category"+w_now+p]=="Discussion Prompt"){
console.log("Discussion Prompt");
next_btn.click();
solve();
}else {
console.log("other");
read_btn = document.querySelector('button[data-testid="mark-complete"]');
if(read_btn){
//anime
read_btn.click();
await new Promise(r => setTimeout(r,10000));
}
completed_txt = document.querySelector('div[data-testid="completed-text"]');
if(completed_txt){
console.log("Completed reading"); }
next_btn.click();
solve();
}//if
function modal(i,category) {
console.log("loop"+i);
try_start_resume_btn = document.querySelector('a[aria-labelledby ="Try again"]') || document.querySelector('button[aria-labelledby="Start assignment"]') || document.querySelector('button[aria-labelledby="Resume assignment"]') ;
try_start_resume_btn.click();
submitting();
async function submitting() {
await new Promise(r => setTimeout(r,15000));
console.log("opened");
//worked- selected all questions
questions = document.querySelectorAll('[class="rc-FormPartsQuestion"]');
console.log(questions);
//worked6- loop through question
for ( l= 0; l < questions.length; l++) {
//console.log("questions");
console.log(questions[l]);
//got all four options
options= questions[l].querySelectorAll("input");
console.log(options);
//worked-seperated input type
if(options[0]){
option_type=options[0].getAttribute("type");
// radio>=checkbox=>true so for checkbox loop radio also gain one additional chance
if(option_type>=category){
// console.log("radio");
if (option_type=="radio") {
h=i;
console.log("radio");
}else if(option_type=="checkbox"){
h=(options.length)-1;
console.log("checkbox");
}
//for checkbox it select all options
//for radio it select option behalf of the count of loop
for ( k= 0; k <= h; k++) {
if(options[k]){
console.log("option"+k);
console.log(options[k]);
options[k].parentElement.click(); //worked-seleted options
}else if(k==(options.length-1)){
// if there is no option select last option it will helps if it lessthan 4 options
options[k].parentElement.click();
}//elseif
}//for
}//if
}else{
q_other+=1;
}//elseif
}//for
q_count=questions.length;
console.log("q_count,q_other");
console.log(q_count+","+q_other);
if(q_count<=q_other){
next_btn.click();
solve();
return;
}
//worked2 - agreed
agree_btn = document.querySelector('span[id="agreement-checkbox-base-label-text"]');
agree_btn.click();
console.log("agreed");
//worked-delyed submission
submit_btn = document.querySelector('button[data-test="submit-button"]');
submit_btn.click();
console.log("submitted");
//feedback loop
feedbacking();
async function feedbacking() {
//var questions = document.querySelectorAll('[role="group"]');
// answers=[];
await new Promise(r => setTimeout(r,15000));
console.log("feedbacks");
for ( j= 0; j < questions.length; j++) {
console.log("questions"+j); // console.log(questions[j]);
options= questions[j].querySelectorAll("input");
//console.log("options"); console.log(options);
//worked - got feedback
if(options[0]){
option_type=options[0].getAttribute("type");
if(option_type>=category){
feedback = questions[j].querySelectorAll('div[data-testid="GradeFeedback-caption"]');
console.log("feedback"); console.log(feedback);
//for radio it has only one total feedback but checkbox has feedback for every option
if (option_type=="radio") {
n=0; // make loop once
console.log("radio");
}else if(option_type=="checkbox"){
n=(options.length)-1;
console.log("checkbox");
}
for ( m = 0; m <= n; m++) {
if(option_type=="checkbox"){ o=m;
// for checkbox selected specific feedback feedback[m] and specific option options[m]
}else if(option_type=="radio"){
// for radio selected first feedback feedback[n] and specific option options[i]
o=n; m=i;}
console.log("option"+m);
console.log("feedback_text"); console.log(feedback[o].textContent);
if(feedback[o].textContent.includes("Correct")){
// worked-got options text
options_text = options[m].parentElement.textContent;
console.log("options_text"); console.log(options_text);
if (!answers.includes(options_text)) {
//store answers in object
answers.push(options_text);
}
}//if
}//for
}//if
}//if
}//for
// }//for
console.log("answer_array"); console.log(answers);
if(answers.length<questions.length){
console.log("answers count mistake"); } //if
await new Promise(r => setTimeout(r,5000));
// worked- attempt tryagain
var attempt_btn = document.querySelector('div[data-e2e="AttemptPageTopBanner"]').querySelector("button");
console.log(attempt_btn);
attempt_btn.click();
} //feedbacking
} //submitting
return answers;
}//func-modal
async function select_answer() {
console.log("answer submission");
console.log(answers);
q_other=0; // said to 0 to neutralize for every quiz loop
try_start_resume_btn = document.querySelector('a[aria-labelledby ="Try again"]') || document.querySelector('button[aria-labelledby="Start assignment"]') || document.querySelector('button[aria-labelledby="Resume assignment"]') ;
try_start_resume_btn.click();
await new Promise(r => setTimeout(r,15000));
console.log("opened");
//worked- selected all questions
questions = document.querySelectorAll('[class="rc-FormPartsQuestion"]');
q_count=questions.length;
// console.log(questions);
//worked6- loop through question
for ( l= 0; l < questions.length; l++) {
console.log("question "+l);
//console.log(questions[l]);
//got all four options
options= questions[l].querySelectorAll("input");
// console.log(options);
//worked-seperated input type
if(options[0]){
NOanswer=true;
for ( k= 0; k < options.length; k++) {
console.log("option "+k);
options_text = options[k].parentElement.textContent;
if (answers.includes(options_text)) {
console.log(options_text);
options[k].parentElement.click(); //worked-seleted options
NOanswer=false; // if there is no answer until last NOanswer=true so next if runs
}else if(k==(options.length-1) && NOanswer==true){
console.log("No answer");
// if there is no answer until last option select last option it will helps if it 5 options
options[k].parentElement.click();
}
}//for
}else{
q_other+=1;
}//elseif
}//for
//worked2 - agreed
agree_btn = document.querySelector('span[id="agreement-checkbox-base-label-text"]');
agree_btn.click();
console.log("agreed");
//worked-delyed submission
submit_btn = document.querySelector('button[data-test="submit-button"]');
submit_btn.click();
console.log("submitted");
}//func-ans
function delay(duration) {
return new Promise((resolve) => {
setTimeout(resolve, duration);
});
}
function quiz() {
Promise.resolve()
.then(() => modal(0,"checkbox"))
.then(() => delay(45000))
.then(() => modal(0,"radio"))
.then(() => delay(45000))
.then(() => modal(1,"radio"))
.then(() => delay(45000))
.then(() => modal(2,"radio"))
.then(() => delay(45000))
.then(() => modal(3,"radio"))
.then(() => delay(45000))
.then(() => select_answer())
.then(() => delay(45000))
.then(function() {
console.log("repeated function");
//repeated == false at starting if all the possible questions are not graded , loop continues to second time and set repeated==true to prevent from more than two loop
if(repeated==false){
console.log("repeating");
spans = document.querySelectorAll("div>span");
// grade is in span at top section so we get it few loop
for (s= 0;s < spans.length;s++) {
if(spans[s].textContent=="Latest Submission Grade"){
console.log(spans[s].textContent);
// grade is next sibling to current text so it must be i+1
percent_got=parseFloat(spans[s+1].textContent);
// we got our latest grade
console.log(percent_got);
break;
}else if(spans[s].textContent=="Grade received"){
console.log(spans[s].textContent);
percent_got=parseFloat(spans[s+1].textContent);
// we got our latest grade
console.log(percent_got);
}//elseif
}//for
console.log("q_count,q_other");
console.log(q_count+","+q_other);
// to know what is the percentage of textbox questions
percent_other=((q_other * 100) / q_count).toFixed(2) ;
console.log("percent_got,percent_other");
console.log(percent_got+","+percent_other);
/*
to check all the questions other than text box are answerd, if not repeat whole loop
the loop will not repeat if it met two conditions
>percentage of checkbox and radio questions equal to the percentage we got
>percentage we got is above than 80
*/
console.log( (!(percent_got==(100-percent_other)))&&(percent_got<80) );
if((!(percent_got==(100-percent_other)))&&(percent_got<80)){
repeated=true;
quiz();
}else{ console.log("passed, next");
//if you are passed at first attempt then moved to next
next_btn.click();
solve();
}//else
}else{ console.log("reapted, next");
//after repeatation it moved to next
next_btn.click();
solve();
}//else
});//then
}//func-quiz
function anime_jello() {
styles = `.jello-vertical{-webkit-animation:jello-vertical .9s both;animation:jello-vertical .9s both}@-webkit-keyframes jello-vertical{0%{-webkit-transform:scale3d(1,1,1);transform:scale3d(1,1,1)}30%{-webkit-transform:scale3d(.75,1.25,1);transform:scale3d(.75,1.25,1)}40%{-webkit-transform:scale3d(1.25,.75,1);transform:scale3d(1.25,.75,1)}50%{-webkit-transform:scale3d(.85,1.15,1);transform:scale3d(.85,1.15,1)}65%{-webkit-transform:scale3d(1.05,.95,1);transform:scale3d(1.05,.95,1)}75%{-webkit-transform:scale3d(.95,1.05,1);transform:scale3d(.95,1.05,1)}100%{-webkit-transform:scale3d(1,1,1);transform:scale3d(1,1,1)}}@keyframes jello-vertical{0%{-webkit-transform:scale3d(1,1,1);transform:scale3d(1,1,1)}30%{-webkit-transform:scale3d(.75,1.25,1);transform:scale3d(.75,1.25,1)}40%{-webkit-transform:scale3d(1.25,.75,1);transform:scale3d(1.25,.75,1)}50%{-webkit-transform:scale3d(.85,1.15,1);transform:scale3d(.85,1.15,1)}65%{-webkit-transform:scale3d(1.05,.95,1);transform:scale3d(1.05,.95,1)}75%{-webkit-transform:scale3d(.95,1.05,1);transform:scale3d(.95,1.05,1)}100%{-webkit-transform:scale3d(1,1,1);transform:scale3d(1,1,1)}}`;
styleSheet = document.createElement("style");
styleSheet.innerText = styles;
document.head.appendChild(styleSheet);
anim_elm = document.querySelector(".rc-VideoMiniPlayer");
anim_elm.classList.add("jello-vertical");
}//func-jello
}//func-solve
}//func-complete
complete();