知乎公式复制LaTeX

在知乎中直接复制公式即可得到对应的LaTeX代码

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         知乎公式复制LaTeX
// @namespace    https://jasongzy.com
// @version      1.0
// @description  在知乎中直接复制公式即可得到对应的LaTeX代码
// @author       jasongzy
// @match        https://www.zhihu.com/*
// @match        https://www.zhihu.com/question/*
// @match        https://zhuanlan.zhihu.com/p/*
// @icon         https://www.google.com/s2/favicons?domain=zhihu.com
// @grant        GM_addStyle
// ==/UserScript==

GM_addStyle('.MathJax_Preview ~ .math-holder {font-size:0 !important; display:inline !important;}');
GM_addStyle('span.MJX_Assistive_MathML {display: none !important;}');

function edit_latex() {
    let eqs = document.querySelectorAll(".MathJax_Preview ~ .math-holder");
    // console.log(eqs);
    for (let i = 0; i < eqs.length; i++) {
        if (!eqs[i].textContent.startsWith('$') || !eqs[i].textContent.endsWith('$')) {
            let latex = '$' + eqs[i].textContent + '$';
            eqs[i].textContent = latex;
            // console.log(latex);
        }
    }
}

document.addEventListener('scroll', edit_latex);

(window.onload = function () {
    'use strict';
    setTimeout(function () {
        edit_latex();
    }, 3000);
})