Skip to content

Instantly share code, notes, and snippets.

@dchekmarev
Last active October 20, 2017 05:56
Show Gist options
  • Save dchekmarev/65a345b7e36890f23d76548d9867a5a9 to your computer and use it in GitHub Desktop.
Save dchekmarev/65a345b7e36890f23d76548d9867a5a9 to your computer and use it in GitHub Desktop.
thai hours trainer for mobile, available as short url https://goo.gl/AEpgiB
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<script type="text/javascript"><!--
// data source: https://en.wikipedia.org/wiki/Six-hour_clock
var data = [
{ // midnight
'thai': ['เที่ยงคืน', 'หกทุ่ม', 'สองยาม'],
'rtgs': ['thiang khuen', 'hok thum', 'song yam'],
},
{
'thai': ['ตีหนึ่ง'],
'rtgs': ['tii nueng'],
},
{
'thai': ['ตีสอง'],
'rtgs': ['tii song'],
},
{
'thai': ['ตีสาม'],
'rtgs': ['tii sam'],
},
{
'thai': ['ตีสี่'],
'rtgs': ['tii sii'],
},
{
'thai': ['ตีห้า'],
'rtgs': ['tii haa'],
},
{ // 6am
'thai': ['หกโมงเช้า', 'ตีหก', 'ย่ำรุ่ง'],
'rtgs': ['hok moong chaw', 'tii hok', 'yam rung'],
},
{
'thai': ['เจ็ดโมง (เช้า)', 'โมงเช้า'],
'rtgs': ['chet moong (chaw)', '(nueng) moong (chaw)'],
},
{
'thai': ['แปดโมง (เช้า)', 'สองโมงเช้า'],
'rtgs': ['paet moong (chaw)', 'song moong (chaw)'],
},
{
'thai': ['เก้าโมง (เช้า)', 'สามโมงเช้า'],
'rtgs': ['kao moong (chaw)', 'sam moong (chaw)'],
},
{
'thai': ['สิบโมง (เช้า)', 'สีโมงเช้า'],
'rtgs': ['sip moong (chaw)', 'sii moong (chaw)'],
},
{
'thai': ['สิบเอ็ดโมง (เช้า)', 'ห้าโมงเช้า'],
'rtgs': ['sip et moong (chaw)', 'haa moong (chaw)'],
},
{ // midday
'thai': ['เที่ยงวัน'],
'rtgs': ['thiang (wan)'],
},
{ // 1pm or 13 o'clock
'thai': ['บ่ายโมง'],
'rtgs': ['bai (nueng) moong'],
},
{
'thai': ['บ่ายสองโมง'],
'rtgs': ['bai song moong'],
},
{
'thai': ['บ่ายสามโมง'],
'rtgs': ['bai sam moong'],
},
{
'thai': ['บ่ายสี่โมง'],
'rtgs': ['(bai) sii moong (yen)'],
},
{
'thai': ['บ่ายห้าโมง'],
'rtgs': ['(bai) haa moong (yen)'],
},
{ // 6pm or 18 o'clock
'thai': ['หกโมงเย็น', 'ย่ำค่ำ'],
'rtgs': ['hok moong (yen)', 'yam kham'],
},
{
'thai': ['หนึ่งทุ่ม'],
'rtgs': ['nueng thum'],
},
{
'thai': ['สองทุ่ม'],
'rtgs': ['song thum'],
},
{
'thai': ['สามทุ่ม'],
'rtgs': ['sam thum'],
},
{
'thai': ['สี่ทุ่ม'],
'rtgs': ['sii thum'],
},
{
'thai': ['ห้าทุ่ม'],
'rtgs': ['haa thum'],
},
]
var state = 'a'
var hour = 0
var dir = 0
var question = ''
var answer = ''
function next() {
console.log(state + ', dir=' + dir)
if (state == 'a') {
state = 'q'
hour = Math.floor(Math.random() * data.length)
dir = Math.round(Math.random())
q = data[hour]
question_big = q['thai'].join(', ')
question_small = q['rtgs'].join(', ')
answer = hour + " o'clock"
answer_small = hour % 12 > 0 ? hour % 12 : 12
answer_small += hour > 12 ? 'pm' : 'am'
document.getElementById('question_big').innerHTML = dir ? question_big : answer
document.getElementById('question_small').innerHTML = dir ? question_small : answer_small
document.getElementById('answer_big').innerHTML = '&nbsp;'
document.getElementById('answer_small').innerHTML = '&nbsp;'
} else {
state = 'a'
document.getElementById('answer_big').innerHTML = !dir ? question_big : answer
document.getElementById('answer_small').innerHTML = !dir ? question_small : answer_small
}
}
//--></script>
<style type="text/css"><!--
#question_big, #answer_big {
font-size:500%;
margin-top: 10%;
}
#question_small, #answer_small {
font-size:300%;
}
#button {
font-size:500%;
margin-top: 10%;
}
//--></style></head>
<body onload="next()" align="center">
<div id="question_big"></div>
<div id="question_small"></div>
<br/>
<div id="answer_big"></div>
<div id="answer_small"></div>
<input id="button" type="button" value="next / show" onclick="next()"/>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment