Better Mathjax For 124OJ

强制加载新的 MathJax CDN 确保公式正确渲染

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Better Mathjax For 124OJ
// @namespace    http://tampermonkey.net/
// @version      1.1.2
// @description  强制加载新的 MathJax CDN 确保公式正确渲染
// @author       GGapa
// @match        *://124.221.194.184/*
// @license      MIT
// @grant        none
// @icon         https://ex124oj.pond.ink/images/icon.png
// ==/UserScript==

(function() {
    'use strict';

    const newCDN = 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js';

    function forceLoadMathJax() {
        console.log('强制替换 MathJax CDN...');

        // 删除页面上所有旧的 MathJax 脚本
        document.querySelectorAll('script[src*="MathJax"]').forEach(script => script.remove());

        // 添加新的 MathJax 脚本
        const script = document.createElement('script');
        script.src = newCDN;
        script.async = true;

        // 配置 MathJax
        window.MathJax = {
            tex: {
                inlineMath: [['$', '$'], ['\\(', '\\)']],
                displayMath: [['$$', '$$'], ['\\[', '\\]']]
            },
            options: {
                skipHtmlTags: ['script', 'noscript', 'style', 'textarea', 'pre'],
                processEscapes: true
            },
            startup: {
                ready: () => {
                    console.log('MathJax 已加载');
                    MathJax.startup.defaultReady();
                    MathJax.typesetPromise().then(() => {
                        console.log('公式已成功渲染');
                    }).catch(err => console.error('渲染出错:', err));
                }
            }
        };

        document.head.appendChild(script);
    }

    // 强制加载新的 MathJax,无论是否已有加载
    forceLoadMathJax();
})();