Skip to content

Instantly share code, notes, and snippets.

@yuantailing
Last active December 1, 2018 04:27
Show Gist options
  • Save yuantailing/8fd1aa455a21c25361a5cdac251c7958 to your computer and use it in GitHub Desktop.
Save yuantailing/8fd1aa455a21c25361a5cdac251c7958 to your computer and use it in GitHub Desktop.
点“concatenate lines”删除英文里的换行。适用于从 PDF 复制到 Google Translate 的文本
// ==UserScript==
// @name Google Translation Concatenate Lines
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Concatenate source lines in Google translation.
// @author github.com/yuantailing
// @match https://translate.google.com/*
// @match https://translate.google.com.hk/*
// @match https://translate.google.cn/*
// @require https://unpkg.com/[email protected]/dist/jquery.min.js
// @grant none
// ==/UserScript==
/**/;(function($) {
'use strict';
$(document).ready(function() {
function concat(e) {
e.preventDefault();
var src = $('#source').val();
src = src.replace(/-\n/g, '').replace(/\n\n/g, '__DOUBLE_CR__');
var dst = src.split('\n').join(' ');
dst = dst.replace(/__DOUBLE_CR__/g, '\n\n');
$('#source').val(dst);
}
var button = $('<button></button>');
button.text('concatenate lines');
button.addClass('goog-inline-block jfk-button jfk-button-standard');
button.click(concat);
var div = $('<div></div>');
div.append(button);
$('#gt-src-c').append(div);
var div1 = $('<div></div>');
div1.text('concatenate lines');
div1.addClass('text');
var div2 = $('<div></div>');
div2.addClass('input-button').addClass('header-button');
div2.css('padding-left', '16px');
div2.attr('tabindex', '-1');
div2.click(concat);
div2.append(div1);
$('.tlid-input-button-container').append(div2);
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment