Disable LaTeX Rendering

Disable LaTeX rendering and keep raw LaTeX code visible

目前為 2025-02-14 提交的版本,檢視 最新版本

// ==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();
    });
})();

QingJ © 2025

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