Created
October 11, 2016 13:24
-
-
Save JanPokorny/9c567de821ef351eb0c8b02e07d9986f to your computer and use it in GitHub Desktop.
Transliterates azbuka to latin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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