Cyrillic Transliterator (Ukrainian)

Transliterates Ukranian cyrillic characters to latin characters on any webpage (Czech version)

目前為 2023-08-09 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Cyrillic Transliterator (Ukrainian)
// @description  Transliterates Ukranian cyrillic characters to latin characters on any webpage (Czech version)
// @version      2.1
// @match        *://*/*
// @include      *
// @grant        none
// @author       w4t3r1ily
// @icon         https://opu.peklo.biz/p/23/05/13/1684010167-8264b.jpg
// @namespace https://greasyfork.org/users/905173
// ==/UserScript==

   (function() {

       //Custom rules
       var customMap = {
        '’Є': 'Je',
        '’є': 'je',
        '’Ю': 'Ju',
        '’ю': 'ju',
        '’Я': 'Ja',
        '’я': 'ja',

        "'Є": 'Je',
        "'є": "je",
        "'Ю": "Ju",
        "'ю": "ju",
        "'Я": "Ja",
        "'я": "ja",

     };
        //Normal translit
        var map = {
         'A': 'A',
         'a': 'a',
         'Б': 'B',
         'б': 'b',
         'В': 'V',
         'в': 'v',
         'Г': 'H',
         'г': 'h',
         'Ґ': 'G',
         'ґ': 'g',
         'Д': 'D',
         'д': 'd',
         'Е': 'E',
         'е': 'e',
         'Є': 'Ê',
         'є': 'ê',
         'Ж': 'Ž',
         'ж': 'ž',
         'З': 'Z',
         'з': 'z',
         'И': 'Y',
         'и': 'y',
         'І': 'I',
         'і': 'i',
         "Ї": "Ji",
         "ї": "ji",
         'Й': 'J',
         'й': 'j',
         'К': 'K',
         'к': 'k',
         'Л': 'L',
         'л': 'l',
         'М': 'M',
         'м': 'm',
         'Н': 'N',
         'н': 'n',
         'О': 'O',
         'о': 'o',
         'П': 'P',
         'п': 'p',
         'Р': 'R',
         'р': 'r',
         'С': 'S',
         'с': 's',
         'Т': 'T',
         'т': 't',
         'У': 'U',
         'у': 'u',
         'Ф': 'F',
         'ф': 'f',
         'Х': 'Ch',
         'х': 'ch',
         'Ц': 'C',
         'ц': 'c',
         'Ч': 'Č',
         'ч': 'č',
         'Ш': 'Š',
         'ш': 'š',
         'Щ': 'Šč',
         'щ': 'šč',
         'Ю': 'Û',
         'ю': 'û',
         'Я': 'Â',
         'я': 'â',
         'Ь': 'ʼ',
         'ь': 'ʼ',
         '’': 'ʺ',
         "'": "ʺ",

       //Archaic symbols
        'Ы':'Y',
        'ы':'y',
        'Ѣ':'Ě',
        'ѣ':'ě',
        'Ѳ':'F̀',
        'ѳ':'f̀',
        'Ѵ':'Ỳ',
        'ѵ':'ỳ',
    };



 // Merge the customMap and map objects
    map = Object.assign({}, customMap, map);

        function replaceText(node) {
    var value = node.nodeValue;
    var newValue = '';
    var i = 0;

    while (i < value.length) {
        var char = value.charAt(i);
        var nextChar = value.charAt(i + 1);
        var combined = char + nextChar;

        if (combined in map) {
            newValue += map[combined];
            i += 2;
        } else if (char in map) {
            newValue += map[char];
            i++;
        } else {
            newValue += char;
            i++;
        }
    }

    node.nodeValue = newValue;
}

        function replaceCyrillic() {
            var walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT, null, false);
            var node;
            while (node = walker.nextNode()) {
                replaceText(node);
            }
        }

        function createToggleButton() {
            var button = document.createElement('button');
            button.innerHTML = 'Transliterate (ukr)';
               button.className = 'cyr-tr-button'; // Set the class name to "tr-cyr-button"
            button.style.position = 'fixed';
            button.style.bottom = '40px';
            button.style.right = '20px';
            button.onclick = toggleTransliteration;
            document.body.appendChild(button);
        }

        function toggleTransliteration() {
            isTransliterationEnabled = !isTransliterationEnabled;
            if (isTransliterationEnabled) {
                replaceCyrillic();
            } else {
                location.reload();
            }
        }

        var isTransliterationEnabled = false;
        var cyrillicRegex = /[\u0400-\u04FF]/;

        if (cyrillicRegex.test(document.body.innerHTML)) {
            createToggleButton();
        }
    })();