Disable LaTeX rendering but keep the raw LaTeX code visible (no MathJax, no KaTeX)
当前为
// ==UserScript==
// @name Disable LaTeX Rendering - Keep Raw LaTeX
// @namespace http://tampermonkey.net/
// @version 0.4
// @description Disable LaTeX rendering but keep the raw LaTeX code visible (no MathJax, no KaTeX)
// @author You
// @match *://*/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Function to disable LaTeX rendering
function disableLatexRendering() {
// Find all elements containing LaTeX formulas, e.g., elements with class names like 'mathjax' or 'katex'
const latexElements = document.querySelectorAll('script[src*="mathjax"], script[src*="katex"], span, div, p, img');
latexElements.forEach(element => {
// Check if the element contains LaTeX code (looks like \[ ... \] or \( ... \))
if (element.innerHTML && (element.innerHTML.match(/\\\[(.*?)\\\]/) || element.innerHTML.match(/\\\((.*?)\\\)/))) {
// Replace the LaTeX content with its raw version, preventing rendering
element.innerHTML = element.innerText;
}
});
// If MathJax or KaTeX is present, disable it
if (window.MathJax) {
window.MathJax.Hub.Config({
showMathMenu: false, // Disable MathJax menu
skipStartupTypeset: true, // Skip initial render
});
}
// Prevent KaTeX from rendering
if (window.katex) {
window.katex.render = function() {}; // Override KaTeX rendering function
}
}
// Run the function when the document is fully loaded
window.addEventListener('load', function() {
disableLatexRendering();
});
// Continuously check for new LaTeX content if the page is dynamic (AJAX)
setInterval(disableLatexRendering, 1000);
})();