一键复制公式

Click to copy equation in Wikipedia

目前为 2020-03-11 提交的版本。查看 最新版本

// ==UserScript==
// @name         一键复制公式
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Click to copy equation in Wikipedia
// @author       flaribbit
// @match        http://*.wikipedia.org/*
// @match        https://*.wikipedia.org/*
// @match        https://www.zhihu.com/question/*
// @match        https://zhuanlan.zhihu.com/p/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    // Your code here...
    window.tempbox=document.createElement("input");
    document.body.appendChild(window.tempbox);
    let host=document.location.host;
    if(host.search('wikipedia')>0){
        let copyTex=function(){
            window.tempbox.value='$'+this.alt+'$';
            window.tempbox.select();
            document.execCommand('copy');
        }
        let eqs=document.getElementsByClassName("mwe-math-fallback-image-inline");
        for(let i=0;i<eqs.length;i++){
            eqs[i].onclick=copyTex;
            eqs[i].title='点击即可复制公式';
        }
    }else if(host.search('zhihu')>0){
        let copyTex=function(){
            window.tempbox.value='$'+this.getAttribute("data-formula")+'$';
            window.tempbox.select();
            document.execCommand('copy');
        }
        let imgs=document.getElementsByTagName("img");
        for(let i=0;i<imgs.length;i++){
            if(imgs[i].alt){
                imgs[i].onclick=copyTex;
                imgs[i].title='点击即可复制公式';
            }
        }
    }
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址