Google翻译 替换

对翻译后的字符串进行替换。github:https://github.com/Ahaochan/Tampermonkey,欢迎star和fork。

  1. // ==UserScript==
  2. // @name Google Translate replace
  3. // @name:zh-CN Google翻译 替换
  4. // @namespace https://github.com/Ahaochan/Tampermonkey
  5. // @version 0.0.3
  6. // @description Replace the translated string. Github:https://github.com/Ahaochan/Tampermonkey. Star and fork is welcome.
  7. // @description:zh-CN 对翻译后的字符串进行替换。github:https://github.com/Ahaochan/Tampermonkey,欢迎star和fork。
  8. // @author Ahaochan
  9. // @include http*://translate.google.*
  10. // @grant GM.setValue
  11. // @grant GM.getValue
  12. // @require https://code.jquery.com/jquery-2.2.4.min.js
  13. // ==/UserScript==
  14.  
  15. jQuery(function ($) {
  16. 'use strict';
  17.  
  18. // 1. 初始化之前设置的 pattern 和 replace
  19. let $div = $('<div class="tlid-input-button input-button header-button tlid-input-button-docs documents-icon" role="tab" tabindex="-1">' +
  20. '<div class="text">' +
  21. ' <input id="ahao-pattern" placeholder="pattern" style="width: 50px;"> >>' +
  22. ' <input id="ahao-replace" placeholder="replace" style="width: 50px; margin: 0 4px;">' +
  23. ' <span id="ahao-button">替换</span>' +
  24. '</div></div>');
  25. $('.tlid-input-button-container').append($div);
  26. GM.getValue('pattern').then(function (value) { $('#ahao-pattern').val(value); });
  27. GM.getValue('replace').then(function (value) { $('#ahao-replace').val(value); });
  28.  
  29. // 2. 绑定替换事件
  30. $('#ahao-button').on('click', function () {
  31. let pattern = $('#ahao-pattern').val();
  32. let replace = $('#ahao-replace').val();
  33. GM.setValue('pattern', pattern);
  34. GM.setValue('replace', replace);
  35.  
  36. $('.translation').find('span').each(function () {
  37. let $this = $(this);
  38. $this.text($this.text().replace(new RegExp(pattern, 'gm'), replace));
  39. });
  40. });
  41. });

QingJ © 2025

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