Cyrillic Transliterator (PI)

Transliterates Cyrillic characters to Latin characters on any webpage.

  1. // ==UserScript==
  2. // @name Cyrillic Transliterator (PI)
  3. // @description Transliterates Cyrillic characters to Latin characters on any webpage.
  4. // @author w4t3r1ily
  5. // @version 1.6
  6. // @match *://*/*
  7. // @include *
  8. // @grant none
  9. // @icon https://opu.peklo.biz/p/23/05/13/1684010167-8264b.jpg
  10. // @namespace https://greasyfork.org/users/905173
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. var map = {
  15. 'А': 'A',
  16. 'а': 'a',
  17. 'Б': 'B',
  18. 'б': 'b',
  19. 'В': 'V',
  20. 'в': 'v',
  21. 'Г': 'G',
  22. 'г': 'ġ',
  23. 'Ґ': 'Ġ',
  24. 'ґ': 'g̀',
  25. 'Д': 'D',
  26. 'д': 'd',
  27. 'Ѓ': 'Ǵ',
  28. 'ѓ': 'ǵ',
  29. 'Ђ': 'Ď',
  30. 'ђ': 'ď',
  31. 'Е': 'E',
  32. 'е': 'e',
  33. 'Ё': 'Ë',
  34. 'ё': 'ë',
  35. 'Є': 'Je',
  36. 'є': 'je',
  37. 'Ж': 'Ž',
  38. 'ж': 'ž',
  39. 'З': 'Z',
  40. 'з': 'z',
  41. 'Ѕ': 'Dz',
  42. 'ѕ': 'dz',
  43. 'И': 'I',
  44. 'и': 'i',
  45. 'І': 'Ī',
  46. 'і': 'ī',
  47. 'Ї': 'Ji',
  48. 'ї': 'ji',
  49. 'Й': 'J',
  50. 'й': 'j',
  51. 'Ј': 'J',
  52. 'ј': 'j',
  53. 'К': 'K',
  54. 'к': 'k',
  55. 'Л': 'L',
  56. 'л': 'l',
  57. 'Љ': 'Ľ',
  58. 'љ': 'ľ',
  59. 'М': 'M',
  60. 'м': 'm',
  61. 'Н': 'N',
  62. 'н': 'n',
  63. 'Њ': 'Ń',
  64. 'њ': 'ń',
  65. 'О': 'O',
  66. 'о': 'o',
  67. 'П': 'P',
  68. 'п': 'p',
  69. 'Р': 'R',
  70. 'р': 'r',
  71. 'С': 'S',
  72. 'с': 's',
  73. 'Т': 'T',
  74. 'т': 't',
  75. 'Ќ': 'Ḱ',
  76. 'ќ': 'ḱ',
  77. 'Ћ': 'Ć',
  78. 'ћ': 'ć',
  79. 'У': 'U',
  80. 'у': 'u',
  81. 'Ў': 'W',
  82. 'ў': 'w',
  83. 'Ф': 'F',
  84. 'ф': 'f',
  85. 'Х': 'Ch',
  86. 'х': 'ch',
  87. 'Ц': 'C',
  88. 'ц': 'c',
  89. 'Ч': 'Č',
  90. 'ч': 'č',
  91. 'Џ': 'Ǵ',
  92. 'џ': 'ǵ',
  93. 'Ш': 'Š',
  94. 'ш': 'š',
  95. 'Щ': 'Šč',
  96. 'щ': 'šč',
  97. 'Ъ': '-',
  98. 'ъ': '-',
  99. 'Ы': 'Y',
  100. 'ы': 'y',
  101. 'Ь': 'ʹ',
  102. 'ь': 'ʹ',
  103. 'Ѣ': 'Ě',
  104. 'ѣ': 'ě',
  105. 'Э': 'È',
  106. 'э': 'è',
  107. 'Ю': 'Ju',
  108. 'ю': 'ju',
  109. 'Я': 'Ja',
  110. 'я': 'ja',
  111. "'": '-',
  112. 'Ѫ': 'Ǎ',
  113. 'ѫ': 'ǎ',
  114. 'Ѳ': 'ḟ',
  115. 'ѳ': 'ḟ',
  116. 'Ѵ': 'Ẏ',
  117. 'ѵ': 'ẏ',
  118. };
  119.  
  120. function replaceText(node) {
  121. var value = node.nodeValue;
  122. var newValue = '';
  123. for (var i = 0; i < value.length; i++) {
  124. var char = value.charAt(i);
  125. newValue += char in map ? map[char] : char;
  126. }
  127. node.nodeValue = newValue;
  128. }
  129.  
  130. function replaceCyrillic() {
  131. var walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT, null, false);
  132. var node;
  133. while (node = walker.nextNode()) {
  134. replaceText(node);
  135. }
  136. }
  137.  
  138. function createToggleButton() {
  139. var button = document.createElement('button');
  140. button.innerHTML = 'Transliterate Cyrillic (PI)';
  141. button.className = 'cyr-tr-button'; // Set the class name to "tr-cyr-button"
  142. button.style.position = 'fixed';
  143. button.style.bottom = '40px';
  144. button.style.right = '20px';
  145. button.onclick = toggleTransliteration;
  146. document.body.appendChild(button);
  147. }
  148.  
  149. function toggleTransliteration() {
  150. isTransliterationEnabled = !isTransliterationEnabled;
  151. if (isTransliterationEnabled) {
  152. replaceCyrillic();
  153. } else {
  154. location.reload();
  155. }
  156. }
  157.  
  158. var isTransliterationEnabled = false;
  159. var cyrillicRegex = /[\u0400-\u04FF]/;
  160.  
  161. if (cyrillicRegex.test(document.body.innerHTML)) {
  162. createToggleButton();
  163. }
  164. })();