Skip to content

Instantly share code, notes, and snippets.

@Stmol
Created September 22, 2013 13:48
Show Gist options
  • Save Stmol/6660053 to your computer and use it in GitHub Desktop.
Save Stmol/6660053 to your computer and use it in GitHub Desktop.
Swap letters on Ru-En keyboard
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<input type="text" id="issue" value="">
<input type="button" id="convert" value="Convert">
<div id="result"></div>
<input style="display: none;" type="button" id="copy" value="Copy">
<script type="text/javascript">
/**
* @author: Stmol 2013
* @url: stmol.me
*/
(function(doc) {
var en = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'A', 'B', 'C', 'D', 'D', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'`', '[', ']', ';', '\'', ',', '.', '/', '~', '{', '}', ':', '"', '<', '>', '?' ]
, ru = ['ф', 'и', 'с', 'в', 'у', 'а', 'п', 'р', 'ш', 'о', 'л', 'д', 'ь', 'т', 'щ', 'з', 'й', 'к', 'ы', 'е', 'г', 'м', 'ц', 'ч', 'н', 'я',
'Ф', 'И', 'С', 'В', 'У', 'А', 'П', 'Р', 'Ш', 'О', 'Л', 'Д', 'Ь', 'Т', 'Щ', 'З', 'Й', 'К', 'Ы', 'Е', 'Г', 'М', 'Ц', 'Ч', 'Н', 'Я',
'ё', 'х', 'ъ', 'ж', 'э', 'б', 'ю', '.', 'Ё', 'Х', 'Ъ', 'Ж', 'Э', 'Б', 'Ю', '.' ];
doc.getElementById('convert').onclick = function () {
var textInput = doc.getElementById('issue').value
, resultDiv = doc.getElementById('result')
, resultStr = '';
for (var i = 0, l = textInput.length; i < l; i++) {
if (en.indexOf(textInput[i]) !== -1) {
resultStr += ru[en.indexOf(textInput[i])];
continue;
}
if (ru.indexOf(textInput[i]) !== -1) {
resultStr += en[ru.indexOf(textInput[i])];
continue;
}
resultStr += textInput[i];
}
resultDiv.innerHTML = resultStr;
}
})(document);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment