Native MathML for Wikipedia

Use MathML on Wikipedia.

  1. // ==UserScript==
  2. // @name Native MathML for Wikipedia
  3. // @namespace Violentmonkey Scripts
  4. // @description Use MathML on Wikipedia.
  5. //// http:
  6. // @include http://*wiki*
  7. // @include http://wikipedia.org/*
  8. // @include http://*.wikipedia.org/*
  9. // @include http://wiktionary.org/*
  10. // @include http://*.wiktionary.org/*
  11. // @include http://*/wiki/*
  12. //// https:
  13. // @include https://*wiki*
  14. // @include https://wikipedia.org/*
  15. // @include https://*.wikipedia.org/*
  16. // @include https://wiktionary.org/*
  17. // @include https://*.wiktionary.org/*
  18. // @include https://*/wiki/*
  19. // @version 0.1
  20. // @author loikein
  21. // @license MPL-2.0
  22. // ==/UserScript==
  23. // Adapted from: https://github.com/fred-wang/webextension-native-mathml/tree/master
  24.  
  25. /* This Source Code Form is subject to the terms of the Mozilla Public
  26. * License, v. 2.0. If a copy of the MPL was not distributed with this
  27. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  28.  
  29. let menuConfig = "renderer:NativeMML"; // Force the native MathML output.
  30. menuConfig += "&;semantics:true"; // Preserve semantics annotations.
  31. menuConfig += "&;context:Browser"; // Force the browser context menu.
  32. menuConfig += "&;zoom:None"; // Disable MathJax's zoom.
  33.  
  34. // Create a mjx.menu cookie for this document to modify the menu option.
  35. document.cookie = `mjx.menu=${escape(menuConfig)}; path=/; SameSite=Strict`;
  36.  
  37. // Delete the cookie before leaving the page.
  38. window.addEventListener("unload", () => {
  39. document.cookie = "mjx.menu=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT; SameSite=Strict";
  40. });
  41.  
  42. /**
  43. * https://stackoverflow.com/a/15506705/10668706
  44. * Utility function to add CSS in multiple passes.
  45. * @param {string} styleString
  46. */
  47. function addStyle(styleString) {
  48. const style = document.createElement('style');
  49. style.textContent = styleString;
  50. document.head.append(style);
  51. }
  52.  
  53. addStyle(`
  54. .mwe-math-mathml-a11y {
  55. clip: auto !important;
  56. overflow: visible !important;
  57. position: static !important;
  58. width: auto !important;
  59. height: auto !important;
  60. opacity: 1 !important;
  61. display: inherit !important;
  62. }
  63. body.mediawiki .ve-ce-mwLatexNode .mwe-math-mathml-a11y {
  64. /* override https://phabricator.wikimedia.org/diffusion/EMAT/browse/master/modules/ve-math/ve.ce.MWLatexNode.css */
  65. display: inherit !important;
  66. }
  67. /* Support where MediaWiki lazy loaded images */
  68. .mwe-math-mathml-inline ~ .lazy-image-placeholder,
  69. .mwe-math-mathml-display ~ .lazy-image-placeholder,
  70. /* Support where MediaWiki doesn't lazy load images */
  71. .mwe-math-mathml-inline + .mwe-math-fallback-image-inline,
  72. .mwe-math-mathml-display + .mwe-math-fallback-image-display {
  73. display: none !important;
  74. }
  75. `);

QingJ © 2025

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