Disable LaTeX Rendering - Keep Raw LaTeX

Disable LaTeX rendering but keep the raw LaTeX code visible (no MathJax, no KaTeX)

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

  1. // ==UserScript==
  2. // @name Disable LaTeX Rendering - Keep Raw LaTeX
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.4
  5. // @description Disable LaTeX rendering but keep the raw LaTeX code visible (no MathJax, no KaTeX)
  6. // @author You
  7. // @match *://*/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // Function to disable LaTeX rendering
  15. function disableLatexRendering() {
  16. // Find all elements containing LaTeX formulas, e.g., elements with class names like 'mathjax' or 'katex'
  17. const latexElements = document.querySelectorAll('script[src*="mathjax"], script[src*="katex"], span, div, p, img');
  18.  
  19. latexElements.forEach(element => {
  20. // Check if the element contains LaTeX code (looks like \[ ... \] or \( ... \))
  21. if (element.innerHTML && (element.innerHTML.match(/\\\[(.*?)\\\]/) || element.innerHTML.match(/\\\((.*?)\\\)/))) {
  22. // Replace the LaTeX content with its raw version, preventing rendering
  23. element.innerHTML = element.innerText;
  24. }
  25. });
  26.  
  27. // If MathJax or KaTeX is present, disable it
  28. if (window.MathJax) {
  29. window.MathJax.Hub.Config({
  30. showMathMenu: false, // Disable MathJax menu
  31. skipStartupTypeset: true, // Skip initial render
  32. });
  33. }
  34.  
  35. // Prevent KaTeX from rendering
  36. if (window.katex) {
  37. window.katex.render = function() {}; // Override KaTeX rendering function
  38. }
  39. }
  40.  
  41. // Run the function when the document is fully loaded
  42. window.addEventListener('load', function() {
  43. disableLatexRendering();
  44. });
  45.  
  46. // Continuously check for new LaTeX content if the page is dynamic (AJAX)
  47. setInterval(disableLatexRendering, 1000);
  48. })();