Greasy Fork is available in English.

Антилах (Ctrl+Win, Shift+Win)

Антилах

Mint 2020.03.05.. Lásd a legutóbbi verzió

// ==UserScript==
// @name          Антилах (Ctrl+Win, Shift+Win)
// @description	  Антилах
// @author        DygDyg
// @homepage      http://dygdyg.ddns.net
// @version       2.1.2
// @include       *
// @require       https://code.jquery.com/jquery-3.3.1.min.js
// @icon          https://cdn.discordapp.com/attachments/497134253788758026/657240743554973698/ico48.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://greasyfork.org/users/303755
// ==/UserScript==

var $ = window.jQuery;

var ver_info = '2';
var _info = 'Добавил функцию "Антикапс", по умолчанию Shift+Win, так же изменил кнопки по умолчанию для трансилта на Ctrl+Win (Изменить можно в настройках).';

//debug
$(document).ready(function () {
    //menu(); //не забыть закомментировать
});

if (GM_getValue('translite_key1', null) == null) GM_setValue('translite_key1', 'ControlLeft');
if (GM_getValue('translite_key2', null) == null) GM_setValue('translite_key2', 'MetaLeft');
if (GM_getValue('caps_key1', null) == null) GM_setValue('caps_key1', 'ShiftLeft');
if (GM_getValue('caps_key2', null) == null) GM_setValue('caps_key2', 'MetaLeft');

GM_registerMenuCommand('Настройки', () => {
    menu();
});

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 an_textdefrustrated = "";
    for (i = 0; i < text.length; i++) {
        an_textdefrustrated += layouts[text.charAt(i)] || text.charAt(i);
    }

    console.log("Перевод: " + an_textdefrustrated);
    navigator.clipboard.writeText(an_textdefrustrated)
    GM_notification({ title: "Скопировано в буфер: ", text: an_textdefrustrated, image: "https://cdn.discordapp.com/attachments/497134253788758026/657240743554973698/ico48.png", timeout: 3000 });
    return an_textdefrustrated;
}

function CapsToNorm(text) {

    text = text.toLowerCase();

    text = text[0].toUpperCase() + text.substring(1);

    console.log("Понижено: " + text);
    navigator.clipboard.writeText(text);
    GM_notification({ title: "Скопировано в буфер: ", text: text, image: "https://cdn.discordapp.com/attachments/497134253788758026/657240743554973698/ico48.png", timeout: 3000 });
    return text;
}



$(document).on('click', '.im-mess--edit._im_mess_edit', function (e) {
    if (e.ctrlKey) {
        let editor = $('.im_editable');
        let curTxt = editor.text();
        let newTxt = translateToNorm(curTxt);
        editor.text(newTxt);
        setTimeout(() => {
            $('.im-send-btn.im-chat-input--send.im-send-btn_saudio._im_send.im-send-btn_audio').click();
        }, 10)
    }
});


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;
            }
        }

        pressed.clear();

        func();
    });

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

runOnKeys(
    function (e) {
        translateToNorm(getSelection().toString())
    },
    GM_getValue('translite_key1'),
    GM_getValue('translite_key2')
);

runOnKeys(
    function (e) {
        CapsToNorm(getSelection().toString())
    },
    GM_getValue('caps_key1'),
    GM_getValue('caps_key2')
);

GM_addStyle(`
.dark-theme-box
    {
    position: fixed;
    white-space: nowrap;
    z-index: 200; height: 42px;
    top: 0; left: 0;
    padding: 0 5px 0 10px;
    line-height: 42px;
    }
.dark-theme-box a
    {
    color: red
    }
`);


//#region Вызвать меню настроек
$(document).ready(function () {

    $('#side_bar_inner ol').append($('<div>', { class: 'more_div' })).append($('<li>', { id: 'l_bt' }).append($('<a>', { class: 'left_row' }).on("click", () => { window.open('https://greasyfork.org/ru/scripts/393973-%D0%B0%D0%BD%D1%82%D0%B8%D0%BB%D0%B0%D1%85-2-0-ctrl-alt') }).append($('<span>', {
        class: 'left_fixer', html: [
            $('<span>', { class: 'left_count_wrap fl_r left_void' }).append($('<span>', { class: 'inl_bl left_count_sign' })),
            $('<span>', { class: 'left_icon fl_l' }),
            $('<span>', { class: 'left_label inl_bl', text: `Антилах ${GM_info.script.version}` })
        ]
    }))))

});

//#endregion
//#region Модальное окно //стиль
GM_addStyle(`

#an_alert {
    background: #000000a3;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200' viewBox='0 0 800 800'%3E%3Cg fill='none' stroke='%23383838' stroke-width='2'%3E%3Cpath d='M769 229L1037 260.9M927 880L731 737 520 660 309 538 40 599 295 764 126.5 879.5 40 599-197 493 102 382-31 229 126.5 79.5-69-63'/%3E%3Cpath d='M-31 229L237 261 390 382 603 493 308.5 537.5 101.5 381.5M370 905L295 764'/%3E%3Cpath d='M520 660L578 842 731 737 840 599 603 493 520 660 295 764 309 538 390 382 539 269 769 229 577.5 41.5 370 105 295 -36 126.5 79.5 237 261 102 382 40 599 -69 737 127 880'/%3E%3Cpath d='M520-140L578.5 42.5 731-63M603 493L539 269 237 261 370 105M902 382L539 269M390 382L102 382'/%3E%3Cpath d='M-222 42L126.5 79.5 370 105 539 269 577.5 41.5 927 80 769 229 902 382 603 493 731 737M295-36L577.5 41.5M578 842L295 764M40-201L127 80M102 382L-261 269'/%3E%3C/g%3E%3Cg fill='%23696969'%3E%3Ccircle cx='769' cy='229' r='8'/%3E%3Ccircle cx='539' cy='269' r='8'/%3E%3Ccircle cx='603' cy='493' r='8'/%3E%3Ccircle cx='731' cy='737' r='8'/%3E%3Ccircle cx='520' cy='660' r='8'/%3E%3Ccircle cx='309' cy='538' r='8'/%3E%3Ccircle cx='295' cy='764' r='8'/%3E%3Ccircle cx='40' cy='599' r='8'/%3E%3Ccircle cx='102' cy='382' r='8'/%3E%3Ccircle cx='127' cy='80' r='8'/%3E%3Ccircle cx='370' cy='105' r='8'/%3E%3Ccircle cx='578' cy='42' r='8'/%3E%3Ccircle cx='237' cy='261' r='8'/%3E%3Ccircle cx='390' cy='382' r='8'/%3E%3C/g%3E%3C/svg%3E");
    backdrop-filter: blur(2px);
    width: 100%;
    height: 100%;
    position: fixed;
    z-index: 99999999;
    text-align: center;
}

#window1 {
    background-color: #272727db !important;
    width: 300px;
    /*height: 120px;*/
    border-radius: 4px;
    position: absolute;
    top: 10%;
    left: 50%;
    transform: translate(-50%);
    padding: 10px 10px 10px 10px;
    box-shadow: 7px 7px 3px 3px rgba(0,0,0,.1);
}

.stop-scrolling {
  height: 100%;
  overflow: hidden;
}

.an_theme_button {
    display: block;
    padding: 7px 16px 8px;
    margin: 5px;
    font-size: 12.5px;
    zoom: 1;
    cursor: pointer;
    white-space: nowrap;
    outline: none;
    font-family: -apple-system,BlinkMacSystemFont,Roboto,Helvetica Neue,"Noto Sans Armenian","Noto Sans Bengali","Noto Sans Cherokee","Noto Sans Devanagari","Noto Sans Ethiopic","Noto Sans Georgian","Noto Sans Hebrew","Noto Sans Kannada","Noto Sans Khmer","Noto Sans Lao","Noto Sans Osmanya","Noto Sans Tamil","Noto Sans Telugu","Noto Sans Thai",sans-serif;
    vertical-align: top;
    line-height: 15px;
    text-align: center;
    text-decoration: none;
    background: none;
    background-color: #5181b8a3;
    color: #fff;
    border: 0;
    border-radius: 4px;
    box-sizing: border-box;
    box-shadow: 7px 7px 3px 3px rgba(0,0,0,.1);
}

div#test1 {
    text-align: center;
}

div#key {
    text-align: center;
    /*margin-bottom: 40px;*/
}

.an_text {
    width: 290px;
    margin: 5px;
    box-sizing: border-box;
    padding: 7px;
    border: none;
    border-radius: 2px;
    display: flex;
    height: 86px;
    resize: none;
    background: #6b6b6bad !important;
    color: white;
    box-shadow: 7px 7px 3px 3px rgba(0,0,0,.1);
}

div#image {
    width: 290px;
    height: 180px;
    margin: 0 auto;
    margin-bottom: 5px;
    border-radius: 4px;
}


.theme_text {
    font-size: 19px;
    line-height: 25px;
    font-weight: 400;
    -webkit-font-smoothing: subpixel-antialiased;
    -moz-osx-font-smoothing: auto;
    margin: -1px 0 -1px -1px;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-left: 1px;
    color: #fff;
    box-shadow: 7px 7px 3px 3px rgba(0,0,0,.1);
}

.cont-bottom {
    border-bottom: 1px solid #b5b1b191;
}
img.izo {
    object-fit: cover;
    width: 100%;
    height: 100%;
    background: url(https://sun9-57.userapi.com/c857620/v857620009/18a5fd/uOxmtZm_L2A.jpg);
    background-size: 100%;
    box-shadow: 7px 7px 3px 3px rgba(0,0,0,.1);
}


`)

//#endregion
//#region Модальное окно //логика


var on = true;
function menu() {
    var newImage;
    $('body').addClass('stop-scrolling').prepend(
        $('<div>', { id: 'an_alert' }).append(
            $('<div>', { id: 'window1' }).append(
                $('<div>', {
                    class: 'cont-bottom', id: 'cont1', html: [
                        $('<div>', { class: 'theme_text', text: 'Смена раскладки транслита' }).css({ 'cursor': 'default' }),
                        //$('<div>', { class: 'cont-bottom' }),
                        $('<div>', { class: 'theme_text', text: 'установлено', id: 'key1' }).css({ 'cursor': 'default' }),
                        $('<div>', { class: 'theme_text', text: GM_getValue('translite_key1') + ' + ' + GM_getValue('translite_key2'), id: 'key2' }).css({ 'cursor': 'default' }),
                        $('<div>', { class: 'an_theme_button', id: 'button_translite_edit', text: 'Изменить' }).on('click', translite_key_add)
                    ]
                })
            ).append($('<div>', { class: 'cont-bottom' })).append(
                $('<div>', {
                    class: 'cont-bottom', id: 'cont2', html: [
                        $('<div>', { class: 'theme_text', text: 'Смена раскладки капса (не реализовано)' }).css({ 'cursor': 'default' }),
                        //$('<div>', { class: 'cont-bottom' }),
                        $('<div>', { class: 'theme_text', text: 'установлено', id: 'key1' }).css({ 'cursor': 'default' }),
                        $('<div>', { class: 'theme_text', text: GM_getValue('caps_key1') + ' + ' + GM_getValue('caps_key2'), id: 'key2' }).css({ 'cursor': 'default' }),
                        $('<div>', { class: 'an_theme_button', id: 'button_caps_edit', text: 'Изменить' }).on('click', caps_key_add)
                    ]
                })
            ).append(
                $('<div>', {
                    class: 'cont-bottom', id: 'cont2', html: [
                        $('<div>', { class: 'theme_text', text: 'Изменения вступят в силу после перезагрузки страницы' }).css({ 'color': 'red', 'font-size': '16px', 'line-height': '17px', 'cursor': 'pointer' }).on('click', refresh)
                    ]
                })
            ).append(
                $('<div>', { class: 'an_theme_button', id: 'button_exit', text: 'Закрыть' }).on('click', exit_)
            )));
}
//#endregion
//#region Настройка управления
var key1;
var key2;
var keycode1;
var keycode2;
var key_caps;
var key_translite;

let pressed = new Set();

$(document).on('keyup', function (e) {
    t = e.originalEvent.code;
    pressed.add(t);
    pressed.clear();
    if (key_translite == true) {
        if (key1 == true) {
            console.log("test_key1");
            key1 = false;
            key2 = true;
            keycode1 = t;
            $('#cont1 #key1').text('Нажмите вторую клавишу');
            $('#cont1 #key2').text(keycode1 + ' + <key>');
        } else if (key2 == true) {
            console.log("test_key2");
            key2 = false;
            keycode2 = t;
            $('#cont1 #key1').text('установлено');
            $('#cont1 #key2').text(keycode1 + ' + ' + keycode2);
            GM_setValue('translite_key1', keycode1);
            GM_setValue('translite_key2', keycode2);
            $('#button_translite_edit').css({ 'background-color': '#5181b8', 'pointer-events': 'auto', 'color': '#fff' });
            key_translite = false;
        }
    } else if (key_caps == true) {
        if (key1 == true) {
            console.log("test_key1");
            key1 = false;
            key2 = true;
            keycode1 = t;
            $('#cont2 #key1').text('Нажмите вторую клавишу');
            $('#cont2 #key2').text(keycode1 + ' + <key>');

        } else if (key2 == true) {
            console.log("test_key2");
            key2 = false;
            keycode2 = t;
            $('#cont2 #key1').text('установлено');
            $('#cont2 #key2').text(keycode1 + ' + ' + keycode2);
            GM_setValue('caps_key1', keycode1);
            GM_setValue('caps_key2', keycode2);
            $('#button_caps_edit').css({ 'background-color': '#5181b8', 'pointer-events': 'auto', 'color': '#fff' });
            key_caps = false;
        }
    }
});


function translite_key_add() {
    $('#cont1 #key1').text('Нажмите первую клавишу');
    $('#cont1 #key2').text('<key> + <key>');
    $('#button_translite_edit').css({ 'background-color': '#a5a5a566', 'pointer-events': 'none', 'color': '#777' });
    key1 = true;
    key_translite = true;
}

function caps_key_add() {
    $('#cont2 #key1').text('Нажмите первую клавишу');
    $('#cont2 #key2').text('<key> + <key>');
    $('#button_caps_edit').css({ 'background-color': '#a5a5a566', 'pointer-events': 'none', 'color': '#777' });
    key1 = true;
    key_caps = true;
}

function exit_() {
    $('#an_alert').remove();
    $('body').removeClass('stop-scrolling');
}

function refresh() { window.location.reload() }

if (GM_getValue('ver_info', null) == null) GM_setValue('ver_info', '0');

$(document).ready(function () {
    if (GM_getValue('ver_info') != ver_info) {
        info();

    }

})

function info() {
    $('body').addClass('stop-scrolling').prepend(
        $('<div>', { id: 'an_alert' }).append(
            $('<div>', { id: 'window1' }).append(
                $('<div>', {
                    class: 'cont-bottom', id: 'cont1', html: [
                        $('<div>', { class: 'theme_text', text: GM_info.script.name + ' ' + GM_info.script.version }),
                        $('<div>', { class: 'theme_text', text: 'Нововведения:' }),
                    ]
                })
            ).append(
                $('<div>', {
                    class: 'cont-bottom', id: 'cont1', html: [
                        $('<div>', { style: 'font-size: 14px; text-align: -webkit-auto;', class: 'theme_text', text: _info })
                    ]
                })).append(
                    $('<div>', { class: 'an_theme_button', id: 'button_exit', text: 'Закрыть' }).on('click', () => {
                        GM_setValue('ver_info', ver_info);
                        exit_();
                    }))
        )
    )
}

//#endregion