-
Notifications
You must be signed in to change notification settings - Fork 0
/
listener.js
1277 lines (1079 loc) · 34.8 KB
/
listener.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
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* @Author : Abdullah Ali, Tejas Bhalerao
* @Date : 2017-05-29 00:37:13
* @Description : This script is the content script responsible for capturing user's mouse movement data and generating notifications
* @Last Modified by : Tejas
* @Last Modified time: 2017-05-29 01:04:51
* @Contact : @xyleques, xyleques@me.com; tejasbhalerao01@gmail.com
* @version : 2
*/
// for testing purposes
console.log("Test PINATA is starting...");
//decalre all user data metrics to capture
var url = [];
var type = [];
var tStamp = [];
var se_X = [];
var se_Y = [];
var se_targets = [];
var se_tIDs = [];
var se_tH = [];
var se_tW = [];
var se_tTags = [];
var se_tL = [];
var se_tT = [];
var se_tA = [];
var se_tCx = [];
var se_tCy = [];
var se_tP = [];
var se_trP = [];
var win_h = [];
var win_w = [];
var num_clicks = 0;
var slips = [];
var click_durations = [];
var pause = [];
var batchSize = 100;
var writeCounter = 0;
// Slip Distance
// starting X position for the slip distance
var start_slip_x;
// starting y position for the slip distance
var start_slip_y;
// ending X position for the slip distance
var end_slip_x;
// ending y position for the slip distance
var end_slip_y;
// The distance of the slip
var SLIP_DISTANCE;
// Slip Distance
// Click duration
// The start time for a click
var start_mil = new Date();
// The end time for a click
var end_mil = new Date();
// The click duration in milliseconds
var CLICK_DURATION;
// Click duration
// Pause timing
var pauseTemp = [];
var PAUSE_TIME;
//////////////////////////////// Pointer Behavior \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
////////////// Mouse behavior handeling functions \\\\\\\\\\\\\\\
// FUNCTION: Save the X, Y coordinates where the mouse was clicked in 2 variables
document.onclick = function(e) {
};
// FUNCTION: Save the X, Y coordinates where the mouse was moved in 2 variables
// Get information about whatever element the cursor is hovering on
document.onmousemove = function(e) {
//check if the user data has reached max batch size and then store data to server in batch
performBatchRoutine();
//start capturing user movement data
url.push(getCurrentURL());
type.push("mouse move");
tStamp.push(new Date());
//get pointer positions
var move_x = e.pageX;
se_X.push(move_x);
var move_y = e.pageY;
se_Y.push(move_y);
//get hovered target
var hTarget = e.target;
se_targets.push(hTarget);
// Ignoring undefined targets
if (hTarget == "undefined") {
} else{
}
var hTid = hTarget.id;
se_tIDs.push(hTid);
//get target height
var hTarget_properties = window.getComputedStyle(hTarget, null);
var hTarget_height = hTarget_properties.height;
hTarget_height = clearPx(hTarget_height);
se_tH.push(hTarget_height);
//get target width
var hTarget_width = hTarget_properties.width;
hTarget_width = clearPx(hTarget_width);
se_tW.push(hTarget_width);
//get element type by HTML tag
var hTarget_tagName = hTarget.tagName;
se_tTags.push(hTarget_tagName);
//get the element's position from the left of the screen
var hLeft = getOffsetLeft(hTarget);
se_tL.push(hLeft);
//get the element's position from the top of the screen
var hTop = getOffsetTop(hTarget);
se_tT.push(hTop);
//calculate the area of the element
var hArea = getElemArea(hTarget_height, hTarget_width);
se_tA.push(hArea);
// Get the coordiantes of center point of the element
var hCenter = getCenter(hLeft, hTop, hTarget_height, hTarget_width);
se_tCx.push(hCenter.x);
se_tCy.push(hCenter.y);
// Pointing precision. The shortest line distance between the pointer and the center of the element
var p = getSlip (hCenter.x, hCenter.y, move_x, move_y);
se_tP.push(p);
var rP = getRelativeP(p, hArea);
se_trP.push(rP);
//get window height
var cWin_h = screen.height;
win_h.push(cWin_h);
//get window width
var cWin_w = screen.width;
win_w.push(cWin_w);
//slips
slips.push("");
//click durations
click_durations.push("");
//pause time
pauseTemp.push(new Date().getTime());
if(pauseTemp.length >= 2) {
var n = pauseTemp.length;
PAUSE_TIME = pauseTemp[n-1] - pauseTemp[n-2];
PAUSE_TIME = PAUSE_TIME/1000;
pause.push(PAUSE_TIME);
//notification
notification("move");
}
};
// FUNCTION: Onmousedown:
/* Save the start time of a click
Save the initial mouse position of a click
*/
document.onmousedown = function(e)
{
performBatchRoutine();
url.push(getCurrentURL());
type.push("mouse down");
tStamp.push(new Date());
// The time the click started
start_mil = new Date();
// X, Y position of the mouse when the click started
start_slip_x = e.pageX;
start_slip_y = e.pageY;
//get pointer positions
var move_x = e.pageX;
se_X.push(move_x);
var move_y = e.pageY;
se_Y.push(move_y);
// coor += "X:" + e.pageX + " Y:" + e.pageY +"-";
//get hovered target
var hTarget = e.target;
se_targets.push(hTarget);
// Ignoring undefined targets
if (hTarget == "undefined") {
} else {
}
var hTid = hTarget.id;
se_tIDs.push(hTid);
//get target height
var hTarget_properties = window.getComputedStyle(hTarget, null);
var hTarget_height = hTarget_properties.height;
hTarget_height = clearPx(hTarget_height);
se_tH.push(hTarget_height);
//get target width
var hTarget_width = hTarget_properties.width;
hTarget_width = clearPx(hTarget_width);
se_tW.push(hTarget_width);
//get element type by HTML tag
var hTarget_tagName = hTarget.tagName;
se_tTags.push(hTarget_tagName);
//get the element's position from the left of the screen
var hLeft = getOffsetLeft(hTarget);
se_tL.push(hLeft);
//get the element's position from the top of the screen
var hTop = getOffsetTop(hTarget);
se_tT.push(hTop);
//calculate the area of the element
var hArea = getElemArea(hTarget_height, hTarget_width);
se_tA.push(hArea);
//get the coordiantes of center point of the element
var hCenter = getCenter(hLeft, hTop, hTarget_height, hTarget_width);
se_tCx.push(hCenter.x);
se_tCy.push(hCenter.y);
//Pointing precision. The shortest line distance between the pointer and the center of the element
var p = getSlip (hCenter.x, hCenter.y, move_x, move_y);
se_tP.push(p);
var rP = getRelativeP(p, hArea);
se_trP.push(rP);
//get window height
var cWin_h = screen.height;
win_h.push(cWin_h);
//get window height
var cWin_w = screen.width;
win_w.push(cWin_w);
//slips
slips.push("");
//click durations
click_durations.push("");
//pause time
pause.push("");
};
// Function: Onmouseup:
/* Save the end time of a click
Calculate the click duration
Save the end position of the mouse
Calculate the slip distance
*/
document.onmouseup = function(e)
{
performBatchRoutine();
url.push(getCurrentURL());
type.push("mouse up");
tStamp.push(new Date());
//the time the click ended
end_mil = new Date();
//click duration
CLICK_DURATION = end_mil - start_mil;
click_durations.push(CLICK_DURATION);
// X, Y position of the mouse when the click started
end_slip_x = e.pageX;
end_slip_y = e.pageY;
//slips
var slip = getSlip(start_slip_x, start_slip_y, end_slip_x, end_slip_y);
slips.push(slip);
//get pointer positions
var move_x = e.pageX;
se_X.push(move_x);
var move_y = e.pageY;
se_Y.push(move_y);
// coor += "X:" + e.pageX + " Y:" + e.pageY +"-";
//get hovered target
var hTarget = e.target;
se_targets.push(hTarget);
// Ignoring undefined targets
if (hTarget == "undefined") {
} else{
}
var hTid = hTarget.id;
se_tIDs.push(hTid);
//get target height
var hTarget_properties = window.getComputedStyle(hTarget, null);
var hTarget_height = hTarget_properties.height;
hTarget_height = clearPx(hTarget_height);
se_tH.push(hTarget_height);
//get target width
var hTarget_width = hTarget_properties.width;
hTarget_width = clearPx(hTarget_width);
se_tW.push(hTarget_width);
//get element type by HTML tag
var hTarget_tagName = hTarget.tagName;
se_tTags.push(hTarget_tagName);
//get the element's position from the left of the screen
var hLeft = getOffsetLeft(hTarget);
se_tL.push(hLeft);
//get the element's position from the top of the screen
var hTop = getOffsetTop(hTarget);
se_tT.push(hTop);
//calculate the area of the element
var hArea = getElemArea(hTarget_height, hTarget_width);
se_tA.push(hArea);
//get the coordiantes of center point of the element
var hCenter = getCenter(hLeft, hTop, hTarget_height, hTarget_width);
se_tCx.push(hCenter.x);
se_tCy.push(hCenter.y);
//Pointing precision. The shortest line distance between the pointer and the center of the element
var p = getSlip (hCenter.x, hCenter.y, move_x, move_y);
se_tP.push(p);
var rP = getRelativeP(p, hArea);
se_trP.push(rP);
//get window height
var cWin_h = screen.height;
win_h.push(cWin_h);
//get window width
var cWin_w = screen.width;
win_w.push(cWin_w);
//num clicks
num_clicks++;
//pause
pause.push("");
//set data in chrome storage
chrome.storage.sync.set({
'num_clicks': num_clicks,
// 'timeStamp': tStamp,
'slips': slips,
'clickTiming': CLICK_DURATION
// 'pause': pause
}, function(){});
//compare and store data in chrome storage
chrome.storage.sync.get(null, function(items) { // null implies all items
//Slip/Click Ratio
if (items.t_num_clicks == null || items.t_num_clicks == "undefined") {
chrome.storage.sync.set({
't_num_clicks': items.num_clicks
}, function(){});
} else {
chrome.storage.sync.set({
't_num_clicks': items.t_num_clicks + items.num_clicks
}, function(){});
}
if (items.t_num_slips == null || items.t_num_slips == "undefined") {
chrome.storage.sync.set({
't_num_slips': slipCounter(items.slips)
}, function(){});
} else {
chrome.storage.sync.set({
't_num_slips': items.t_num_slips + slipCounter(items.slips)
}, function(){});
}
// //Adaptations
// if (items.t_num_slips == null || items.t_num_slips == "undefined") {
// chrome.storage.sync.set({
// 'slip_prefAdapt': items.slip_prefAdapt
// }, function(){});
// } else {
// chrome.storage.sync.set({
// 'slip_prefAdapt': items.slip_prefAdapt
// }, function(){});
// }
});
//show notification
notification("up");
}; //End of onmouseup
function resetUserData() {
url = [];
type = [];
tStamp = [];
se_X = [];
se_Y = [];
se_targets = [];
se_tIDs = [];
se_tH = [];
se_tW = [];
se_tTags = [];
se_tL = [];
se_tT = [];
se_tA = [];
se_tCx = [];
se_tCy = [];
se_tP = [];
se_trP = [];
win_h = [];
win_w = [];
slips = [];
click_durations = [];
pause = [];
}
function sendBgMessage(message){
// Send message with user data to background page to be sent to server
chrome.runtime.sendMessage(
{
message : message,
writeCounter : writeCounter,
batchSize : batchSize,
url : url,
type : type,
timeStamp : tStamp,
x : se_X,
y : se_Y,
targets : se_targets,
tID : se_tIDs,
heights : se_tH,
widths : se_tW ,
tags : se_tTags,
left : se_tL,
top : se_tT,
area : se_tA,
Center_X : se_tCx,
Center_Y : se_tCy,
precision : se_tP,
relPrecision : se_trP,
win_height : win_h,
win_width : win_w,
num_clicks : num_clicks,
slips : slips,
click_durations: click_durations,
pause : pause
},
function(response) {
if (response.responseMessage === "roger") {
console.log("Resetting user data...");
resetUserData();
}
});
}
function performBatchRoutine() {
if(isStorageFull(url, batchSize)) {
writeCounter ++;
console.log("Sending Batch #" + writeCounter);
//send message to background page
sendBgMessage("send");
}
}
////////////// Mouse behavior handeling functions \\\\\\\\\\\\\\\
///////////////////////////////////// Pointer Behavior \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
////////////////////////////////////////// Notifications And Adaptations \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
////////////// Options \\\\\\\\\\\\\\\
// bar options
var posTop;
var posBtm;
var barPlusDismissFlag = false; //false: not clicked, true: clicked
var barPlusAdaptFlag = false; //false: not clicked, true: clicked
var dialogBoxDismissFlag = false; //false: not clicked, true: clicked
var dialogBoxAdaptFlag = false; //false: not clicked, true: clicked
// pause timing
var ptFlag;
var ptRel;
var ptValue;
var ptViz;
var ptPosTop;
var ptPosBtm;
var ptThick;
var ptBarColor;
////////////// Options \\\\\\\\\\\\\\\
///////////// Talking to options.js for notification preferences \\\\\\\\\\\\\\\
//************** Get Store **************//
chrome.storage.sync.get({
ptFlag : false,
ptRel : false,
ptValue : "gt",
ptViz : "ptBar",
ptPosTop : true,
ptPosBtm : false,
ptThick : "5",
ptBarColor: "#fc2862"
}, function(items) {
ptFlag = items.ptFlag,
ptRel = items.ptRel,
ptValue = items.ptValue,
ptViz = items.ptViz,
ptPosTop = items.ptPosTop,
ptPosBtm = items.ptPosBtm,
ptThick = items.ptThick,
ptBarColor= items.ptBarColor
});
///////////// Talking to options.js for notification preferences \\\\\\\\\\\\\\\
///////////// Feedback HTML elements \\\\\\\\\\\\\\\
//This is javascript code that creates HTML elements to be injected on web pages
///////////// Bar \\\\\\\\\\\\\\\
// This is the HTML element for the Bar notification
// Create a DIV element
var barElement=document.createElement("DIV");
barElement.style.display = "none";
// Fixed position
barElement.style.position = "fixed";
// Top of the page
// bar position
// barElement.style.top = "0px";
// As wide as the page
barElement.style.width = "100%";
// 3px in height
// barElement.style.height= "5px";
// z-index set to 999 so the DIV would appear on top of other elements of the page
barElement.style.zIndex = "2147483647";
// Set the background
// barElement.style.background = "#fc2862";
// Add blank text to the DIV so it would show
var tmp = document.createTextNode("");
barElement.appendChild(tmp);
// Add the DIV element to the body of the page
document.body.appendChild(barElement);
//ct Bar
var ctBarElement = barElement;
document.body.appendChild(ctBarElement);
//pt Bar
var ptBarElement = barElement;
document.body.appendChild(ptBarElement);
///////////// Bar \\\\\\\\\\\\\\\
///////////// Bar+ \\\\\\\\\\\\\\\
// This is the HTML element for the Bar+ notification
// Create a DIV element
var barPlusElement=document.createElement("DIV");
// Hide the Bar+ by default, it will show when triggered
barPlusElement.style.display = "none";
// Fixed position
barPlusElement.style.position = "fixed";
// Top of the page
barPlusElement.style.top = "0px";
// As wide as the page
barPlusElement.style.width = "100%";
// 3px in height
barPlusElement.style.height= "45px";
// z-index set to 999 so the DIV would appear on top of other elements of the page
barPlusElement.style.zIndex = "2147483647";
// Set the background
barPlusElement.style.background = "#efefef";
// Set text color
barPlusElement.style.color = "#656565";
// Set text size
barPlusElement.style.fontSize = "10pt";
// Set text type
barPlusElement.style.fontFamily = "Helvetica" ;
// Set bottom border
barPlusElement.style.borderBottom = "1px solid #ccc";
// Set padding
barPlusElement.style.padding = "5px";
// Add shadow to give layering illusion, this element is on top of the page
barPlusElement.style.boxShadow = "2px 1px 1px #000";
// Add logo to Bar+ notification
var logoBP = document.createElement("IMG");
logoBP.src = chrome.extension.getURL("img/newConceptCircleYellow.png");
logoBP.style.display = "block";
logoBP.style.width = "35px";
logoBP.style.height = "35px";
logoBP.style.float = "left";
logoBP.style.marginLeft = "10px";
logoBP.style.marginTop = "7px";
barPlusElement.appendChild(logoBP);
// Add the notification text to the Bar+ element
var notifBPTxt=document.createElement("DIV");
notifBPTxt.style.display = "block";
notifBPTxt.style.float = "left";
// notifBPTxt.style.clear = "both";
notifBPTxt.style.width = "50%";
notifBPTxt.style.height = "45px";
notifBPTxt.style.paddingTop = "5px";
notifBPTxt.style.marginLeft = "10px";
notifBPTxt.style.lineHeight = "15px";
notifBPTxt.style.color = "#000";
notifBPTxt.innerHTML = "The webpage you are currently browsing seems to have small, hard to click targets.<br> Would you like the page to be zoomed in for a more enjoyable browsing experience?";
barPlusElement.appendChild(notifBPTxt);
// Buttons \\
// Dismiss \\
// Add dismiss button to the barPlusElement div
var dismissBarP=document.createElement("DIV");
// Style the dismiss button
dismissBarP.style.width = "100px";
dismissBarP.style.height = "20px";
dismissBarP.style.padding = "2px";
dismissBarP.style.textAlign = "center";
dismissBarP.style.lineHeight = "20px";
dismissBarP.style.background ="#fff";
dismissBarP.style.boxShadow = "0 2px 5px 0 rgba(0, 0, 0, 0.26)";
dismissBarP.style.margin = "3px";
dismissBarP.style.cursor = "pointer";
dismissBarP.style.float = "right";
dismissBarP.style.marginRight = "10px";
dismissBarP.style.borderTop = "3px solid #93bfdb";
dismissBarP.style.borderRadius = "2px";
// Add functionality to the dismiss button
dismissBarP.onclick = dismissBarPlus;
// Add text to the dismiss button
var dismissTxt = document.createTextNode("Dismiss");
dismissBarP.appendChild(dismissTxt);
// Add the dismiss button to the barPlusElement
barPlusElement.appendChild(dismissBarP);
// Dismiss \\
// Adapt \\
// Add dismiss button to the barPlusElement div
var adaptZoomBarP=document.createElement("DIV");
// Style the dismiss button
adaptZoomBarP.style.width = "100px";
adaptZoomBarP.style.height = "20px";
adaptZoomBarP.style.padding = "2px";
adaptZoomBarP.style.textAlign = "center";
adaptZoomBarP.style.lineHeight = "20px";
adaptZoomBarP.style.background ="#fff";
adaptZoomBarP.style.boxShadow = "0 2px 5px 0 rgba(0, 0, 0, 0.26)";
adaptZoomBarP.style.margin = "3px";
adaptZoomBarP.style.cursor = "pointer";
adaptZoomBarP.style.float = "right";
adaptZoomBarP.style.marginRight = "10px";
adaptZoomBarP.style.borderTop = "3px solid #bada55";
adaptZoomBarP.style.borderRadius = "2px";
// Add functionality to the dismiss button
adaptZoomBarP.onclick = adaptUIZoomBarPlus;
// Add text to the dismiss button
var adaptZBPtxt = document.createTextNode("Adapt my UI");
adaptZoomBarP.appendChild(adaptZBPtxt);
// Add the dismiss button to the barPlusElement
barPlusElement.appendChild(adaptZoomBarP);
// Adapt \\
// Buttons \\
// Add the DIV element to the body of the page
document.body.appendChild(barPlusElement);
//ct Bar
var ctBarPlusElement = barPlusElement;
document.body.appendChild(ctBarPlusElement);
//pt Bar
var ptBarPlusElement = barPlusElement;
document.body.appendChild(ptBarPlusElement);
// Bar+ functions \\
function dismissBarPlus(){
// Dismissing the Bar+ will turn off the notification Bar+
barPlusDismissFlag = true;
barPlusAdaptFlag = false;
}
function adaptUIZoomBarPlus(){
// Turn on zoom adaptation, and turn off Bar+ notification
// console.log("Adapting the UI, zoomAdapt is: " + zoomAdapt + " the Bar+ is: " + barPlus);
barPlusAdaptFlag = true;
barPlusDismissFlag = false;
}
// Bar+ functions \\
///////////// Bar+ \\\\\\\\\\\\\\\
///////////// Dialog \\\\\\\\\\\\\\\
// This is the HTML element for the Bar+ notification
// Create a DIV element
var dialogElement=document.createElement("DIV");
dialogElement.id = "dialog";
// Hide the Bar+ by default, it will show when triggered
dialogElement.style.display = "none";
// Fixed position
dialogElement.style.position = "fixed";
// dialogElement.style.margin = "0 0 0 -40%";
// Top of the page
var w = window.innerWidth;
// console.log("width is: " + w);
var h = window.innerHeight;
var leftPos = (w/2) - 200;
// console.log("left position is: " + leftPos);
dialogElement.style.top = "35%";
dialogElement.style.left = leftPos+"px";
// As wide as the page
dialogElement.style.width = "400px";
// 3px in height
dialogElement.style.height= "150px";
// z-index set to 999 so the DIV would appear on top of other elements of the page
dialogElement.style.zIndex = "2147483647";
// Set the background
dialogElement.style.background = "#fbfbfb";
// Set text color
dialogElement.style.color = "#656565";
// Set text size
dialogElement.style.fontSize = "10pt";
// Set text type
dialogElement.style.fontFamily = "Helvetica" ;
// Set bottom border
dialogElement.style.border = "1px solid #ccc";
// Set padding
dialogElement.style.padding = "5px";
// Add shadow to give layering illusion, this element is on top of the page
dialogElement.style.boxShadow = "0 8px 17px 0 rgba(0, 0, 0, 0.2)";
// Add logo to Bar+ notification
var dLogoBP = document.createElement("IMG");
dLogoBP.src = chrome.extension.getURL("img/newConceptCircleYellow.png");
dLogoBP.style.display = "block";
dLogoBP.style.width = "35px";
dLogoBP.style.height = "35px";
dLogoBP.style.float = "left";
dLogoBP.style.marginLeft = "10px";
dLogoBP.style.marginTop = "7px";
dialogElement.appendChild(dLogoBP);
// Add the notification text to the Bar+ element
var dNotifBPTxt=document.createElement("DIV");
dNotifBPTxt.style.display = "block";
dNotifBPTxt.style.float = "left";
// dNotifBPTxt.style.clear = "both";
dNotifBPTxt.style.width = "340px";
// dNotifBPTxt.style.height = "45px";
dNotifBPTxt.style.paddingTop = "5px";
dNotifBPTxt.style.marginLeft = "10px";
dNotifBPTxt.style.marginBottom = "20px";
dNotifBPTxt.style.lineHeight = "15px";
dNotifBPTxt.style.color = "#000";
dNotifBPTxt.innerHTML = "The webpage you are currently browsing seems to have small, hard to click targets!<br> <br> Would you like the page to be zoomed in for a more enjoyable browsing experience?";
dialogElement.appendChild(dNotifBPTxt);
var clear=document.createElement("DIV");
clear.style.clear= "both";
dialogElement.appendChild(clear);
// Buttons \\
// Dismiss \\
// Add dismiss button to the dialogElement div
var dismissDialog=document.createElement("DIV");
// Style the dismiss button
dismissDialog.style.width = "100px";
dismissDialog.style.height = "20px";
dismissDialog.style.padding = "2px";
dismissDialog.style.textAlign = "center";
dismissDialog.style.lineHeight = "20px";
dismissDialog.style.background ="#fff";
dismissDialog.style.boxShadow = "0 2px 5px 0 rgba(0, 0, 0, 0.26)";
dismissDialog.style.margin = "3px";
dismissDialog.style.marginRight = "90px";
dismissDialog.style.cursor = "pointer";
dismissDialog.style.float = "right";
dismissDialog.style.borderTop = "3px solid #93bfdb";
dismissDialog.style.borderRadius = "3px";
// Add functionality to the dismiss button
dismissDialog.onclick = dismissDialogPlus;
// Add text to the dismiss button
var dismissDTxt = document.createTextNode("Dismiss");
dismissDialog.appendChild(dismissDTxt);
// Add the dismiss button to the dialogElement
dialogElement.appendChild(dismissDialog);
// Dismiss \\
// Adapt \\
// Add dismiss button to the dialogElement div
var adaptZoomDialog=document.createElement("DIV");
// Style the dismiss button
adaptZoomDialog.style.width = "100px";
adaptZoomDialog.style.height = "20px";
adaptZoomDialog.style.padding = "2px";
adaptZoomDialog.style.textAlign = "center";
adaptZoomDialog.style.lineHeight = "20px";
adaptZoomDialog.style.background ="#fff";
adaptZoomDialog.style.boxShadow = "0 2px 5px 0 rgba(0, 0, 0, 0.26)";
adaptZoomDialog.style.margin = "3px";
adaptZoomDialog.style.marginLeft = "90px";
adaptZoomDialog.style.cursor = "pointer";
adaptZoomDialog.style.float = "left";
adaptZoomDialog.style.borderTop = "3px solid #bada55";
adaptZoomDialog.style.borderRadius = "3px";
// Add functionality to the dismiss button
adaptZoomDialog.onclick = adaptUIZoomDialog;
// Add text to the dismiss button
var adaptZBPtxt = document.createTextNode("Adapt my UI");
adaptZoomDialog.appendChild(adaptZBPtxt);
// Add the dismiss button to the dialogElement
dialogElement.appendChild(adaptZoomDialog);
// Adapt \\
// Buttons \\
// Add the DIV element to the body of the page
document.body.appendChild(dialogElement);
//ct
var ctDialogElement = dialogElement;
document.body.appendChild(ctDialogElement);
//pt
var ptDialogElement = dialogElement;
document.body.appendChild(ptDialogElement);
// Dialog functions \\
function dismissDialogPlus(){
// Dismissing the Bar+ will turn off the notification Bar+
dialogBoxDismissFlag = true;
dialogBoxAdaptFlag = false;
}
function adaptUIZoomDialog(){
// Turn on zoom adaptation, and turn off Bar+ notification
// console.log("Adapting the UI, zoomAdapt is: " + zoomAdapt + " the Bar+ is: " + dialogBox);
// zoomAdapt = true;
dialogBoxAdaptFlag = true;
dialogBoxDismissFlag = false;
}
// dialog functions \\
///////////// Dialog \\\\\\\\\\\\\\\
///////////// Feedback HTML elements \\\\\\\\\\\\\\\
///////////// Functions for notifications and adaptations \\\\\\\\\\\\\\\
function notification(nType) {
if(nType === "move") {
//display pause timing notification
if (ptFlag &&
((ptRel === "gt" && PAUSE_TIME > ptValue) ||
(ptRel === "lt" && PAUSE_TIME < ptValue) ||
(ptRel === "et" && PAUSE_TIME == ptValue))) {
/////////// Bar notification \\\\\\\\\\
if (ptViz === "ptBar") {
// turn on Bar notification only if there is an ineffective click
ptBarElement.style.display = "block";
// Position
if(ptPosTop === true) {
ptBarElement.style.top = "0px";
} else {
ptBarElement.style.bottom = "0px";
}
// thickness
ptBarElement.style.height = ptThick + "px";
//color
ptBarElement.style.background = ptBarColor;
document.documentElement.style.position = "relative";
document.documentElement.style.top = "5px";
}
/////////// Bar+ notification \\\\\\\\\\
else if (ptViz === "ptBarPlus") {
// turn on Bar+ notification
ptBarPlusElement.style.display = "block";
ptBarPlusElement.style.background = "#bada55";
ptBarPlusElement.style.background = "#efefef";
document.documentElement.style.position = "relative";
document.documentElement.style.top = "45px";
if(barPlusDismissFlag) {
// turn off Bar+ notification
ptBarPlusElement.style.display = "none";
ptBarPlusElement.style.background = "#efefef";
document.documentElement.style.position = "relative";
document.documentElement.style.top = "0";
barPlusDismissFlag = false;
barPlusAdaptFlag = false;
} else if(barPlusAdaptFlag) {
adaptToZoome();
}
}
/////////// Dialog box notification \\\\\\\\\\
else if (ptViz === "ptDialog") {
// turn on Bar+ notification
ptDialogElement.style.display = "block";
ptDialogElement.style.background = "#bada55";
ptDialogElement.style.background = "#efefef";
if(dialogBoxDismissFlag) {
// turn off Bar+ notification
ptDialogElement.style.display = "none";
ptDialogElement.style.background = "#efefef";
dialogBoxDismissFlag = false;
dialogBoxAdaptFlag = false;
} else if(dialogBoxAdaptFlag) {
adaptToZoome();
}
}
}
} else {
//display slip/click ratio and click timing notification
//************** Get Store **************//
chrome.storage.sync.get(null, function(items) { // null implies all items
//scr
var scrRel = items.scrRel;
var scrViz = items.scrViz;
var posTop = items.posTop;
var posBtm = items.posBtm;
var scrThick = items.scrThick;
var scrBarColor = items.scrBarColor;
var total_clicks = items.t_num_clicks;
var total_slips = items.t_num_slips;
console.log("clicks" + total_clicks);
console.log("slips" + total_slips);
var scrRatio = (total_slips/total_clicks) * 100;
console.log("scr " + scrRatio);
//ct
var ctRel = items.ctRel;
var ctViz = items.ctViz;
var ctPosTop = items.ctPosTop;
var ctPosBtm = items.ctPosBtm;
var ctThick = items.ctThick;
var ctBarColor = items.ctBarColor;
var clickTiming = items.clickTiming;
//convert clickTiming into seconds
clickTiming = clickTiming/1000;
console.log("ct " + clickTiming);
//START: scr
if (items.scrFlag &&