aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorache <ache@ache.one>2017-06-02 06:24:14 +0000
committerache <ache@ache.one>2017-06-02 06:24:14 +0000
commita3cc59032a7966acd389642f1d5625a612e875f3 (patch)
tree332998ba9b3fe4fecbe1678ed1b003865fab2f3b
parentAjout kanjis (diff)
Prise en comptes des valeurs multiples
-rw-r--r--synhestesis.js244
1 files changed, 127 insertions, 117 deletions
diff --git a/synhestesis.js b/synhestesis.js
index 66244a9..8fb30f6 100644
--- a/synhestesis.js
+++ b/synhestesis.js
@@ -1,11 +1,11 @@
function shuffle(a) {
- var j, x, i;
- for (i = a.length; i; i--) {
- j = Math.floor(Math.random() * i);
- x = a[i - 1];
- a[i - 1] = a[j];
- a[j] = x;
- }
+ var j, x, i;
+ for (i = a.length; i; i--) {
+ j = Math.floor(Math.random() * i);
+ x = a[i - 1];
+ a[i - 1] = a[j];
+ a[j] = x;
+ }
}
onTop = document.getElementById('onTop');
@@ -20,118 +20,128 @@ select = document.getElementById('select');
asPass = false
function selectChange(evt) {
- inputAnswer.style.float = "right";
- passButt.type = "button";
- passButt.style.float = "right";
- passButt.value = "Pass";
- resetButt.type = "button";
- resetButt.style.float = "right";
- resetButt.value = "Reset";
-
- var xmlHttp = new XMLHttpRequest();
- xmlHttp.onreadystatechange = function() {
- if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
- loadFile(xmlHttp.responseText);
- }
+ inputAnswer.style.float = "right";
+ passButt.type = "button";
+ passButt.style.float = "right";
+ passButt.value = "Pass";
+ resetButt.type = "button";
+ resetButt.style.float = "right";
+ resetButt.value = "Reset";
+
+ var xmlHttp = new XMLHttpRequest();
+ xmlHttp.onreadystatechange = function() {
+ if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
+ loadFile(xmlHttp.responseText);
}
- xmlHttp.open("GET", "http://ache.one/shared/synhestesis/" +select.options[select.selectedIndex].value, true);
- xmlHttp.send(null);
+ }
+ xmlHttp.open("GET", "http://ache.one/shared/synhestesis/" +select.options[select.selectedIndex].value, true);
+ xmlHttp.send(null);
}
function loadFile( str ) {
- console.log( str )
- var last = JSON.parse(str);
- var res = []
- var indexRes = 0;
- var cmpGood = 0;
- var cmpBad = 0;
- res = last;
- shuffle(res.answer);
- compteurSpan.innerText = "0/" + res.answer.length;
- ratioSpan.innerText = "∅";
- outputAnswer.innerText = res.answer[indexRes].key;
- onTop.appendChild(inputAnswer);
- onTop.appendChild(passButt);
- onTop.appendChild(resetButt);
- if( res.answer[indexRes].style )
- outputAnswer.style = outputStyleBase + res.answer[indexRes].style;
- function pass() {
- console.log(inputAnswer.value)
- asPass = true
- inputAnswer.value = "" + res.answer[indexRes].value
- console.log(inputAnswer.value)
- }
- function reset() {
- cmpGood = 0
- cmpBad = 0
- indexRes = 0
- res = last;
- shuffle(res.answer);
- compteurSpan.innerText = "0/" + res.answer.length;
- ratioSpan.innerText = "∅";
- outputAnswer.innerText = res.answer[indexRes].key;
- onTop.appendChild(inputAnswer);
- onTop.appendChild(passButt);
- }
- inputAnswer.onkeydown = function(event) {
- inputAnswer.style.borderColor = ""
- var ev = event || window.event;
- var key = ev.keyCode || ev.which || ev.charCode;
- if( key == 13 ) {
- if( ev.shiftKey ) {
- pass();
- } else {
- inputAnswer.change();
- }
- }
- }
- passButt.onclick = pass
- resetButt.onclick = reset
- inputAnswer.change = function() {
- if( inputAnswer.value == res.answer[indexRes].value ) {
- if( ! asPass ) {
- cmpGood+=1;
- console.log("Good");
- }else {
- console.log("Passed : " + res.answer[indexRes].value);
- asPass = false;
- }
- inputAnswer.style.borderColor = "#0F0"
-
- inputAnswer.value = "";
- if( indexRes+1 < res.answer.length ) {
- indexRes++;
- outputAnswer.innerText = res.answer[indexRes].key;
- } else {
- onTop.removeChild(inputAnswer);
- onTop.removeChild(passButt);
- if( cmpBad == 0 ) {
- outputAnswer.innerText = "Perfect !";
- }else if( cmpGood/cmpBad > 0.9 * (res.answer.length + cmpBad) ) {
- outputAnswer.innerText = "Almost perfect !";
- }else if( cmpGood/cmpBad > 0.75 * (res.answer.length + cmpBad) ) {
- outputAnswer.innerText = "Good !";
- }else if( cmpGood/cmpBad > 0.5 * (res.answer.length + cmpBad) ) {
- outputAnswer.innerText = "Average";
- }else if( cmpGood/cmpBad > 0.25 * (res.answer.length + cmpBad) ) {
- outputAnswer.innerText = "Can do better";
- }else {
- outputAnswer.innerText = "Bad";
- }
- }
+ console.log( str )
+ var last = JSON.parse(str);
+ var res = []
+ var indexRes = 0;
+ var cmpGood = 0;
+ var cmpBad = 0;
+ res = last;
+ shuffle(res.answer);
+ compteurSpan.innerText = "0/" + res.answer.length;
+ ratioSpan.innerText = "∅";
+ outputAnswer.innerText = res.answer[indexRes].key;
+ onTop.appendChild(inputAnswer);
+ onTop.appendChild(passButt);
+ onTop.appendChild(resetButt);
+ if( res.answer[indexRes].style )
+ outputAnswer.style = outputStyleBase + res.answer[indexRes].style;
+ function pass() {
+ console.log(inputAnswer.value)
+ asPass = true
+ inputAnswer.value = "" + res.answer[indexRes].value
+ console.log(inputAnswer.value)
+ }
+ function reset() {
+ cmpGood = 0
+ cmpBad = 0
+ indexRes = 0
+ res = last;
+ shuffle(res.answer);
+ compteurSpan.innerText = "0/" + res.answer.length;
+ ratioSpan.innerText = "∅";
+ outputAnswer.innerText = res.answer[indexRes].key;
+ onTop.appendChild(inputAnswer);
+ onTop.appendChild(passButt);
+ }
+ inputAnswer.onkeydown = function(event) {
+ inputAnswer.style.borderColor = ""
+ var ev = event || window.event;
+ var key = ev.keyCode || ev.which || ev.charCode;
+ if( key == 13 ) {
+ if( ev.shiftKey ) {
+ pass();
} else {
- console.log("Bad");
- inputAnswer.style.borderColor = "red"
- cmpBad+=1;
+ inputAnswer.change();
}
+ }
+ }
+ passButt.onclick = pass
+ resetButt.onclick = reset
+ inputAnswer.change = function() {
+ var valid = false;
+ if( res.answer[indexRes].value != undefined && res.answer[indexRes].value == inputAnswer.value )
+ valid = true;
+ else if( res.answer[indexRes].values != undefined ) {
+ console.log("Hello");
+ console.log( res.answer[indexRes].values )
+ if( res.answer[indexRes].values.indexOf(inputAnswer.value) != -1 )
+ valid = true;
+ }
+
+ if( valid ) {
+ if( ! asPass ) {
+ cmpGood+=1;
+ console.log("Good");
+ }else {
+ console.log("Passed : " + res.answer[indexRes].value);
+ asPass = false;
+ }
+ inputAnswer.style.borderColor = "#0F0"
- if( cmpBad > 0 )
- ratioSpan.innerText = "" + cmpGood/cmpBad;
- else
- ratioSpan.innerText = "∅";
-
-
- compteurSpan.innerText = indexRes + "/" + res.answer.length;
+ inputAnswer.value = "";
+ if( indexRes+1 < res.answer.length ) {
+ indexRes++;
+ outputAnswer.innerText = res.answer[indexRes].key;
+ } else {
+ onTop.removeChild(inputAnswer);
+ onTop.removeChild(passButt);
+ if( cmpBad == 0 ) {
+ outputAnswer.innerText = "Perfect !";
+ }else if( cmpGood/cmpBad > 0.9 * (res.answer.length + cmpBad) ) {
+ outputAnswer.innerText = "Almost perfect !";
+ }else if( cmpGood/cmpBad > 0.75 * (res.answer.length + cmpBad) ) {
+ outputAnswer.innerText = "Good !";
+ }else if( cmpGood/cmpBad > 0.5 * (res.answer.length + cmpBad) ) {
+ outputAnswer.innerText = "Average";
+ }else if( cmpGood/cmpBad > 0.25 * (res.answer.length + cmpBad) ) {
+ outputAnswer.innerText = "Can do better";
+ }else {
+ outputAnswer.innerText = "Bad";
+ }
+ }
+ } else {
+ console.log("Bad");
+ inputAnswer.style.borderColor = "red"
+ cmpBad+=1;
}
+
+ if( cmpBad > 0 )
+ ratioSpan.innerText = "" + cmpGood/cmpBad;
+ else
+ ratioSpan.innerText = "∅";
+
+
+ compteurSpan.innerText = indexRes + "/" + res.answer.length;
+ }
}
function handleFileSelect(evt) {
@@ -140,7 +150,7 @@ function handleFileSelect(evt) {
var file = files[0];
var reader = new FileReader();
-
+
inputAnswer.style.float = "right";
passButt.type = "button";
passButt.style.float = "right";
@@ -148,12 +158,12 @@ function handleFileSelect(evt) {
resetButt.type = "button";
resetButt.style.float = "right";
resetButt.value = "Reset";
-
-
-
+
+
+
reader.onload = function (evt) {
- loadFile( evt.target.result )
+ loadFile( evt.target.result )
}
reader.readAsText(file, "UTF-8");
}