Translate Helper

翻译去换行

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Translate Helper
// @namespace    http://tampermonkey.net/
// @version      3.2
// @description  翻译去换行
// @author       o1hy
// @match        https://translate.google.com/*
// @match        https://translate.google.cn/*
// @match        https://www.deepl.com/*
// @match        https://fanyi.sogou.com/*
// @match        http://fanyi.youdao.com/*
// @grant        none
// ==/UserScript==

function new_version(){
    var url = window.location.href

    if(url.includes("deepl.com")){
        var a = document.querySelector("#dl_translator > div > div > div > div > div > textarea");
    }else if(url.includes("translate.google")){
        var a = document.querySelector("body > c-wiz > div > div > c-wiz > div > c-wiz > div > div > div > c-wiz > span > span > div > textarea");
    }else if(url.includes("sogou.com")){
        var a = document.querySelector("#trans-input");
    }else if(url.includes("fanyi.youdao.com")){
        var a = document.querySelector("#inputOriginal");
    }

    a.addEventListener("paste",function(event){

        let paste = (event.clipboardData || window.clipboardData).getData('text');

        paste = paste.replaceAll("\n"," ")
        paste = paste.replaceAll("\r"," ")

        document.execCommand("insertText",false,paste)
        event.preventDefault();
    })
}



(function() {
   'use strict';
   new_version();
})();