Browse Source

Add js code

master
Nyymix 2 months ago
parent
commit
bc6d00fe09
  1. 9
      index.html
  2. 15
      main.css
  3. 135
      main.js

9
index.html

@ -5,10 +5,15 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="main.css">
<title>Document</title>
<title>Translite</title>
</head>
<body>
<h1>Translite</h1>
<div class="wrapper">
<textarea id="transtxt" cols="30" rows="15" oninput="translit()"></textarea>
</div>
<button onclick="copytxt()">Copy text</button>
<button onclick="cleartxt()">Clear text</button>
<script src="main.js"></script>
</body>
</html>

15
main.css

@ -0,0 +1,15 @@
body {
font-size: medium;
background-color: #e5e5e5;
}
.wrapper {
padding: 20px;
margin: 5px 0;
background-color: #222222;
}
textarea {
font-size: 20px;
width: 100%;
}

135
main.js

@ -0,0 +1,135 @@
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 = "";
};
Loading…
Cancel
Save