Google翻译 替换

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

目前為 2017-11-12 提交的版本,檢視 最新版本

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