Disable LaTeX Rendering Completely3

Completely disable LaTeX rendering (MathJax, KaTeX, etc.)

目前为 2025-02-14 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Disable LaTeX Rendering Completely3
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description Completely disable LaTeX rendering (MathJax, KaTeX, etc.)
  6. // @author You
  7. // @match *://*/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // Function to disable LaTeX rendering (remove MathJax, KaTeX scripts, and prevent any rendering)
  15. function disableLatexRendering() {
  16. // Remove any LaTeX rendering scripts like MathJax or KaTeX
  17. const scripts = document.querySelectorAll('script[src*="mathjax"], script[src*="katex"], script[type="math/tex"]');
  18. scripts.forEach(script => script.remove());
  19.  
  20. // Remove elements that might be rendering LaTeX as images or HTML
  21. const latexElements = document.querySelectorAll('span, div, p, img');
  22. latexElements.forEach(element => {
  23. if (element.innerHTML && element.innerHTML.match(/(?:\\\[.*\\\]|\\\(.*\\\))/)) {
  24. // If the element contains LaTeX, change its inner HTML to raw LaTeX code
  25. element.innerHTML = element.innerText;
  26. }
  27. });
  28.  
  29. // Make sure no LaTeX is being auto-rendered by MathJax/KaTeX
  30. const mathJaxVars = ['MathJax', 'katex'];
  31. mathJaxVars.forEach(varName => {
  32. if (window[varName]) {
  33. window[varName] = undefined;
  34. }
  35. });
  36. }
  37.  
  38. // Run the function when the document is fully loaded
  39. window.addEventListener('load', function() {
  40. disableLatexRendering();
  41. });
  42.  
  43. // Also run the function periodically to handle dynamic content (e.g., AJAX updates)
  44. setInterval(disableLatexRendering, 1000);
  45. })();
  46.