双击复制知乎/wiki中的数学公式tex

双击latex公式将其复制到剪切板

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         双击复制知乎/wiki中的数学公式tex
// @homepageURL  https://github.com/Lysanleo/little-piece-crisps
// @namespace    http://tampermonkey.net/
// @version      0.1
// @license      GPLv3
// @description  双击latex公式将其复制到剪切板
// @author       Lysanleo
// @match        *://*.wikipedia.org/*
// @match        *://*.wikipedia.org/*
// @match        *://*.zhihu.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=wikipedia.org
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function getAttributeName(url) {
        if (url.includes('wikipedia.org')) {
            return 'alt';
        } else if (url.includes('zhihu.com')) {
            return 'data-tex';
        }
        // Add more conditions for other websites here
    }

    function addDoubleClickHandler() {
        const attribute = getAttributeName(window.location.href);

        if (!attribute) return;

        document.querySelectorAll(`[${attribute}]`).forEach(e => e.ondblclick = () => navigator.clipboard.writeText(e.getAttribute(attribute)));
    }

    // Add event listener for when the page is loaded or changed
    document.addEventListener('DOMContentLoaded', addDoubleClickHandler);
    new MutationObserver(addDoubleClickHandler).observe(document.documentElement, {childList: true, subtree: true});
})();