Антилах 2.0

Антилах

当前为 2019-12-19 提交的版本,查看 最新版本

// ==UserScript==
// @name          Антилах 2.0
// @description	  Антилах
// @author        DygDyg
// @homepage      http://dygdyg.ddns.net
// @version       0.0.1
// @include       *
// @require       https://code.jquery.com/jquery-3.3.1.min.js
// @icon          https://cdn.discordapp.com/attachments/497134253788758026/657240742196019200/ico16.png
// @run-at        document-start
// @grant         GM_setValue
// @grant         GM_getValue
// @grant         GM_addStyle
// @grant 		  GM_info
// @grant         GM_unregisterMenuCommand
// @grant         GM_registerMenuCommand
// @grant         GM_openInTab
// @grant         GM_notification
// @run-at        context-menu
// @namespace https://gf.qytechs.cn/users/303755
// ==/UserScript==

function translateToNorm(text) {
    var layouts = { "q": "й", "w": "ц", "e": "у", "r": "к", "t": "е", "y": "н", "u": "г", "i": "ш", "o": "щ", "p": "з", "[": "х", "]": "ъ", "a": "ф", "s": "ы", "d": "в", "f": "а", "g": "п", "h": "р", "j": "о", "k": "л", "l": "д", ";": "ж", "'": "э", "z": "я", "x": "ч", "c": "с", "v": "м", "b": "и", "n": "т", "m": "ь", ",": "б", ".": "ю", "/": ".", "`": "ё", "Q": "Й", "W": "Ц", "E": "У", "R": "К", "T": "Е", "Y": "Н", "U": "Г", "I": "Ш", "O": "Щ", "P": "З", "{": "Х", "}": "Ъ", "A": "Ф", "S": "Ы", "D": "В", "F": "А", "G": "П", "H": "Р", "J": "О", "K": "Л", "L": "Д", ":": "^", "\"": "Э", "|": "/", "Z": "Я", "X": "Ч", "C": "С", "V": "М", "B": "И", "N": "Т", "M": "Ь", "<": "Б", ">": "Ю", "?": ",", "~": "Ё", "@": "\"", "#": "№", "$": ";", "^": ":", "&": "?", "й": "q", "ц": "w", "у": "e", "к": "r", "е": "t", "н": "y", "г": "u", "ш": "i", "щ": "o", "з": "p", "х": "[", "ъ": "]", "ф": "a", "ы": "s", "в": "d", "а": "f", "п": "g", "р": "h", "о": "j", "л": "k", "д": "l", "ж": ";", "э": "'", "я": "z", "ч": "x", "с": "c", "м": "v", "и": "b", "т": "n", "ь": "m", "б": ",", "ю": ".", "ё": "`", "Й": "Q", "Ц": "W", "У": "E", "К": "R", "Е": "T", "Н": "Y", "Г": "U", "Ш": "I", "Щ": "O", "З": "P", "Х": "{", "Ъ": "}", "Ф": "A", "Ы": "S", "В": "D", "А": "F", "П": "G", "Р": "H", "О": "J", "Л": "K", "Д": "L", "Ж": ":", "Э": "\"", "Я": "Z", "Ч": "X", "С": "C", "М": "V", "И": "B", "Т": "N", "Ь": "M", "Б": "<", "Ю": ">", "Ё": "~", "№": "#" };
    var text_defrustrated = "";
    for (i = 0; i < text.length; i++) {
        text_defrustrated += layouts[text.charAt(i)] || text.charAt(i);
    }
    console.log(text_defrustrated);
    navigator.clipboard.writeText(text_defrustrated)

    GM_notification("Переведено: " + text_defrustrated, "Скопировано в буфер обмена", "https://cdn.discordapp.com/attachments/497134253788758026/657240742196019200/ico16.png");

    return text_defrustrated;
}

function runOnKeys(func, ...codes) {
    let pressed = new Set();

    document.addEventListener('keydown', function (event) {
        pressed.add(event.code);

        for (let code of codes) { // все ли клавиши из набора нажаты?
            if (!pressed.has(code)) {
                return;
            }
        }

        // да, все

        // во время показа alert, если посетитель отпустит клавиши - не возникнет keyup
        // при этом JavaScript "пропустит" факт отпускания клавиш, а pressed[keyCode] останется true
        // чтобы избежать "залипания" клавиши -- обнуляем статус всех клавиш, пусть нажимает всё заново
        pressed.clear();
        console.log(getSelection().toString())
        console.log(getSelection())

        /*var ke = new KeyboardEvent("keydown", { key: "v", keyCode: 86, ctrlKey: true, cancelable: true, bubbles: true });
        document.dispatchEvent(ke);*/

        document.execCommand("paste");

        func();
    });

    document.addEventListener('keyup', function (event) {
        pressed.delete(event.code);
    });

}

runOnKeys(
    function (e) {
        translateToNorm(getSelection().toString())
    },
    "ControlLeft",
    "AltLeft",
);


QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址