谷歌翻译绕过代码块

让谷歌翻译插件翻译网页的时候,绕过代码块和一些无需翻译的元素

  1. // ==UserScript==
  2. // @name 谷歌翻译绕过代码块
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.4
  5. // @description 让谷歌翻译插件翻译网页的时候,绕过代码块和一些无需翻译的元素
  6. // @author xiandan
  7. // @homeurl https://github.com/xiandanin/LardMonkeyScripts
  8. // @homeurl https://gf.qytechs.cn/zh-CN/scripts/392357
  9. // @match https://github.com/*
  10. // @match https://npmjs.com/*
  11. // @match https://stackoverflow.com/*
  12. // @match https://*.google.com/*
  13. // @license MIT
  14. // @grant none
  15. // ==/UserScript==
  16. /*jshint esversion: 6 */
  17. (function () {
  18. 'use strict'
  19.  
  20. function noTranslate (array) {
  21. array.forEach((name) => {
  22. [...document.querySelectorAll(name)].forEach(node => {
  23. if (node.className.indexOf('notranslate') === -1) {
  24. node.classList.add('notranslate')
  25. }
  26. })
  27. })
  28. }
  29.  
  30. const bypassSelectorArray = [
  31. 'pre'
  32. ]
  33. if (window.location.hostname.indexOf("github") !== -1) {
  34. // 如果是github 还需要处理一些别的元素
  35. const githubSelector = [
  36. '#repository-container-header > div:nth-child(1)',
  37. 'summary.btn.css-truncate',
  38. '.commit-author',
  39. '.js-navigation-open.link-gray-dark',
  40. '.Box-title',
  41. '.BorderGrid-cell > div.mt-3 > a.Link--muted',
  42. '.BorderGrid-cell > a[data-pjax="#repo-content-pjax-container"] > div > div:first-child',
  43. '.BorderGrid-cell > ul.list-style-none',
  44. 'div[role="rowheader"]'
  45. ]
  46. bypassSelectorArray.push.apply(bypassSelectorArray, githubSelector)
  47.  
  48. //如果还有github的插件 还需要延迟追加一些
  49. setTimeout(function () {
  50. const githubPluginSelector = [
  51. '.github-repo-size-div',
  52. '.octotree-tree-view'
  53. ]
  54. noTranslate(githubPluginSelector)
  55. }, 3000)
  56. }
  57. noTranslate(bypassSelectorArray)
  58. })()

QingJ © 2025

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