pdf复制去回车脚本

复制PDF的内容之后,点击Change按钮,实现去回车翻译

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         pdf复制去回车脚本
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  复制PDF的内容之后,点击Change按钮,实现去回车翻译
// @author       sun_liber
// @match        https://fanyi.baidu.com/*
// @match        http://fanyi.youdao.com/*
// @match        https://translate.google.cn/*
// @match        https://translate.google.com/*
// @match        https://translate.google.com/*
// ==/UserScript==

(function() {
    var txt = "";
    var id = "";
    var transButtonId=""
    var host = window.location.host;
    if( host == "fanyi.baidu.com" )
    {
       id = "baidu_translate_input";
        transButtonId="translate-button";
    }
    if( host == "fanyi.youdao.com" )
    {
       id = "inputOriginal";
        transButtonId="transMachine";
    }
    if( host == "translate.google.cn" || host == "translate.google.com" )
    {
       id = "source";
       //谷歌翻译好像没有按钮
    }


    var button = document.createElement('button');
    button.setAttribute('style','position:fixed;top:300px;left:30px;');
    button.textContent="Change";
    button.onclick=function(){
          txt = document.getElementById(id).value;
        for (var i=0;i<txt.length;i++)
        {
            if(txt.indexOf("\n"))txt = txt.replace("\n"," ");
        }
        document.getElementById(id).value = txt;

        transButtonId!==""?document.getElementById(transButtonId).click():console.log("谷歌大法好啊");

    }
    document.body.appendChild(button);
})();