-
Notifications
You must be signed in to change notification settings - Fork 2
/
ishihara.js
140 lines (111 loc) · 4.08 KB
/
ishihara.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
function calcScore(prm)
{
var label = $("#ishId")[0].src;
var lbl = label[label.length-7];
var vl = $("#ishNum").val();
if(lbl==vl)
{
if(prm==1)
{
chrome.storage.sync.get(["score1"], function(result) {
var s = result.score1+1;
chrome.storage.sync.set({score1:s}, function() {});
})
}
else
{
chrome.storage.sync.get(["score2"], function(result) {
var s = result.score2+1;
chrome.storage.sync.set({score2:s}, function() {});
})
}
}
}
function setVal(params)
{
var max = 9;
var min=0;
var r = Math.random() * (max - min) + min;
var b = Math.random() * (max - min) + min;
var srcName = "data/"+params+"/"+Math.ceil(r)+"_"+Math.ceil(b)+".png";
$("#ishId")[0].src = srcName;
}
$(document).ready(function(){
$("#test1").click(function()
{
setVal("red-green");
chrome.storage.sync.set({ishNextVal:1}, function() {});
chrome.storage.sync.set({score1:0}, function() {});
chrome.storage.sync.set({score2:0}, function() {});
$("#ishNum").focus();
});
$("#ishNext").click(function(){
chrome.storage.sync.get(["ishNextVal"], function(result) {
if(result.ishNextVal<10)
{
calcScore(1);
setVal("red-green");
q = result.ishNextVal+1;
chrome.storage.sync.set({ishNextVal:q}, function() {});
$("#ishNum").focus();
$("#ishNum").val(null);
}
else if(result.ishNextVal>=10 && result.ishNextVal<20)
{
calcScore(2);
setVal("blue-yellow");
q = result.ishNextVal+1;
chrome.storage.sync.set({ishNextVal:q}, function() {});
$("#ishNum").focus();
$("#ishNum").val(null);
}
else
{
calcScore(2);
chrome.storage.sync.get(["score1","score2"], function(result) {
var displayMsg;
if(result.score1<5 && result.score2<5)
{
displayMsg="Sorry!!...You seem to have complete color blindness";
}
else if(result.score1<result.score2)
{
var prb = result.score1;
if(prb>=8)
{
displayMsg = "Your eyes are perfect. No worries!!";
}
else if(prb<8 && prb>=5)
{
displayMsg = "You have a mild red-green color blindness";
}
else
{
displayMsg = "Sorry!!..You have a severe red-green color blindness";
}
}
else
{
var prb = result.score2;
if(prb>=8)
{
displayMsg = " No worries!!...Your eyes are perfect.";
}
else if(prb<8 && prb>=5)
{
displayMsg = "You have a mild blue-yellow color blindness";
}
else
{
displayMsg = "Sorry!!..You have a severe blue-yellow color blindness";
}
}
$("#ishihara").css("display","none");
$("#bldRes").html(displayMsg);
$("#bldRes1").css({"display":"flex","flex-direction":"column"});
chrome.storage.sync.set({page:7}, function() {});
})
}
})
});
});