notranslate-防止chrome翻译代码段和公式

A tampermonkey script aims to prevent unnecessary translation of code segment and math equations.

目前为 2020-03-26 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name notranslate-防止chrome翻译代码段和公式
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description A tampermonkey script aims to prevent unnecessary translation of code segment and math equations.
  6. // @author winding
  7. // @supportURL https://github.com/windingwind/notranslate/blob/master/README.md
  8. // @include *
  9. // @require http://code.jquery.com/jquery-3.4.1.min.js
  10. // @grant GM_setValue
  11. // @grant GM_getValue
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16. /* You can add your settings here.
  17. "type" can be "id", "class", or "element".
  18. "param" is how you trace the target element.
  19. */
  20. const behaviorList = [
  21. {
  22. 'type':'class',
  23. 'param':'prettyprint',
  24. },
  25. {
  26. 'type':'class',
  27. 'param':'mjx-chtml',
  28. },
  29. {
  30. 'type':'class',
  31. 'param':'MathJax_Display',
  32. },
  33. {
  34. 'type':'class',
  35. 'param':'katex--display',
  36. },
  37. {
  38. 'type':'class',
  39. 'param':'syntaxhighlighter',
  40. },
  41. ];
  42. function addNotranslate (selector, loop, interval) {
  43. $(selector).attr("class", function(i,origValue){
  44. return origValue + " notranslate";
  45. });
  46. }
  47. function run () {
  48. console.log($);
  49. for(let i = 0; i < behaviorList.length; i++) {
  50. //console.log(behaviorList[i]);
  51. let selector = '';
  52. switch (behaviorList[i].type){
  53. case 'class':
  54. selector = "."+behaviorList[i].param;
  55. break;
  56. case 'id':
  57. selector = "#"+behaviorList[i].param;
  58. break;
  59. case 'element':
  60. selector = behaviorList[i].param;
  61. break;
  62. }
  63. addNotranslate(selector, behaviorList[i].loop, behaviorList[i].interval);
  64. }
  65. }
  66. function main(){
  67. $(function(){
  68. $("body").keyup(function(event){
  69. if (event.ctrlKey && event.keyCode === 81){
  70. if(confirm('Will add "notranslate" to some elements on his page. Continue?')){
  71. run();
  72. console.log('finish');
  73. }
  74. }
  75. });
  76. });
  77. }
  78. main();
  79. })();// ==UserScript==
  80. // @name notranslate-防止chrome翻译代码段和公式
  81. // @namespace http://tampermonkey.net/
  82. // @version 0.1
  83. // @description A tampermonkey script aims to prevent unnecessary translation of code segment and math equations.
  84. // @author winding
  85. // @supportURL https://github.com/windingwind/notranslate/blob/master/README.md
  86. // @include *
  87. // @require http://code.jquery.com/jquery-3.4.1.min.js
  88. // @grant GM_setValue
  89. // @grant GM_getValue
  90. // ==/UserScript==
  91.  
  92. (function() {
  93. 'use strict';
  94. /* You can add your settings here.
  95. "type" can be "id", "class", or "element".
  96. "param" is how you trace the target element.
  97. */
  98. const behaviorList = [
  99. {
  100. 'type':'class',
  101. 'param':'prettyprint',
  102. },
  103. {
  104. 'type':'class',
  105. 'param':'mjx-chtml',
  106. },
  107. {
  108. 'type':'class',
  109. 'param':'MathJax_Display',
  110. },
  111. {
  112. 'type':'class',
  113. 'param':'katex--display',
  114. },
  115. {
  116. 'type':'class',
  117. 'param':'syntaxhighlighter',
  118. },
  119. ];
  120. function addNotranslate (selector, loop, interval) {
  121. $(selector).attr("class", function(i,origValue){
  122. return origValue + " notranslate";
  123. });
  124. }
  125. function run () {
  126. console.log($);
  127. for(let i = 0; i < behaviorList.length; i++) {
  128. //console.log(behaviorList[i]);
  129. let selector = '';
  130. switch (behaviorList[i].type){
  131. case 'class':
  132. selector = "."+behaviorList[i].param;
  133. break;
  134. case 'id':
  135. selector = "#"+behaviorList[i].param;
  136. break;
  137. case 'element':
  138. selector = behaviorList[i].param;
  139. break;
  140. }
  141. addNotranslate(selector, behaviorList[i].loop, behaviorList[i].interval);
  142. }
  143. }
  144. function main(){
  145. $(function(){
  146. $("body").keyup(function(event){
  147. if (event.ctrlKey && event.keyCode === 81){
  148. if(confirm('Will add "notranslate" to some elements on his page. Continue?')){
  149. run();
  150. console.log('finish');
  151. }
  152. }
  153. });
  154. });
  155. }
  156. main();
  157. })();