forked from hackeysackers/seesecurity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.html
338 lines (304 loc) · 11.5 KB
/
demo.html
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=utf-8">
<TITLE>Simple Demonstration of how WebGazer.js works</TITLE>
<link rel="stylesheet" type="text/css" href="styles.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</HEAD>
<BODY LANG="en-US" LINK="#0000ff" DIR="LTR">
<div class="fullBodyImg">
<img id="calibrateImg1" src="calibration-green(1).png" style="position: absolute; top: 0; left: 0;">
<img id="calibrateImg2" src="calibration-green(2).png" style="position: absolute; top: 0; left: 0;">
<img id="calibrateImg3" src="calibration-green(3).png" style="position: absolute; top: 0; left: 0;">
<img id="calibrateImg4" src="calibration-green(4).png" style="position: absolute; top: 0; left: 0;">
<img id="calibrateImg5" src="calibration-green(5).png" style="position: absolute; top: 0; left: 0;">
<img id="calibrateImg6" src="calibration-green(6).png" style="position: absolute; top: 0; left: 0;">
<img id="calibrateImg7" src="calibration-green(7).png" style="position: absolute; top: 0; left: 0;">
<img id="calibrateImg8" src="calibration-green(8).png" style="position: absolute; top: 0; left: 0;">
<img id="calibrateImg9" src="calibration-green(9).png" style="position: absolute; top: 0; left: 0;">
<img id="calibrateImg0" src="calibration.png" style="position: relative; top: 0; left: 0; z-index:999">
</div>
<div id = "eyes" class="center">
<ul>
<li>
<img id="statusImg1" src="https://d30y9cdsu7xlg0.cloudfront.net/png/204724-200.png" style="position: relative;">
</li>
<li>
<img id="statusImg2" src="https://d30y9cdsu7xlg0.cloudfront.net/png/204724-200.png" style="position: relative;">
</li>
<li>
<img id="statusImg3" src="https://d30y9cdsu7xlg0.cloudfront.net/png/204724-200.png" style="position: relative;">
</li>
</ul>
</div>
<script src="build/webgazer.js"></script>
<script>
// for the status toggle
var counter = 0;
function toggleStatus() {
counter++;
if (counter == 1) {
document.getElementById('statusImg1').src = "http://www.freeiconspng.com/uploads/eyeball-icon-png-eye-icon-1.png";
} else if (counter == 2) {
document.getElementById('statusImg2').src = "http://www.freeiconspng.com/uploads/eyeball-icon-png-eye-icon-1.png";
} else if (counter == 3) {
document.getElementById('statusImg3').src = "http://www.freeiconspng.com/uploads/eyeball-icon-png-eye-icon-1.png";
}
}
function resetEyes() {
for(var j = 1; j < 4; j++){
document.getElementById('statusImg'+j).src = "https://d30y9cdsu7xlg0.cloudfront.net/png/204724-200.png";
}
}
document.body.onmousedown = function() {
++mouseDown;
}
document.body.onmouseup = function() {
--mouseDown;
}
var domID = "calibrateImg";
function showhide(domID) {
console.log(domID);
var img = document.getElementById(domID);
if (img.style.visibility === 'hidden') {
// Currently hidden, make it visible
img.style.visibility = "visible";
} else {
// Currently visible, make it hidden
img.style.visibility = "hidden";
}
}
for(var i = 0; i < 10; i++){
var string = domID + i;
showhide(string);
}
function removeLayers() {
for(var i = 0; i < 10; i++){
var string = domID + i;
var img = document.getElementById(string);
if (img.style.visibility === 'visible'){
img.style.visibility = "hidden";
}
}
}
var w = window.innerWidth;
var h = window.innerHeight;
var init = 0;
// number of tries
var tries = 0;
var first = 0;
var second = 0;
var calibrationComplete = 0;
var sectorsVisited = [];
var calibratedSectors = [];
var sectorCounters = [];
var sectorClicks = [];
//how many ints have been added to the guess
var attemptCodeCounter = 0;
var addedCounter = 0;
//how many ints added to the secret code
//hard coded for now, later during initiate calibration
//it will set the secret password
var secretCodeCounter = 3;
//hard coded for now
var secretCode = [1, 6, 7];
var mouseDown = 0;
var initiateCalibration = function() {
alert("Drag your cursor and click three times " +
"over each of the 9 grey boxes." +
" When that box turns green, it has been calibrated.");
}
var compareCodes = function(secretCode, sectorsVisited, sector) {
for(i = secretCode.length; i--;) {
if(secretCode[i] !== sectorsVisited[i]){
tries++;
if(tries > 5){
alert("You have exceded your tries. Now exiting.");
exit();
}
else{
resetEyes();
sectorsVisited.length = 0;
addedCounter = 0;
counter = 0;
sectorCounters[sector-1] = 0;
return;
}
}
}
// match has been found
alert("Congrats! Match has been found for " + secretCode);
exit();
}
var addToArray = function(sector) {
if (sectorsVisited[sectorsVisited.length - 1] != sector) {
sectorsVisited.push(sector);
addedCounter++;
toggleStatus();
alert(sectorsVisited + " current sector vals");
// if the added counter is equal to the true counter
if(addedCounter == secretCodeCounter){
compareCodes(secretCode, sectorsVisited, sector);
}
}
}
var checkIfCalibrationComplete = function(calibratedSectors) {
for(i = 0; i < 9; i++){
if(calibratedSectors[i] == 0){
return false;
}
}
alert("Calibration complete. Please enter passcode.");
calibrationComplete = 1;
removeLayers();
return true;
}
var trackSector = function(sector) {
// reset every value except for the one we're currently one
for (i = 0; i < 9; i++) {
if (i != sector - 1) {
sectorCounters[i] = 0;
}
}
// increment the counter
sectorCounters[sector - 1]++;
// if it has reached the threshold, add it officially
if (calibrationComplete == 0 && mouseDown == 1) {
sectorClicks[sector - 1]++;
// console.log("click");
if(sectorClicks[sector - 1] == 3){
removeLayers();
string = domID + sector;
showhide(string);
calibratedSectors[sector-1]++;
if(checkIfCalibrationComplete(calibratedSectors) == true){
console.log("calibration complete");
}
}
// mouseDown--;
}
if (calibrationComplete == 1 && sectorCounters[sector - 1] > 100) {
//console.log("HERE");
addToArray(sector);
}
}
var classifer = function(x, y){
// leftmost column
if(x < (w/5)){
if(y < 3*h/8){
trackSector(1);
} else if(y < (3*h/4) && y > 3*h/8){
trackSector(4);
} else if (y > 3*h/4) {
trackSector(7);
}
}
// middle column
if (2*w/5 < x && x < 4*w/5) {
if(y < 3*h/8){
trackSector(2);
} else if(y < (3*h/4) && y > 3*h/8){
trackSector(5);
} else if (y > 3*h/4) {
trackSector(8);
}
}
// rightmost column
if (4*w/5 < x) {
if(y < 3*h/8){
trackSector(3);
} else if(y < (3*h/4) && y > 3*h/8){
trackSector(6);
} else if (y > 3*h/4) {
trackSector(9);
}
}
}
window.onload = function() {
initiateCalibration();
webgazer.setRegression('ridge') /* currently must set regression and tracker */
.setTracker('clmtrackr')
.setGazeListener(function(data, clock) {
if(calibrationComplete == 0 && data != null){
if(first == 0){
first = 1;
showhide("calibrateImg0");
}
classifer(data.x, data.y);
}
else if(calibrationComplete == 1 && data != null){
if(second == 0){
second = 1;
}
//webgazer.clearGazeListener();
classifer(data.x, data.y);
}
})
.begin()
.showPredictionPoints(true); /* shows a square every 100 milliseconds where current prediction is */
var width = window.innerWidth/5;
var height = window.innerHeight/4;
var topDist = '0px';
var leftDist = '0px';
var setup = function() {
var video = document.getElementById('webgazerVideoFeed');
video.style.display = 'block';
video.style.position = 'absolute';
video.style.top = topDist;
video.style.left = leftDist;
video.width = width;
video.height = height;
video.style.margin = '0px';
webgazer.params.imgWidth = width;
webgazer.params.imgHeight = height;
var overlay = document.createElement('canvas');
overlay.id = 'overlay';
overlay.style.position = 'absolute';
overlay.width = width;
overlay.height = height;
overlay.style.top = topDist;
overlay.style.left = leftDist;
overlay.style.margin = '0px';
document.body.appendChild(overlay);
var cl = webgazer.getTracker().clm;
// initialize the empty array with zeroes
function initializeArray() {
for (i = 0; i < 9; i++) {
sectorCounters.push(0);
sectorClicks.push(0);
calibratedSectors.push(0);
}
}
function drawLoop() {
requestAnimFrame(drawLoop);
overlay.getContext('2d').clearRect(0,0,width,height);
if (cl.getCurrentPosition()) {
cl.draw(overlay);
}
}
drawLoop();
initializeArray();
};
function checkIfReady() {
if (webgazer.isReady()) {
setup();
} else {
setTimeout(checkIfReady, 100);
}
}
setTimeout(checkIfReady,100);
};
window.onbeforeunload = function() {
//webgazer.end(); //Uncomment if you want to save the data even if you reload the page.
window.localStorage.clear(); //Comment out if you want to save data across different sessions
}
</script>
</BODY>
</HTML>