您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
为网页添加MathJax支持,优化性能
当前为
// ==UserScript== // @name MathJax Support // @namespace http://tampermonkey.net/ // @version 0.4 // @description 为网页添加MathJax支持,优化性能 // @author Snowballl11 // @license MIT // @match *://*/* // @grant none // @run-at document-idle // ==/UserScript== (function() { 'use strict'; // 检查页面是否已经加载了MathJax if (window.MathJax) { console.log('MathJax已经存在,嘎!'); return; } // 创建MathJax配置 window.MathJax = { tex: { inlineMath: [['$', '$'], ['\\(', '\\)']], displayMath: [['$$', '$$'], ['\\[', '\\]']], processEscapes: true }, options: { skipHtmlTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code'] } }; // 创建并插入MathJax脚本 var script = document.createElement('script'); script.src = 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js'; script.async = true; document.head.appendChild(script); // 添加一个MathJax加载完成的回调 script.onload = function() { console.log('MathJax加载完成,嘎!'); // 使用防抖函数来限制typeset的调用频率 var debounceTypeset = debounce(function() { if (typeof MathJax !== 'undefined') { MathJax.typeset(); } }, 1000); // 创建一个MutationObserver来监视特定元素的变化 var observer = new MutationObserver(function(mutations) { debounceTypeset(); }); // 配置observer,只观察子节点的变化 var config = { childList: true, subtree: true }; // 尝试找到文章内容的容器元素,这里假设它有一个特定的ID或类名 var contentContainer = document.querySelector('#article-content') || document.querySelector('.post-content'); if (contentContainer) { observer.observe(contentContainer, config); } else { console.log('未找到文章容器,改为观察整个body,嘎!'); observer.observe(document.body, config); } }; // 防抖函数 function debounce(func, wait) { var timeout; return function() { var context = this, args = arguments; clearTimeout(timeout); timeout = setTimeout(function() { func.apply(context, args); }, wait); }; } })(); /* MIT License Copyright (c) [2024] [Snowballl11] Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */