Disable LaTeX on Discourse

Prevent LaTeX rendering on Discourse forums

Stan na 15-07-2025. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Disable LaTeX on Discourse
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Prevent LaTeX rendering on Discourse forums
// @match        *://*/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // Helper to override MathJax and KaTeX render functions
    function blockRenderers() {
        if (window.MathJax) {
            console.log("[Tampermonkey] Blocking MathJax...");
            window.MathJax = {
                typeset: function() {},
                typesetPromise: function() { return Promise.resolve(); },
                startup: { promise: Promise.resolve() },
                config: {}
            };
        }

        if (window.katex) {
            console.log("[Tampermonkey] Blocking KaTeX...");
            window.katex = {
                render: function() {},
                renderToString: function() { return ''; }
            };
        }
    }

    // Observe new script tags that try to load MathJax or KaTeX
    const observer = new MutationObserver((mutations) => {
        for (let mutation of mutations) {
            for (let node of mutation.addedNodes) {
                if (node.tagName === 'SCRIPT' && node.src &&
                    (node.src.includes('MathJax') || node.src.includes('katex'))) {
                    console.log("[Tampermonkey] Blocking script:", node.src);
                    node.type = 'javascript/blocked';
                    node.parentNode.removeChild(node);
                }
            }
        }
    });

    observer.observe(document.documentElement, {
        childList: true,
        subtree: true
    });

    // Run blocker early and often
    blockRenderers();
    setInterval(blockRenderers, 1000); // Re-block in case the page tries to reload them
})();