js-translit/main.js
2022-04-27 22:58:34 +03:00

135 lines
No EOL
2.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

function translit() {
var dic1 = {
A: "А",
a: "а",
B: "Б",
b: "б",
V: "В",
v: "в",
G: "Г",
g: "г",
D: "Д",
d: "д",
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 = {
ЙЕ: "Э",
Йе: "Э",
йе: "э",
ЙО: "Ё",
Йо: "Ё",
йо: "ё",
ЫО: "Ё",
Ыо: "Ё",
ыо: "ё",
ЙУ: "Ю",
Йу: "Ю",
йу: "ю",
ЫУ: "Ю",
Ыу: "Ю",
ыу: "ю",
ЙА: "Я",
Йа: "Я",
йа: "я",
ЫА: "Я",
Ыа: "Я",
ыа: "я",
ЦХ: "Ч",
Цх: "Ч",
цх: "ч",
СХ: "Ш",
Сх: "Ш",
сх: "ш",
ЗХ: "Ж",
Зх: "Ж",
зх: "ж",
ШХ: "Щ",
Шх: "Щ",
шх: "щ",
"ьь": "Ь",
"ъъ": "Ъ"
};
var ctl = document.getElementById("transtxt");
var str = ctl.value;
var pos = ctl.selectionStart;
var tmp = str.slice(pos - 1, pos);
if (dic1.hasOwnProperty(tmp)) {
tmp = dic1[tmp];
str = str.replace(str.substring(pos - 1, pos), tmp);
ctl.value = str;
ctl.selectionEnd = pos;
}
tmp = str.slice(pos - 2, pos);
if (dic2.hasOwnProperty(tmp)) {
tmp = dic2[tmp];
str = str.replace(str.substring(pos - 2, pos), tmp);
ctl.value = str;
ctl.selectionEnd = pos - 1;
}
};
function copytxt() {
var copyctl = document.getElementById("transtxt");
copyctl.select();
copyctl.setSelectionRange(0, copyctl.value.length);
navigator.clipboard.writeText(copyctl.value)
};
function cleartxt() {
var clearctl = document.getElementById("transtxt");
clearctl.select();
clearctl.value = "";
};