Greasy Fork

Greasy Fork is available in English.

公式翻译保留

网页翻译时,保留公式

当前为 2023-06-04 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         公式翻译保留
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  网页翻译时,保留公式
// @author       GShang
// @require      http://cdn.staticfile.org/jquery/1.8.3/jquery.min.js

// @grant        GM_getResourceURL
// @grant        unsafeWindow
// @grant        GM_setClipboard
// @include      https://www.sciencedirect.com/*
// @include      https://ieeexplore.ieee.org/*
// @include      https://link.springer.com/*
// @grant        GM_getResourceURL
// @grant        GM_xmlhttpRequest
// @grant        GM_getResourceText
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_download
// @grant        GM_addStyle
// @grant        GM_openInTab
// @noframes     Edge
// @compatible   Chrome
// @compatible   Firefox
// @compatible   Edge
// @compatible   Safari
// @compatible   Opera
// @compatible   UC
// @license      GPL3 license
// ==/UserScript==

(function() {
    'use strict';


    // 带有公式的元素
    const mathElement ='math, .math, .MathJax';

    // 添加按钮
    var mathBtn = '<button id="math-btn">公式翻译保留</button>';
    $('body').append(mathBtn);

    // 添加样式
    GM_addStyle('#math-btn {background:#ff3500;padding:10px 20px;color:#fff;border-radius:40px 0 0 40px;position:fixed;right:0px;top:50vh;z-index:99999999999999;border:none;height:fit-content;outline:none;cursor:grab}');

    // 点击按钮,添加翻译保留属性
    $('#math-btn').click(function(){
        if($(mathElement).length > 0){
            // console.log('该页面存在公式!');
            // alert('该页面存在公式!');
            $(mathElement).attr('translate','no');
            alert('公式已被保留!');
        }else{
            console.log('未发现公式!');
            alert('未发现公式!');
        }
    })

    // Your code here...
})();