Better Mathjax For 124OJ

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

  1. // ==UserScript==
  2. // @name Better Mathjax For 124OJ
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1.2
  5. // @description 强制加载新的 MathJax CDN 确保公式正确渲染
  6. // @author GGapa
  7. // @match *://124.221.194.184/*
  8. // @license MIT
  9. // @grant none
  10. // @icon https://ex124oj.pond.ink/images/icon.png
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. const newCDN = 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js';
  17.  
  18. function forceLoadMathJax() {
  19. console.log('强制替换 MathJax CDN...');
  20.  
  21. // 删除页面上所有旧的 MathJax 脚本
  22. document.querySelectorAll('script[src*="MathJax"]').forEach(script => script.remove());
  23.  
  24. // 添加新的 MathJax 脚本
  25. const script = document.createElement('script');
  26. script.src = newCDN;
  27. script.async = true;
  28.  
  29. // 配置 MathJax
  30. window.MathJax = {
  31. tex: {
  32. inlineMath: [['$', '$'], ['\\(', '\\)']],
  33. displayMath: [['$$', '$$'], ['\\[', '\\]']]
  34. },
  35. options: {
  36. skipHtmlTags: ['script', 'noscript', 'style', 'textarea', 'pre'],
  37. processEscapes: true
  38. },
  39. startup: {
  40. ready: () => {
  41. console.log('MathJax 已加载');
  42. MathJax.startup.defaultReady();
  43. MathJax.typesetPromise().then(() => {
  44. console.log('公式已成功渲染');
  45. }).catch(err => console.error('渲染出错:', err));
  46. }
  47. }
  48. };
  49.  
  50. document.head.appendChild(script);
  51. }
  52.  
  53. // 强制加载新的 MathJax,无论是否已有加载
  54. forceLoadMathJax();
  55. })();