您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
自动渲染 OpenAI 的 ChatGPT 页面上的 LaTeX 数学公式。
当前为
- // ==UserScript==
- // @name OpenAI-ChatGPT LaTeX Auto Render (with MathJax V2)
- // @namespace http://tampermonkey.net/
- // @version 0.2.2
- // @author Scruel (https://github.com/scruel)
- // @description Auto typeset LaTeX math formulas on OpenAI ChatGPT page.
- // @description:zh-CN 自动渲染 OpenAI 的 ChatGPT 页面上的 LaTeX 数学公式。
- // @match https://chat.openai.com/chat
- // @grant none
- // ==/UserScript==
- 'use strict';
- async function addScript(url) {
- const scriptElement = document.createElement('script');
- scriptElement.src = url;
- scriptElement.async = true;
- const headElement = document.getElementsByTagName('head')[0] || document.documentElement;
- headElement.insertBefore(scriptElement , headElement.firstChild);
- await waitScriptLoaded();
- }
- function waitScriptLoaded() {
- return new Promise(async (resolve, reject) => {
- const resolver = () => {
- if (MathJax.hasOwnProperty('Hub')) {
- resolve();
- return;
- }
- // console.log("Loading...")
- window.setTimeout(resolver, 200);
- }
- resolver();
- });
- }
- function renderTrigger() {
- setTimeout(renderLatex, window.renderDelay);
- }
- function renderLatex() {
- const submitButton = document.querySelector('main form textarea+button');
- // console.log(submitButton)
- if (submitButton && !submitButton.disabled) {
- // console.log("Rendering...")
- MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
- }
- renderTrigger();
- }
- (async function() {
- window.MathJax = {
- tex2jax: {
- inlineMath: [['$', '$']],
- displayMath : [['$$', '$$']]
- },
- CommonHTML: { linebreaks: { automatic: true } },
- "HTML-CSS": { linebreaks: { automatic: true } },
- SVG: { linebreaks: { automatic: true } }
- };
- await addScript('https://cdn.jsdelivr.net/npm/mathjax@2/MathJax.js?config=TeX-AMS_CHTML');
- window.renderDelay = 1000;
- renderTrigger();
- })();