Skip to content

Instantly share code, notes, and snippets.

@JanPokorny
Created October 11, 2016 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JanPokorny/9c567de821ef351eb0c8b02e07d9986f to your computer and use it in GitHub Desktop.
Save JanPokorny/9c567de821ef351eb0c8b02e07d9986f to your computer and use it in GitHub Desktop.
Transliterates azbuka to latin
// ==UserScript==
// @name RuTranslit
// @namespace RuTranslit
// @description Azbuka -> Latin
// @include *
// @version 1
// @grant none
// ==/UserScript==
function textNodesUnder(node) {
var all = [];
for (node=node.firstChild;node;node=node.nextSibling) {
if (node.nodeType==3) all.push(node);
else all = all.concat(textNodesUnder(node));
}
return all;
}
function udelejto(x) {
var new_s = x;
var replaces = {
"А": "A",
"Б": "B",
"В": "V",
"Г": "G",
"Д": "D",
"Е": "E",
"Ё": "Ju",
"Ж": "Ž",
"З": "Z",
"И": "I",
"Й": "J",
"К": "K",
"Л": "L",
"М": "M",
"Н": "N",
"О": "O",
"П": "P",
"Р": "R",
"С": "S",
"Т": "T",
"У": "U",
"Ф": "F",
"Х": "Ch",
"Ц": "C",
"Ч": "Č",
"Ш": "Š",
"Щ": "Šč",
"Ъ": "ʺ",
"Ы": "Y",
"Ь": "ʹ",
"Э": "E",
"Ю": "Ju",
"Я": "Ja"
};
for(var i in replaces)
{
new_s = new_s
.replace(new RegExp(i,"g"), replaces[i])
.replace(new RegExp(i.toLowerCase(),"g"), replaces[i].toLowerCase());
}
return new_s;
}
var nodes = textNodesUnder(document.body);
for(var i in nodes) {
var node = nodes[i];
node.textContent = udelejto(node.textContent);
}
document.title = udelejto(document.title);
var buttons = document.querySelectorAll("input");
for(var i in buttons)
{
if(buttons[i].value) buttons[i].value = udelejto(buttons[i].value);
if(buttons[i].placeholder) buttons[i].placeholder = udelejto(buttons[i].placeholder);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment