百度翻译

小庄的脚本园

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         百度翻译
// @namespace    http://tampermonkey.net/
// @version      5.2.1
// @description  小庄的脚本园
// @author       zjazn
// @match        *://*.fanyi.baidu.com/*
// @grant        GM_getValue
// @grant        GM.getValue
// @grant        GM_setValue
// @grant        GM.setValue
// @run-at       document-start
// @match        <$URL$>
// ==/UserScript==

(function () {
    //用于等待资源传输完成
    setTimeout(function(){
        function sleep (time) {
            return new Promise((resolve) => setTimeout(resolve, time));
        }
        function start() {
            if(document.querySelector('.operate-btn')) {
                document.querySelector('.operate-btn')?document.querySelector('.operate-btn').click():''
                var timing = setTimeout(function(){
                    console.log("字符长度:",document.getElementById("baidu_translate_input").value.length);
                    sleep(500).then(() => {
                        // 这里写sleep之后需要去做的事情
                        start();
                    })
                },document.getElementById("baidu_translate_input").value.length*300 )
            }
        }
        start();

    },500)




})();