-
Notifications
You must be signed in to change notification settings - Fork 0
/
submitter.js
185 lines (169 loc) · 7.31 KB
/
submitter.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
// Deadline calculator:
var timeOut,hrs,mins,secs,givenHr,givenMin,timeNow,given,now,x,countDown,ok,dlChk,subInps,subTime,timer,timerChk,timerlbl,timerInterval,is30=false,isOk=false;
function DLcheckbox() {
dlChk = document.getElementById('DLcheckbox');
timerLbl = document.getElementById('timerLbl');
subTime = document.getElementById('subTime');
if(!dlChk.checked){
timer.innerHTML='-:--:--';
timerChk.click();
clearTimeout(timeOut);
clearInterval(timerInterval);
x.disabled=true;
subInps.disabled=true;
ok.disabled=true;
timerChk.disabled=true;
subTime.style.color='#aaa';
ok.style.backgroundColor='#aaa';
timerLbl.style.color='#aaa';
}
else{
x.disabled=false;
subInps.disabled=false;
ok.disabled=false;
timerChk.disabled=false;
subTime.style.color='#000';
timerLbl.style.color='#000';
ok.style.backgroundColor='#03787c';
timer.style.color='#32cd32';
isOk=false;
}
}
function tmrCheckbox() {
timer = document.getElementById('timer');
if (timerChk.checked){
timer.style.display = 'block';
}
else{
timer.style.display = 'none';
}
}
function runTimer() {
clearInterval(timerInterval);
timerInterval = setInterval(function(){
timer = document.getElementById("timer");
var hours = Math.floor((countDown % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((countDown % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((countDown % (1000 * 60)) / 1000);
if(minutes<10){minutes='0'+minutes}
if(seconds<10){seconds='0'+seconds}
var noHr = minutes + ":" + seconds;
if(hours==0){timer.innerHTML = noHr}
else{timer.innerHTML = hours + ":" + noHr}
if (countDown/1000 < 60 && countDown/1000 > 0 && !is30){
timer.style.color = 'red';
}
else if (countDown/1000 < 60*5 && countDown/1000 > 0 && !is30){
timer.style.color = 'orange';
}
else if (countDown < 0 || is30) {
timer.style.color = '#32cd32';
timer.innerHTML = '-:--:--';
clearInterval(timerInterval);
}
else{
timer.style.color = '#32cd32';
}
countDown-=1000;
},1000);
}
function timing(){
clearTimeout(timeOut);
is30=false;
ok.style.backgroundColor='#000';
givenHr = x.value.substr(0,2);
givenMin = x.value.substr(3,5);
hrs = new Date().getHours();
mins = new Date().getMinutes();
secs = new Date().getSeconds();
timeNow = hrs + ":" + mins;
given = new Date(null,null,null,givenHr,givenMin-1,60-subInps.value);
now = new Date(null,null,null,hrs,mins,secs);
countDown = given-now;
if (countDown > 0 && countDown < 30000){
ok.style.backgroundColor='#03787c';
alert('Cannot set timer below 30 seconds. Please provide a higher value!');
isOk=false;
is30=true;
return 86400000;
}
else if (countDown > 0) {
return countDown;
}
else{
ok.style.backgroundColor='#03787c';
alert('INVALID Deadline!');
clearTimeout(timeOut);
isOk=false;
return 86400000;
}
}
// Identification of unattempted questions:
function isAttempted(qsn) {
var onPC = qsn.getElementsByClassName('office-form-question-choice');
var onMobile = qsn.getElementsByClassName('office-form-question-choice-mobile');
var options=[];
let mLength = onMobile.length;
let pcLength = onPC.length;
if(pcLength != 0){options=onPC}
else if (mLength != 0){options=onMobile}
var attempted = false;
if (pcLength != 0 || mLength != 0) {
for (var i = 0; i<options.length; i++) {
var radio = options[i].getElementsByTagName('input');
var selected = radio[0].ariaChecked == "true";
attempted = attempted || selected;
if (attempted) {break;}
}
return attempted;
}
else{return true;}
}
function unattemptedQs() {
var questions = document.getElementsByClassName('__question__');
var unattempted = [];
let isReq;
for (var i = 0; i<questions.length; i++) {
isReq = questions[i].getElementsByClassName('required-star').length;
if (!isAttempted(questions[i]) && isReq) {
unattempted[unattempted.length] = questions[i];
}
}
return unattempted;
}
// Action:
function randomSelect(unattempted) {
for (var i = 0; i < unattempted.length; i++) {
var onPC = unattempted[i].getElementsByClassName('office-form-question-choice');
var onMobile = unattempted[i].getElementsByClassName('office-form-question-choice-mobile');
var choice = [];
if(onPC.length != 0){choice=onPC;}
else if (onMobile.length != 0){choice=onMobile}
choice[Math.floor(Math.random()*(choice.length))].click();
}
}
// Submission:
function clickSubmit() {
randomSelect(unattemptedQs());
var button = document.getElementsByClassName('__submit-button__')[0];
button.click();
ok.style.backgroundColor='#03787c';
// console.log(document.getElementById('deadLine').value);
// console.log(new Date().getHours()+":"+new Date().getMinutes());
// console.log(hrs+":"+mins+":"+secs);
}
function setTimer() {
isOk=true;
timeOut=setTimeout(clickSubmit,timing());
}
// HTML Injection:
function HTMLinjector() {
var inject = '<div style="padding-top:35px;position:relative;"><div style="padding-left:20px;padding-right:20px;"><div class="question-title-box"><label style="font-weight:NORMAL;margin-left:-10px;"><input type="checkbox" id="DLcheckbox" style="bottom:0;height:18px;margin:auto 0 auto 0;position:absolute;top:0;width:20px;cursor:pointer" checked onclick="DLcheckbox()"><div class="office-form-question-title" style="margin-left:30px;margin-top:2px;cursor:pointer"><span>Deadline:</span></div></label></div><div class="office-form-question-element"><input type="time" id="deadLine" onchange="if(isOk){setTimer();runTimer()}"><br><label style="margin:25px 0 10px;font-weight:NORMAL;"><div style="font-size:14px;margin-top:1px;white-space: normal;margin-left:0px;display:inline;" class="office-form-question-title"><span id="subTime">Submit before:</span></div></label><select id="subInps" style="width:100px;margin-left:5px;border-radius:5px;" onchange="if(isOk){setTimer();runTimer()}"><option value="10">10 seconds</option><option value="20">20 seconds</option><option value="30">30 seconds</option><option value="45">45 seconds</option></select><br><label style="margin:10px 0"><input type="checkbox" checked="" id="timerChk" style="height:12px;position:absolute;width:20px;cursor:pointer;" onclick="tmrCheckbox()"><div style="margin-left:25px;cursor:pointer;font-weight:NORMAL;font-size:14px;margin-top:1px;white-space:normal;" class="office-form-question-title"><span id="timerLbl">SHOW TIMER</span></div></label></div><button id="okButton" class="light-background-button" onclick="setTimer();runTimer();">OK</button></div></div><style type="text/css">#deadLine{background-color:#fff;text-align:center;font-size:15px;height:40px;padding:12px;width:15%}#okButton{margin:10px 0 0 20px;background:#03787c;color:#fff;font-size:15px;height:35px;text-align:center;width:50px}#timer{font-size:60px;top:-50px;color:#32cd32;background-color:black;right:25px;position:fixed;line-height:normal;z-index:1;padding:0 15px;border-radius:15px;font-family:monospace;}@media only screen and (max-width:375px){#deadLine{width:50%}#okButton{margin-left:0px}#timer{top:-35px;font-size:45px;right:10px;padding:0 15px;}}</style>';
document.getElementsByClassName("office-form-notice-container")[0].innerHTML += inject;
document.getElementsByClassName("__title__")[0].innerHTML += '<p id="timer">-:--:--</p>'
}
HTMLinjector();
timerChk = document.getElementById('timerChk');
subInps = document.getElementById('subInps');
ok = document.getElementById('okButton');
x = document.getElementById('deadLine');