Disable LaTeX rendering and keep raw LaTeX code visible
当前为
// ==UserScript==
// @name Disable LaTeX Rendering
// @namespace http://tampermonkey.net/
// @version 0.2
// @description Disable LaTeX rendering and keep raw LaTeX code visible
// @author You
// @match *://*/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Define the function to keep raw LaTeX code
function disableLatexRendering() {
// Find elements containing LaTeX code, such as those within <script> tags or classes like mathjax, KaTeX, etc.
// Remove any rendering libraries like MathJax or KaTeX
const scripts = document.querySelectorAll('script[src*="mathjax"], script[src*="katex"]');
scripts.forEach(script => script.remove());
// Find all LaTeX elements and convert them back to raw code (replacing the rendered parts with their raw LaTeX)
const latexElements = document.querySelectorAll('span, div, p, img');
latexElements.forEach(element => {
if (element.innerHTML && element.innerHTML.match(/(?:\\\[.*\\\]|\\\(.*\\\))/)) {
// Replace any rendered LaTeX back to the raw LaTeX text
element.innerHTML = element.innerText;
}
});
}
// Run the function when the document is fully loaded
window.addEventListener('load', function() {
disableLatexRendering();
});
})();