StackOverflow code标签替换

替换<code>为<strong>,使chrome的翻译拆分效果更好。否则code会截断一整个句子的翻译。

  1. // ==UserScript==
  2. // @name StackOverflow code标签替换
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-03-101
  5. // @description 替换<code>为<strong>,使chrome的翻译拆分效果更好。否则code会截断一整个句子的翻译。
  6. // @author You
  7. // @match https://stackoverflow.com/questions/*
  8. // @match https://*.stackexchange.com/questions/*
  9. // @match https://developer.mozilla.org/en-US/*
  10. // @match https://pypi.org/project/*
  11. // @match https://*.github.com/*
  12. // @match https://askubuntu.com/*
  13. // @match https://superuser.com/*
  14. // @match https://serverfault.com/*
  15. // @match https://scikit-learn.org/*
  16. // @match https://access.redhat.com/*
  17. // @match https://www.smashingmagazine.com/*
  18. // @match https://docs.npmjs.com/cli/v8/commands/*
  19. // @match https://highway-env.readthedocs.io/*
  20. // @match https://router.vuejs.org/*
  21. // @match https://farama-foundation.github.io/*
  22. // @match https://developer.chrome.com/*
  23. // @match https://git-scm.com/docs/*
  24.  
  25. // @icon https://www.google.com/s2/favicons?sz=64&domain=stackoverflow.com
  26. // @grant none
  27. // @license LGPLv3
  28. // ==/UserScript==
  29.  
  30.  
  31. let consoleButton = document.createElement('button');
  32. consoleButton.textContent = '替换code标签';
  33.  
  34.  
  35. consoleButton.style.position = 'fixed';
  36. consoleButton.style.top = '30px';
  37. consoleButton.style.right = '30px';
  38. consoleButton.style.zIndex = '9999';
  39.  
  40.  
  41. consoleButton.addEventListener('click', function () {
  42. replaceCode()
  43. });
  44.  
  45. document.body.appendChild(consoleButton);
  46.  
  47. function replaceCode() {
  48. let hh = document.querySelector("body").innerHTML
  49. // hh = hh.replace(/<code style="user-select: text;">(.*?)<\/code>/g, "<strong style=\"user-select: text;\">$1</strong>")
  50. // hh = hh.replace(/<code class="notranslate" style="user-select: text;">(.*?)<\/code>/g, "<strong style=\"user-select: text;\">$1</strong>")
  51. // hh = hh.replace(/<code class="docutils literal notranslate" style="user-select: text;">(.*?)<\/code>/g, "<strong style=\"user-select: text;\">$1</strong>")
  52. // hh = hh.replace(/<code .+?>(.*?)<\/code>/g, "<strong style=\"user-select: text;\">$1</strong>")
  53. hh = hh.replace(/<code.*?>(.*?)<\/code>/g, "<strong style=\"user-select: text;\">$1</strong>")
  54.  
  55. document.querySelector("body").innerHTML = hh
  56. }

QingJ © 2025

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