在進行一手的外文文獻 pdf 閱讀時,如果想大篇幅地復制並粘貼到翻譯網站上進行翻譯,會發現段落中存在大量的換行符,這既影響了翻譯也影響了閱讀。
-
復制段落
-
粘貼到網站進行翻譯,結果出現很多換行符。
那么,如何一鍵刪除這些煩人的換行符呢?這里我們嘗試編寫一個油猴腳本來解決。
解決方案
// ==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, " "));
})
})();
效果演示
以有道翻譯為例,首先復制並粘貼到網站中:
然后點擊 “去除換行符”:
最后再點擊翻譯:
目前已經適配了有道和百度。