Customize Google Translate

For Google Translate, you can customize and specify tags and keywords without translating

  1. // ==UserScript==
  2. // @name Customize Google Translate
  3. // @description For Google Translate, you can customize and specify tags and keywords without translating
  4. // @author levinu634
  5. // @name:zh-CN 自定义谷歌翻译
  6. // @name:en Customize Google Translate
  7. // @namespace http://tampermonkey.net/
  8. // @version 1.0
  9. // @description:zh-cn 针对谷歌翻译,可以自定义指定标签、关键词不翻译
  10. // @description:en For Google Translate, you can customize and specify tags and keywords without translating
  11. // @match *://github.com/*
  12. // @match *://www.elastic.co/*
  13. // @match *://spring.io/*
  14. // @match *://docs.spring.io/*
  15. // @license GPL
  16. // @require http://code.jquery.com/jquery-3.4.1.min.js
  17. // @supportURL https://github.com/levinu634/Customize-Google-Translate
  18. // @grant none
  19. // ==/UserScript==
  20.  
  21. (function () {
  22. 'use strict'
  23. const commonWords = []; //适配所有网页的通用不翻译关键词 Universal untranslated keywords for all web pages
  24. const filterList = [
  25. {
  26. //Customize the target site of the translation configuration. be careful! Before adding a new target page configuration, please add the matching of the target page in the script header
  27. 'website': 'spring.io', //自定义翻译配置的目标网站。注意!添加新目标网页配置前,请在脚本头部添加目标网页的匹配,参考// @match *://github.com/*
  28. 'notranslate': {
  29. 'classes': ['sidebar', 'sidebar_children'], //特定class属性标签不翻译 Specific class attribute labels are not translated
  30. 'ids': [], //特定id标签不翻译 No translation of specific id tags
  31. 'elements': [], //特定标签不翻译
  32. 'words': ['Spring Data REST'], //目标网页下不翻译的关键词 Keyword not translated under the target page
  33. }
  34. },
  35. {
  36. 'website': 'github.com',
  37. 'notranslate': {
  38. 'classes': ['file-navigation', 'flex-wrap', 'js-navigation-open', 'BorderGrid-cell', 'filter-list', 'mr-31', 'topic-tag', 'v-align-middle', 'js-navigation-open',],
  39. 'ids': [],
  40. 'elements': ['pre'],
  41. 'words': [],
  42. }
  43. },
  44. {
  45. 'website': 'www.elastic.co',
  46. 'notranslate': {
  47. 'classes': ['programlisting'],
  48. 'ids': [],
  49. 'elements': [],
  50. 'words': [],
  51. }
  52. },
  53. ]
  54.  
  55. function filter() {
  56. for (let i = 0; i < filterList.length; i++) {
  57. const web = filterList[i];
  58. if (web.website !== window.location.host) {
  59. continue;
  60. }
  61. var notranslate = web.notranslate;
  62. if (notranslate.classes !== null) {
  63. addNotranlate(notranslate.classes, 'classes');
  64. }
  65. if (notranslate.ids !== null) {
  66. addNotranlate(notranslate.ids, 'ids');
  67. }
  68. if (notranslate.elements !== null) {
  69. addNotranlate(notranslate.elements, 'elements');
  70. }
  71. if (notranslate.words !== null) {
  72. addNotranlate(notranslate.words, 'words');
  73. }
  74. }
  75. if (commonWords.length > 0) {
  76. addNotranlate(commonWords, 'words');
  77. }
  78. }
  79.  
  80. function addNotranlate(filterArrray, type) {
  81. for (let index in filterArrray) {
  82. console.log(filterArrray)
  83. let selector;
  84. if (type === 'classes') {
  85. selector = '.' + filterArrray[index]
  86. } else if (type === 'ids') {
  87. selector = '#' + filterArrray[index]
  88. } else if (type === 'elements') {
  89. selector = filterArrray[index]
  90. } else if (type === 'words') {
  91. var reg=new RegExp(filterArrray[index],"gi");
  92. document.body.innerHTML = document.body.innerHTML.replace(reg, '<span class="notranslate">' + filterArrray[index] + '</span>');
  93. continue;
  94. }
  95. $(selector).addClass('notranslate');
  96. // $(selector).addClass('cyxy-no-trs'); //对彩云小译的支持 Support for another translation plug-in
  97. }
  98. }
  99.  
  100. filter();
  101. })();

QingJ © 2025

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