一鍵去除 pdf 復制並翻譯時的大量換行符


在進行一手的外文文獻 pdf 閱讀時,如果想大篇幅地復制並粘貼到翻譯網站上進行翻譯,會發現段落中存在大量的換行符,這既影響了翻譯也影響了閱讀。

  • 復制段落
    image

  • 粘貼到網站進行翻譯,結果出現很多換行符。
    image

那么,如何一鍵刪除這些煩人的換行符呢?這里我們嘗試編寫一個油猴腳本來解決。

解決方案

// ==UserScript==
// @name         New Userscript
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://fanyi.youdao.com/
// @match        https://fanyi.baidu.com/
// @icon         https://www.google.com/s2/favicons?domain=youdao.com
// @require      http://code.jquery.com/jquery-1.11.0.min.js
// @grant        GM_addStyle
// ==/UserScript==

(function() {
    'use strict';

    $('#transMachine').before(`
      <a class="fanyi__operations--machine" id="removeEner" href="javascript:;">去除換行符</a>
     `)

    $('#removeEner').click(function() {
        $('#inputOriginal').val($('#inputOriginal').val().replace(/[\r\n]/g, "  "));
    })

    $('#translate-button').before(`
      <a class="trans-btn trans-btn-zh" id="removeEner" href="javascript:;" style="letter-spacing:1px">去除換行符</a>
     `)

    let css = `
   .select-from-language, .select-to-language {
    min-width:120px!important;
    width:120px!important;
    }
    `
    GM_addStyle(css);
    $('#removeEner').click(function() {
        $('#baidu_translate_input').val($('#baidu_translate_input').val().replace(/[\r\n]/g, "  "));
    })


})();

效果演示

以有道翻譯為例,首先復制並粘貼到網站中:

image

然后點擊 “去除換行符”:

image

最后再點擊翻譯:

image

目前已經適配了有道和百度。

image


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM