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

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

当前为 2020-02-22 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name notranslate-防止chrome翻译代码段和公式
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  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':'katex--display',
  32. },
  33. {
  34. 'type':'class',
  35. 'param':'syntaxhighlighter',
  36. },
  37. ];
  38. function addNotranslate (selector, loop, interval) {
  39. $(selector).attr("class", function(i,origValue){
  40. return origValue + " notranslate";
  41. });
  42. }
  43. function run () {
  44. console.log($);
  45. for(let i = 0; i < behaviorList.length; i++) {
  46. //console.log(behaviorList[i]);
  47. let selector = '';
  48. switch (behaviorList[i].type){
  49. case 'class':
  50. selector = "."+behaviorList[i].param;
  51. break;
  52. case 'id':
  53. selector = "#"+behaviorList[i].param;
  54. break;
  55. case 'element':
  56. selector = behaviorList[i].param;
  57. break;
  58. }
  59. addNotranslate(selector, behaviorList[i].loop, behaviorList[i].interval);
  60. }
  61. }
  62. function main(){
  63. $(function(){
  64. $("body").keyup(function(event){
  65. if (event.ctrlKey && event.keyCode === 81){
  66. if(confirm('Will add "notranslate" to some elements on his page. Continue?')){
  67. run();
  68. console.log('finish');
  69. }
  70. }
  71. });
  72. });
  73. }
  74. main();
  75. })();