google 翻译添加文字格式化窗口

在 google trans 页面添加一个输入框,帮助去除文本的回车

  1. // ==UserScript==
  2. // @name google 翻译添加文字格式化窗口
  3. // @namespace google-trans-delete-wrap
  4. // @version 1.0
  5. // @description 在 google trans 页面添加一个输入框,帮助去除文本的回车
  6. // @author Ericwyn
  7. // @match https://translate.google.com/*
  8. // @match https://translate.google.cn/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14. let isChinaSite = window.location.href.indexOf("google.cn") >= 0;
  15.  
  16. let style = `
  17. height: 150px;
  18. border-radius: 8px;
  19. box-shadow: rgba(0, 0, 0, 0.37) 0px 1px 4px 0px;
  20. border: rgb(255, 255, 255);
  21. outline: none;
  22. resize:none;
  23. padding: 20px;
  24. font-size: 20px;
  25. margin: 0px;
  26. width: 100%;
  27. max-width: ${isChinaSite?"1240px":"1240px"};
  28. `
  29. if(isChinaSite) {
  30. style += "width:100%"
  31. }
  32.  
  33. let textAreaHtml = `<br><textarea
  34. class=".textarea-replace-str"
  35. style="${replaceAllN(style)}"
  36. id="input"
  37. placeholder="粘贴到此处去除多余回车"></textarea>`;
  38.  
  39.  
  40. let domIndex = -1;
  41. let divs = document.getElementsByTagName("div");
  42. for (let i =0;i<divs.length;i++){
  43. if(divs[i].innerText == "发送反馈"){
  44. // console.log(divs[i])
  45. domIndex = i;
  46. break;
  47. }
  48. }
  49. if(isChinaSite) {
  50. divs[domIndex].previousElementSibling.outerHTML += textAreaHtml
  51. } else {
  52. divs[domIndex].previousElementSibling.outerHTML += textAreaHtml
  53.  
  54. // divs[domIndex].nextElementSibling.outerHTML = textAreaHtml + divs[domIndex].nextElementSibling.outerHTML;
  55. }
  56.  
  57. let input = document.getElementById("input")
  58.  
  59. // 消除全部回车
  60. function replaceAllN(str){
  61. while(str.indexOf("\n") > 0) {
  62. str = str.replace("\n", " ");
  63. // console.log("replace:" + str)
  64. }
  65. return str
  66. }
  67.  
  68. input.addEventListener('input',function () {
  69. if(input.value.indexOf("\n") > 0) {
  70. let text = input.value;
  71. text = replaceAllN(text)
  72. document.getElementById("input").value = text;
  73. // 复制
  74. const copyText = document.querySelector('#input');
  75. copyText.select();
  76. if (document.execCommand('copy')) {
  77. document.execCommand('copy');
  78. }
  79.  
  80. }
  81. });
  82.  
  83. })();
  84.  
  85.  

QingJ © 2025

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