google翻译 替换

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

目前为 2017-11-12 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name google翻译 替换
  3. // @name:ja Google Translate replace
  4. // @name:en Google Translate replace
  5. // @namespace https://github.com/Ahaochan/Tampermonkey
  6. // @version 0.0.1
  7. // @description 对翻译后的字符串进行替换。github:https://github.com/Ahaochan/Tampermonkey,欢迎star和fork。
  8. // @description:ja Replace the translated string. Github:https://github.com/Ahaochan/Tampermonkey. Star and fork is welcome.
  9. // @description:en Replace the translated string. Github:https://github.com/Ahaochan/Tampermonkey. Star and fork is welcome.
  10. // @author Ahaochan
  11. // @match https://translate.google.cn
  12. // @match https://translate.google.*
  13. // @grant GM_setValue
  14. // @grant GM_getValue
  15. // @require https://code.jquery.com/jquery-2.2.4.min.js
  16. // ==/UserScript==
  17.  
  18. (function ($) {
  19. 'use strict';
  20.  
  21. var pattern = GM_getValue('pattern', ' ');
  22. var replace = GM_getValue('replace', '_');
  23.  
  24. var $div = $('<div class="gt-lang-sugg-message goog-inline-block je"' +
  25. ' style="float: right; padding: 2px">' +
  26. '<input id="ahao-pattern" placeholder="pattern" style="width: 50px;" value="'+pattern+'"> >>' +
  27. '<input id="ahao-replace" placeholder="replace" style="width: 50px; margin: 0 4px;" value="'+replace+'">' +
  28. '<input id="ahao-button" type="button" class="jfk-button jfk-button-action" value="replace">' +
  29. '</div>');
  30. var $resultBox = $('#result_box');
  31.  
  32. $div.find('#ahao-button').on('click', function () {
  33. var pattern = $div.find('#ahao-pattern').val();
  34. var replace = $div.find('#ahao-replace').val();
  35. GM_setValue('pattern', pattern);
  36. GM_setValue('replace', replace);
  37.  
  38. var text = $resultBox.text();
  39. $resultBox.text(text.replace(new RegExp(pattern, 'gm'),replace));
  40. });
  41.  
  42. $('#gt-lang-right').append($div);
  43. })(jQuery);