谷歌翻译换行

try to take over the world!

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         谷歌翻译换行
// @namespace    http://tampermonkey.net/
// @version      0.7
// @description  try to take over the world!
// @author       You
// @match        https://translate.google.cn/*
// @match        https://translate.google.com/*
// @require      https://cdn.staticfile.org/jquery/3.5.0/jquery.min.js
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    String.prototype.toLine = function(sp) {
        let str = this;
        let _str = "";
        str.split('\n').map(_ => _.trim()).forEach(l => {
            _str += l ? l : '\r\n';
            _str += sp ? ' ' : '';
        });
        return _str;
    }
    function addAction() {
        (() => {
            let div = document.createElement('div');
            div.innerText = "去除换行(行末加空格)";
            'tlid-input-button input-button header-button'.split(' ').forEach(cl => {
                div.classList.add(cl);
            });
            div.style.paddingLeft = "16px";
            div.style.marginLeft = "20px";
            div.style.lineHeight = "34px";
            $('div[aria-label="Main menu"]').parent().append(div);
            $('div[aria-label="主菜单"]').parent().append(div);
            div.onclick = function() {
                let src = $($('textarea')[0]);
                src.val(src.val().toLine(true));
            }
        })();
        (() => {
            let div = document.createElement('div');
            div.innerText = "去除换行(不管)";
            'tlid-input-button input-button header-button'.split(' ').forEach(cl => {
                div.classList.add(cl);
            });
            div.style.paddingLeft = "16px";
            div.style.marginLeft = "20px";
            div.style.lineHeight = "34px";
            $('div[aria-label="Main menu"]').parent().append(div);
            $('div[aria-label="主菜单"]').parent().append(div);
            div.onclick = function() {
                let src = $($('textarea')[0]);
                src.val(src.val().toLine(false));
            }
        })();
        (() => {
            let div = document.createElement('div');
            div.innerText = "去除pdf复制的乱码";
            'tlid-input-button input-button header-button'.split(' ').forEach(cl => {
                div.classList.add(cl);
            });
            div.style.paddingLeft = "16px";
            div.style.marginLeft = "20px";
            div.style.lineHeight = "34px";
            $('div[aria-label="Main menu"]').parent().append(div);
            $('div[aria-label="主菜单"]').parent().append(div);
            div.onclick = function() {
                let src = $($('textarea')[0]);
                src.val(src.val().replace(/\x02/g,''));
            }
        })();
    }
    window.onload = function() {
        let host = location.href.substring(0,location.href.length - location.search.length);
        if (host === 'https://translate.google.com/') {
            setTimeout(() => {
                addAction();
            },5000);
        }
    };
    // Your code here...
})();