Add Transliteration checkbox
This commit is contained in:
parent
e4b564773d
commit
706f105456
2 changed files with 43 additions and 113 deletions
|
@ -1,5 +1,6 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
@ -7,13 +8,16 @@
|
||||||
<link rel="stylesheet" href="main.css">
|
<link rel="stylesheet" href="main.css">
|
||||||
<title>Translite</title>
|
<title>Translite</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<h1>Translite</h1>
|
<h1>Translite</h1>
|
||||||
<div class="wrapper">
|
<div class="wrapper">
|
||||||
<textarea id="transtxt" cols="30" rows="15" oninput="translit()"></textarea>
|
<textarea id="transtxt" cols="30" rows="15" oninput="translit()"></textarea>
|
||||||
</div>
|
</div>
|
||||||
|
<input type="checkbox" id="translitCheckbox" onchange="toggleTranslit()" checked> Transliteration
|
||||||
<button onclick="copytxt()">Copy text</button>
|
<button onclick="copytxt()">Copy text</button>
|
||||||
<button onclick="cleartxt()">Clear text</button>
|
<button onclick="cleartxt()">Clear text</button>
|
||||||
<script src="main.js" charset="utf-8"></script>
|
<script src="main.js" charset="utf-8"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
152
main.js
152
main.js
|
@ -1,112 +1,42 @@
|
||||||
|
let translitEnabled = true;
|
||||||
|
|
||||||
|
function toggleTranslit() {
|
||||||
|
translitEnabled = document.getElementById("translitCheckbox").checked;
|
||||||
|
}
|
||||||
|
|
||||||
function translit() {
|
function translit() {
|
||||||
var dic1 = {
|
if (!translitEnabled) return;
|
||||||
A: "А",
|
|
||||||
a: "а",
|
const dic1 = {
|
||||||
B: "Б",
|
A: "А", a: "а", B: "Б", b: "б", V: "В", v: "в", G: "Г", g: "г",
|
||||||
b: "б",
|
D: "Д", d: "д", E: "Е", e: "е", Z: "З", z: "з", I: "И", i: "и",
|
||||||
V: "В",
|
J: "Й", j: "й", K: "К", k: "к", L: "Л", l: "л", M: "М", m: "м",
|
||||||
v: "в",
|
N: "Н", n: "н", O: "О", o: "о", P: "П", p: "п", R: "Р", r: "р",
|
||||||
G: "Г",
|
S: "С", s: "с", T: "Т", t: "т", U: "У", u: "у", F: "Ф", f: "ф",
|
||||||
g: "г",
|
X: "Х", x: "х", H: "Х", h: "х", C: "Ц", c: "ц", W: "В", w: "в",
|
||||||
D: "Д",
|
"\u0022": "ъ", Y: "Ы", y: "ы", "\u0027": "ь", Ä: "Э", ä: "э",
|
||||||
d: "д",
|
Ö: "Ё", ö: "ё", Ü: "Ю", ü: "ю", Q: "Я", q: "я"
|
||||||
E: "Е",
|
|
||||||
e: "е",
|
|
||||||
Z: "З",
|
|
||||||
z: "з",
|
|
||||||
I: "И",
|
|
||||||
i: "и",
|
|
||||||
J: "Й",
|
|
||||||
j: "й",
|
|
||||||
K: "К",
|
|
||||||
k: "к",
|
|
||||||
L: "Л",
|
|
||||||
l: "л",
|
|
||||||
M: "М",
|
|
||||||
m: "м",
|
|
||||||
N: "Н",
|
|
||||||
n: "н",
|
|
||||||
O: "О",
|
|
||||||
o: "о",
|
|
||||||
P: "П",
|
|
||||||
p: "п",
|
|
||||||
R: "Р",
|
|
||||||
r: "р",
|
|
||||||
S: "С",
|
|
||||||
s: "с",
|
|
||||||
T: "Т",
|
|
||||||
t: "т",
|
|
||||||
U: "У",
|
|
||||||
u: "у",
|
|
||||||
F: "Ф",
|
|
||||||
f: "ф",
|
|
||||||
X: "Х",
|
|
||||||
x: "х",
|
|
||||||
H: "Х",
|
|
||||||
h: "х",
|
|
||||||
C: "Ц",
|
|
||||||
c: "ц",
|
|
||||||
W: "В",
|
|
||||||
w: "в",
|
|
||||||
"\u0022": "ъ",
|
|
||||||
Y: "Ы",
|
|
||||||
y: "ы",
|
|
||||||
"\u0027": "ь",
|
|
||||||
Ä: "Э",
|
|
||||||
ä: "э",
|
|
||||||
Ö: "Ё",
|
|
||||||
ö: "ё",
|
|
||||||
Ü: "Ю",
|
|
||||||
ü: "ю",
|
|
||||||
Q: "Я",
|
|
||||||
q: "я"
|
|
||||||
};
|
};
|
||||||
var dic2 = {
|
const dic2 = {
|
||||||
ЙЕ: "Э",
|
ЙЕ: "Э", Йе: "Э", йе: "э",
|
||||||
Йе: "Э",
|
ЙО: "Ё", Йо: "Ё", йо: "ё", ЫО: "Ё", Ыо: "Ё", ыо: "ё",
|
||||||
йе: "э",
|
ЙУ: "Ю", Йу: "Ю", йу: "ю", ЫУ: "Ю", Ыу: "Ю", ыу: "ю",
|
||||||
ЙО: "Ё",
|
ЙА: "Я", Йа: "Я", йа: "я", ЫА: "Я", Ыа: "Я", ыа: "я",
|
||||||
Йо: "Ё",
|
ЦХ: "Ч", Цх: "Ч", цх: "ч",
|
||||||
йо: "ё",
|
СХ: "Ш", Сх: "Ш", сх: "ш",
|
||||||
ЫО: "Ё",
|
ЗХ: "Ж", Зх: "Ж", зх: "ж",
|
||||||
Ыо: "Ё",
|
ШХ: "Щ", Шх: "Щ", шх: "щ",
|
||||||
ыо: "ё",
|
"ьь": "Ь", "ъъ": "Ъ"
|
||||||
ЙУ: "Ю",
|
|
||||||
Йу: "Ю",
|
|
||||||
йу: "ю",
|
|
||||||
ЫУ: "Ю",
|
|
||||||
Ыу: "Ю",
|
|
||||||
ыу: "ю",
|
|
||||||
ЙА: "Я",
|
|
||||||
Йа: "Я",
|
|
||||||
йа: "я",
|
|
||||||
ЫА: "Я",
|
|
||||||
Ыа: "Я",
|
|
||||||
ыа: "я",
|
|
||||||
ЦХ: "Ч",
|
|
||||||
Цх: "Ч",
|
|
||||||
цх: "ч",
|
|
||||||
СХ: "Ш",
|
|
||||||
Сх: "Ш",
|
|
||||||
сх: "ш",
|
|
||||||
ЗХ: "Ж",
|
|
||||||
Зх: "Ж",
|
|
||||||
зх: "ж",
|
|
||||||
ШХ: "Щ",
|
|
||||||
Шх: "Щ",
|
|
||||||
шх: "щ",
|
|
||||||
"ьь": "Ь",
|
|
||||||
"ъъ": "Ъ"
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var ctl = document.getElementById("transtxt");
|
const ctl = document.getElementById("transtxt");
|
||||||
var str = ctl.value;
|
let str = ctl.value;
|
||||||
var pos = ctl.selectionStart;
|
const pos = ctl.selectionStart;
|
||||||
|
|
||||||
var tmp = str.slice(pos - 1, pos);
|
let tmp = str.slice(pos - 1, pos);
|
||||||
if (dic1.hasOwnProperty(tmp)) {
|
if (dic1.hasOwnProperty(tmp)) {
|
||||||
tmp = dic1[tmp];
|
tmp = dic1[tmp];
|
||||||
str = str.replace(str.substring(pos - 1, pos), tmp);
|
str = str.substring(0, pos - 1) + tmp + str.substring(pos);
|
||||||
ctl.value = str;
|
ctl.value = str;
|
||||||
ctl.selectionEnd = pos;
|
ctl.selectionEnd = pos;
|
||||||
}
|
}
|
||||||
|
@ -114,22 +44,18 @@ function translit() {
|
||||||
tmp = str.slice(pos - 2, pos);
|
tmp = str.slice(pos - 2, pos);
|
||||||
if (dic2.hasOwnProperty(tmp)) {
|
if (dic2.hasOwnProperty(tmp)) {
|
||||||
tmp = dic2[tmp];
|
tmp = dic2[tmp];
|
||||||
str = str.replace(str.substring(pos - 2, pos), tmp);
|
str = str.substring(0, pos - 2) + tmp + str.substring(pos);
|
||||||
ctl.value = str;
|
ctl.value = str;
|
||||||
ctl.selectionEnd = pos - 1;
|
ctl.selectionEnd = pos - 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
|
||||||
|
|
||||||
function copytxt() {
|
function copytxt() {
|
||||||
var copyctl = document.getElementById("transtxt");
|
const copyctl = document.getElementById("transtxt");
|
||||||
copyctl.select();
|
copyctl.select();
|
||||||
copyctl.setSelectionRange(0, copyctl.value.length);
|
navigator.clipboard.writeText(copyctl.value);
|
||||||
navigator.clipboard.writeText(copyctl.value)
|
}
|
||||||
};
|
|
||||||
|
|
||||||
function cleartxt() {
|
function cleartxt() {
|
||||||
var clearctl = document.getElementById("transtxt");
|
document.getElementById("transtxt").value = "";
|
||||||
clearctl.select();
|
}
|
||||||
clearctl.value = "";
|
|
||||||
};
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue