Initial commit

This commit is contained in:
Taevas 2021-01-22 00:25:31 +01:00
commit b2e2089d21
7 changed files with 382 additions and 0 deletions

13
LICENSE Normal file
View file

@ -0,0 +1,13 @@
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.

3
README.md Normal file
View file

@ -0,0 +1,3 @@
# KanaLearning
Despite being functional, KanaLearning is still very much WIP. It'll get a proper README.md once certain things are done.

232
characters.json Normal file
View file

@ -0,0 +1,232 @@
{"items": [
{
"h": "あ",
"k": "ア",
"r": "a"
},
{
"h": "い",
"k": "イ",
"r": "i"
},
{
"h": "う",
"k": "ウ",
"r": "u"
},
{
"h": "え",
"k": "エ",
"r": "e"
},
{
"h": "お",
"k": "オ",
"r": "o"
},
{
"h": "か",
"k": "カ",
"r": "ka"
},
{
"h": "き",
"k": "キ",
"r": "ki"
},
{
"h": "く",
"k": "ク",
"r": "ku"
},
{
"h": "け",
"k": "ケ",
"r": "ke"
},
{
"h": "こ",
"k": "コ",
"r": "ko"
},
{
"h": "さ",
"k": "サ",
"r": "sa"
},
{
"h": "し",
"k": "シ",
"r": "shi"
},
{
"h": "す",
"k": "ス",
"r": "su"
},
{
"h": "せ",
"k": "セ",
"r": "se"
},
{
"h": "そ",
"k": "シ",
"r": "so"
},
{
"h": "た",
"k": "タ",
"r": "ta"
},
{
"h": "ち",
"k": "チ",
"r": "chi"
},
{
"h": "つ",
"k": "ツ",
"r": "tsu"
},
{
"h": "て",
"k": "テ",
"r": "te"
},
{
"h": "と",
"k": "ト",
"r": "to"
},
{
"h": "な",
"k": "ナ",
"r": "na"
},
{
"h": "に",
"k": "ニ",
"r": "ni"
},
{
"h": "ぬ",
"k": "ヌ",
"r": "nu"
},
{
"h": "ね",
"k": "ネ",
"r": "ne"
},
{
"h": "の",
"k": "",
"r": "no"
},
{
"h": "は",
"k": "ハ",
"r": "ha"
},
{
"h": "ひ",
"k": "ヒ",
"r": "hi"
},
{
"h": "ふ",
"k": "フ",
"r": "fu"
},
{
"h": "へ",
"k": "ヘ",
"r": "he"
},
{
"h": "ほ",
"k": "ホ",
"r": "ho"
},
{
"h": "ま",
"k": "マ",
"r": "ma"
},
{
"h": "み",
"k": "ミ",
"r": "mi"
},
{
"h": "む",
"k": "ム",
"r": "mu"
},
{
"h": "め",
"k": "メ",
"r": "me"
},
{
"h": "も",
"k": "モ",
"r": "mo"
},
{
"h": "や",
"k": "ヤ",
"r": "ya"
},
{
"h": "ゆ",
"k": "ユ",
"r": "yu"
},
{
"h": "よ",
"k": "ヨ",
"r": "yo"
},
{
"h": "ら",
"k": "ラ",
"r": "ra"
},
{
"h": "り",
"k": "リ",
"r": "ri"
},
{
"h": "る",
"k": "ル",
"r": "ru"
},
{
"h": "れ",
"k": "レ",
"r": "re"
},
{
"h": "ろ",
"k": "ロ",
"r": "ro"
},
{
"h": "わ",
"k": "ワ",
"r": "wa"
},
{
"h": "を",
"k": "ヲ",
"r": "wo"
},
{
"h": "ん",
"k": "ン",
"r": "n"
}
]}

3
index.css Normal file
View file

@ -0,0 +1,3 @@
body {
text-align: center;
}

30
index.html Normal file
View file

@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<head>
<title>KanaLearning</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="./index.css">
<script type="text/javascript" src="./jquery-3.5.1.min.js"></script>
<script type="text/javascript" src="./index.js"></script>
</head>
<body onload="changeQuestion()">
<div id="question">
<p>If you see this, please enable Javascript in order for the website to work properly!</p>
<input type="text" id="answer_field" autofocus="autofocus" onfocus="this.select()">
<button onclick="checkAnswer()" id="answer_btn">Answer</button>
<button onclick="changeQuestion()" id="next_btn">Next</button>
</div>
<div id="correct_answer" style="visibility: hidden;">
<p>Answer was</p>
</div>
<div id="score">
<p style="color: red">0</p>
<p style="color: green">0</p>
</div>
<form id="allowed">
<input type="checkbox" id="h" checked="true"> <label for="h">Allow questions involving hiraganas?</label>
<input type="checkbox" id="k" checked="true"> <label for="k">Allow questions involving katakanas?</label>
<input type="checkbox" id="r" checked="true"> <label for="r">Allow questions involving romaji?</label>
</form>
</body>
</html>

99
index.js Normal file
View file

@ -0,0 +1,99 @@
$(function() {
document.querySelector("#answer_field").addEventListener("keyup", event => {
if (event.key !== "Enter") {return}
document.getElementById("correct_answer").style.visibility == "visible" ? document.querySelector("#next_btn").click() : document.querySelector("#answer_btn").click()
event.preventDefault()
})
})
function changeQuestion() {
document.getElementById("answer_field").value = ""
document.getElementById("answer_field").focus()
let p = document.getElementById("question").getElementsByTagName('p')[0]
let a = document.getElementById("correct_answer")
let questionShape = shapeQuestion([document.getElementById('h').checked, document.getElementById('k').checked, document.getElementById('r').checked])
a.style.visibility = "hidden"
$.getJSON("characters.json", function(data) {
const characters = data.items[Math.floor(Math.random() * data.items.length)]
var part_one
var part_two
var answer
switch (questionShape[0]) {
case "h":
part_one = "hiragana"
answer = characters.h
break
case "k":
part_one = "katakana"
answer = characters.k
break
case "r":
part_one = "romaji"
answer = characters.r
break
default:
part_one = "???"
}
switch (questionShape[1]) {
case "h":
part_two = characters.h
break
case "k":
part_two = characters.k
break
case "r":
part_two = characters.r
break
default:
part_two = "???"
}
p.innerHTML = `What is the ${part_one} equivalent of ${part_two}?`
a.getElementsByTagName('p')[0].innerHTML = `The answer was ${answer}`
})
}
function shapeQuestion(allow) {
let possibilities = ['h', 'k', 'r']
var element_one
var element_two
while (element_one == undefined) {
let x = Math.floor(Math.random() * possibilities.length)
if (allow[x]) {
let temp = possibilities[x]
allow.splice(possibilities.indexOf(temp), 1)
possibilities.splice(possibilities.indexOf(temp), 1)
element_one = temp
}
}
while (element_two == undefined) {
let x = Math.floor(Math.random() * possibilities.length)
if (allow[x] && possibilities[x] != element_one) {element_two = possibilities[x]}
}
return [element_one, element_two]
}
function checkAnswer() {
let answer_field = document.getElementById("answer_field")
let correct_answer_p = document.getElementById("correct_answer").getElementsByTagName('p')[0]
let positive = document.getElementById("score").getElementsByTagName('p')[1]
let negative = document.getElementById("score").getElementsByTagName('p')[0]
if (answer_field.value == correct_answer_p.innerHTML.slice(correct_answer_p.innerHTML.lastIndexOf(" ") + 1)) {
positive.innerHTML = Number(positive.innerHTML) + 1
} else {
negative.innerHTML = Number(negative.innerHTML) + 1
}
correct_answer.style.visibility = "visible"
}

2
jquery-3.5.1.min.js vendored Normal file

File diff suppressed because one or more lines are too long