Greasy Fork is available in English.

公式翻译保留

网页翻译时,保留公式

< Feedback on 公式翻译保留

Review: Good - script works

§
Posted: 2022-11-25
  1. 因为 按钮太长 占地方,因此建议改成一个中文或两个英文字母。
  2. alert反馈机制不好,影响阅读体验。因此建议改成颜色反馈。

我修改的代码如下

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

// @grant        GM_getResourceURL
// @grant        unsafeWindow
// @grant        GM_setClipboard
// @match        https://www.sciencedirect.com/*
// @match        https://ieeexplore.ieee.org/*
// @match        https://link.springer.com/*
// @match        https://pubs.geoscienceworld.org/*
// @match        https://pubs.rsc.org/en/content/articlehtml/2019/en/c9en00017h

// @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:3px 5px;color:#fff;border-radius:10px 0 0 10px;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');
            $("#math-btn").css("background","green");
        }else{
            //console.log('未发现公式!');
            $("#math-btn").css("background","red");
        }
    })

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

ZhouDuuAuthor
§
Posted: 2023-06-04

好的十分感谢

Post reply

Sign in to post a reply.