Greasy Fork

来自缓存

有道写作快捷键

给有道写作增加快捷键Ctrl+[ 是开闭翻译

// ==UserScript==
// @name         有道写作快捷键
// @namespace    https://write.youdao.com/
// @version      2024-10-24-2
// @description  给有道写作增加快捷键Ctrl+[ 是开闭翻译
// @author       YUN
// @match        https://write.youdao.com/
// @icon         https://www.google.com/s2/favicons?sz=64&domain=greasyfork.org
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

        // 获取按钮元素
        var translateButton = document.querySelector('#index-page > div.wrap > div.editor-area > div.comp-editor-top-bar > div.bar-content-wrapper > div > div.editor-tool-box > div.editor-right > div.tool-wrapper.tool-compare-translate > span > a');
        var Esc=document.querySelector('#index-page > div:nth-child(11) > div > div > div.translateBtn');
        var a=0;

        // 监听键盘事件
        document.addEventListener('keydown', (event) => {

            // 检查是否按下 Ctrl+[
            if (event.ctrlKey && event.key === '[') {
                // 点击按钮
                translateButton = document.querySelector('#index-page > div.wrap > div.editor-area > div.comp-editor-top-bar > div.bar-content-wrapper > div > div.editor-tool-box > div.editor-right > div.tool-wrapper.tool-compare-translate > span > a');
                Esc=document.querySelector('#index-page > div:nth-child(11) > div > div > div.translateBtn');
                console.log(translateButton);
                if(a==0)
                {
                    translateButton.click();
                    a=1;
                }else
                {
                    Esc.click();
                    a=0;
                }
            }
            if (event.key === 'Escape') {
                Esc=document.querySelector('#index-page > div:nth-child(11) > div > div > div.translateBtn');
                Esc.click();
                a=0;
            }

        });
})();