diff --git a/index.html b/index.html
index 9c08958..92647cb 100644
--- a/index.html
+++ b/index.html
@@ -1,5 +1,6 @@
+
@@ -7,13 +8,16 @@
Translite
+
Translite
+ Transliteration
+
\ No newline at end of file
diff --git a/main.js b/main.js
index 30bfa74..bc3a10c 100644
--- a/main.js
+++ b/main.js
@@ -1,112 +1,42 @@
+let translitEnabled = true;
+
+function toggleTranslit() {
+ translitEnabled = document.getElementById("translitCheckbox").checked;
+}
+
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: "я"
+ if (!translitEnabled) return;
+
+ const 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 = {
- ЙЕ: "Э",
- Йе: "Э",
- йе: "э",
- ЙО: "Ё",
- Йо: "Ё",
- йо: "ё",
- ЫО: "Ё",
- Ыо: "Ё",
- ыо: "ё",
- ЙУ: "Ю",
- Йу: "Ю",
- йу: "ю",
- ЫУ: "Ю",
- Ыу: "Ю",
- ыу: "ю",
- ЙА: "Я",
- Йа: "Я",
- йа: "я",
- ЫА: "Я",
- Ыа: "Я",
- ыа: "я",
- ЦХ: "Ч",
- Цх: "Ч",
- цх: "ч",
- СХ: "Ш",
- Сх: "Ш",
- сх: "ш",
- ЗХ: "Ж",
- Зх: "Ж",
- зх: "ж",
- ШХ: "Щ",
- Шх: "Щ",
- шх: "щ",
- "ьь": "Ь",
- "ъъ": "Ъ"
+ const dic2 = {
+ ЙЕ: "Э", Йе: "Э", йе: "э",
+ ЙО: "Ё", Йо: "Ё", йо: "ё", ЫО: "Ё", Ыо: "Ё", ыо: "ё",
+ ЙУ: "Ю", Йу: "Ю", йу: "ю", ЫУ: "Ю", Ыу: "Ю", ыу: "ю",
+ ЙА: "Я", Йа: "Я", йа: "я", ЫА: "Я", Ыа: "Я", ыа: "я",
+ ЦХ: "Ч", Цх: "Ч", цх: "ч",
+ СХ: "Ш", Сх: "Ш", сх: "ш",
+ ЗХ: "Ж", Зх: "Ж", зх: "ж",
+ ШХ: "Щ", Шх: "Щ", шх: "щ",
+ "ьь": "Ь", "ъъ": "Ъ"
};
- var ctl = document.getElementById("transtxt");
- var str = ctl.value;
- var pos = ctl.selectionStart;
+ const ctl = document.getElementById("transtxt");
+ let str = ctl.value;
+ const pos = ctl.selectionStart;
- var tmp = str.slice(pos - 1, pos);
+ let tmp = str.slice(pos - 1, pos);
if (dic1.hasOwnProperty(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.selectionEnd = pos;
}
@@ -114,22 +44,18 @@ function translit() {
tmp = str.slice(pos - 2, pos);
if (dic2.hasOwnProperty(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.selectionEnd = pos - 1;
}
-
-};
+}
function copytxt() {
- var copyctl = document.getElementById("transtxt");
+ const copyctl = document.getElementById("transtxt");
copyctl.select();
- copyctl.setSelectionRange(0, copyctl.value.length);
- navigator.clipboard.writeText(copyctl.value)
-};
+ navigator.clipboard.writeText(copyctl.value);
+}
function cleartxt() {
- var clearctl = document.getElementById("transtxt");
- clearctl.select();
- clearctl.value = "";
-};
\ No newline at end of file
+ document.getElementById("transtxt").value = "";
+}