-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogic.js
70 lines (66 loc) · 1.42 KB
/
logic.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
var json = {
"sites": {
"translate.google.ru": "source",
"translate.google.com": "source",
"translate.google.cz": "source",
"slovnik.seznam.cz": "q",
"prirucka.ujc.cas.cz": "slovo"
},
"letters": {
"charka": {
"a": "á",
"A": "Á",
"o": "ó",
"O": "Ó",
"e": "é",
"E": "É",
"u": "ú",
"U": "Ú",
"y": "ý",
"Y": "Ý",
"i": "í",
"I": "Í"
},
"hachek": {
"e": "ě",
"E": "Ě",
"c": "č",
"C": "Č",
"s": "š",
"S": "Š",
"r": "ř",
"R": "Ř",
"z": "ž",
"Z": "Ž",
"u": "ů",
"U": "Ů",
"n": "ň",
"N": "Ň",
"d": "ď",
"D": "Ď",
"t": "ť",
"T": "Ť"
}
}
}
if (Object.keys(json.sites).includes(document.location.host)) {
console.log("Enable cz-chrome-extension for: " + document.location.host);
var elem = document.getElementById(json.sites[document.location.host])
elem.oninput = () => {
let lastSymbolIndex = elem.value.search(["\'|\""])
if (lastSymbolIndex > 0) {
if (elem.value[lastSymbolIndex] == "\'") {
repl(elem, json.letters.charka, lastSymbolIndex)
}
else {
repl(elem, json.letters.hachek, lastSymbolIndex)
}
}
}
}
function repl(element, dict, index) {
let itemForReplace = element.value[index - 1];
if (Object.keys(dict).includes(itemForReplace)) {
element.value = element.value.substring(0, index - 1) + dict[itemForReplace] + element.value.substring(index + 1, element.value.length)
}
}