谷歌翻译换行

try to take over the world!

目前為 2020-10-14 提交的版本,檢視 最新版本

// ==UserScript==
// @name         谷歌翻译换行
// @namespace    http://tampermonkey.net/
// @version      0.3
// @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;
    }
    window.onload = function() {
        (() => {
            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";
            $('#gb > div.gb_Ud.gb_ee.gb_4d.gb_3d > div.gb_Td.gb_1c.gb_2c').append(div);
            div.onclick = function() {
                let src = $('#source');
                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";
            $('#gb > div.gb_Ud.gb_ee.gb_4d.gb_3d > div.gb_Td.gb_1c.gb_2c').append(div);
            div.onclick = function() {
                let src = $('#source');
                src.val(src.val().toLine(false));
            }
        })();
    }
    // Your code here...
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址