// ==UserScript== // @name Copy ChatGPT KaTeX Formula to Markdown // @namespace http://github.com/PluginsKers // @version 1.4.1 // @description Add a copy interaction to KaTeX formulas to copy them as Markdown LaTeX format, with enhanced user interaction and dynamic color scheme support // @author PluginsKers // @match https://chat.openai.com/* // @match https://chatgpt.com/* // @license MIT // @grant none // @downloadURL https://update.greasyfork.org/scripts/501013/Copy%20ChatGPT%20KaTeX%20Formula%20to%20Markdown.user.js // @updateURL https://update.greasyfork.org/scripts/501013/Copy%20ChatGPT%20KaTeX%20Formula%20to%20Markdown.meta.js // ==/UserScript==
// Initial style update based on current color scheme const initialColorScheme = document.documentElement.style.getPropertyValue('color-scheme') || 'light'; updateStyles(initialColorScheme);
// Function to add copy interaction to a single KaTeX element functionaddCopyInteraction(katexElement) { if (katexElement.classList.contains('copy-interaction-added')) return;
// Function to add copy interactions to all KaTeX elements functionaddCopyInteractions() { document.querySelectorAll('div.markdown .katex').forEach(addCopyInteraction); }
// Function to monitor for new elements functionmonitorNewElements() { const observer = newMutationObserver(() => { if (!document.querySelector('.result-streaming')) { addCopyInteractions(); } }); observer.observe(document.body, { childList: true, subtree: true }); }