forked from letterly/letterly.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyiddish.js
120 lines (119 loc) · 3.25 KB
/
yiddish.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
eventCode = {
"KeyQ": "ך",
"KeyW": "ש",
"KeyE": "ע",
"KeyR": "ר",
"KeyT": "ט",
"KeyY": "י",
"KeyU": "ו",
"KeyI": "יִ",
"KeyO": "אָ",
"KeyP": "פ",
"KeyA": "אַ",
"KeyS": "ס",
"KeyD": "ד",
"KeyF": "פֿ",
"KeyG": "ג",
"KeyH": "ה",
"KeyJ": "ײַ",
"KeyK": "ק",
"KeyL": "ל",
"Semicolon": "ף",
"KeyZ": "ז",
"KeyX": "כ",
"KeyC": "צ",
"KeyV": "ץ",
"KeyB": "ב",
"KeyN": "נ",
"KeyM": "מ",
"Comma": "ם",
"Period": "ן",
"Slash": "וּ",
"BracketLeft": "א",
"BracketRight": "ת",
"Backslash": "ח",
"Space": " ",
"Enter": "",
"Quote": "בֿ",
}
document.addEventListener("DOMContentLoaded", function(){
var textarea = [].slice.call(document.getElementsByTagName("textarea"))[0]
var key = [].slice.call(document.getElementsByClassName('key'))
key.forEach((element, index) => {
element.addEventListener('click', (event) => {
textarea.value += event.target.textContent.trim().charAt(0)
})
})
this.addEventListener('keydown', event => {
if(Object.keys(eventCode).includes(event.code)) event.preventDefault()
if(eventCode[event.code] !== undefined){
textarea.value += eventCode[event.code]
if(event.code != "Enter" && event.code != "Space") document.getElementById(event.code).style.backgroundColor = "#2aa198"
if(event.code == "Enter"){
textarea.value = ""
}
update(textarea.value)
}
})
this.addEventListener('keyup', event => {
if(Object.keys(eventCode).includes(event.code)) event.preventDefault()
if(eventCode[event.code] !== undefined && event.code != "Enter" && event.code != "Space") document.getElementById(event.code).style.backgroundColor = "#fdf6e3"
})
function update(sentence){
result.innerHTML = `<p>${translit(sentence)}</p>`
}
function translit(sentence){
tkey = {
"א": "",
"ײַ": "ay",
"וו": "v",
"וי": "oy",
"דזש": "dzh",
"זש": "zh",
"טש": "tsh",
"ייִ": "yi",
"יי": "ey",
"יִ": "i",
"ו": "u",
"אַ": "a",
"אָ": "o",
"בֿ": "v",
"ב": "b",
"ג": "g",
"ד": "d",
"ה": "h",
"ז": "z",
"ח": "ch",
"ט": "t",
"י": "i",
"כ": "ch",
"ך": "ch",
"ל": "l",
"מ": "m",
"ם": "m",
"נ": "n",
"ן": "n",
"ס": "s",
"ע": "e",
"פֿ": "f",
"ף": "f",
"פּ": "p",
"צ": "tz",
"ץ": "tz",
"ק": "k",
"ר": "r",
"ת": "t",
"ו": "u",
"ש": "sh",
"וּ": "u",
"ת": "t",
"ח": "ch",
}
for(f of Object.entries(tkey)){
regex = new RegExp(f[0].replace("X", ""), "g")
sentence = sentence.replace(regex, f[1])
}
console.log(sentence)
return sentence
}
})