// ==UserScript== // @name 翻译插件——去除换行 // @namespace https://greasyfork.org/zh-CN/scripts/390059-%E7%BF%BB%E8%AF%91%E6%8F%92%E4%BB%B6-%E5%8E%BB%E9%99%A4%E6%8D%A2%E8%A1%8C // @version 1.1 // @description add a new button for removing '\n' // @author Kevin Chen // @match https://fanyi.baidu.com/* // @match http://fanyi.youdao.com/ // @match https://translate.google.cn/* // @match https://translate.google.com/* // @icon https://translate.google.cn/favicon.ico // @grant none // @run-at document-end // @downloadURL none // ==/UserScript== function reload() { var txt = ""; var id = ""; var host = window.location.host; if( host == "fanyi.baidu.com" ) { id = "baidu_translate_input"; } if( host == "fanyi.youdao.com" ) { id = "inputOriginal"; } if( host == "translate.google.cn" || host == "translate.google.com" ) { id = "source"; } txt = document.getElementById(id).value; for (var i=0;i' + txt + ''); new_button.style.textAlign = "center"; new_button.style.height = "30px"; new_button.style.lineHeight = "30px"; new_button.style.fontSize = "14px"; new_button.style.color = "#4395ff"; new_button.style.backgroundColor = "#fff"; new_button.style.border = "1px solid #4395ff"; new_button.style.borderRadius = "3px"; new_button.onclick = reload; return new_button; } function createYoudaoButton(txt) { var new_button = str2elem('' + txt + ''); new_button.onclick = reload; return new_button; } (function main() { var host = window.location.host; var container = null; var new_button = null; if(host == "translate.google.cn" || host == "translate.google.com"){ new_button = createGoogleButton("格式化"); // Get container var container1 = document.querySelector("body > div.frame > div.page.tlid-homepage.homepage.translate-text > div.input-button-container > div") var container2 = document.querySelector("body > div.frame > div.page.tlid-homepage.homepage.translate-docs > div.input-button-container > div") container = container1 || container2; } else if (host == "fanyi.baidu.com") { new_button = createBaiduButton("格式化"); container = document.querySelector("#main-outer > div > div > div.translate-wrap > div.trans-operation-wrapper.clearfix > div.trans-operation.clearfix"); } else if (host == "fanyi.youdao.com") { new_button = createYoudaoButton("格式化"); container = document.querySelector("body > div.fanyi > div.fanyi__operations > div.fanyi__operations--left"); } container.appendChild(new_button); })();