Greasy Fork

Greasy Fork is available in English.

让谷歌浏览器不翻译代码和公式

For Google Translate, you can customize and specify tags and keywords without translating

当前为 2025-01-25 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Make Chrome not Translate Code
// @name:zh-CN   让谷歌浏览器不翻译代码和公式
// @name:en      Make Chrome not Translate Code
// @description  For Google Translate, you can customize and specify tags and keywords without translating
// @author       @amormaid
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description:zh-cn 针对谷歌翻译,可以自定义指定标签、关键词不翻译
// @description:en  For Google Translate, you can customize and specify tags and keywords without translating
// @match        *://*/*
// @license      GPL
// @grant        none
// ==/UserScript==




(function () {
    'use strict'
    const commonWords = []; //适配所有网页的通用不翻译关键词  Universal untranslated keywords for all web pages
    const filterList = [
        {
            //Customize the target site of the translation configuration. be careful! Before adding a new target page configuration, please add the matching of the target page in the script header
            'website': 'spring.io', //自定义翻译配置的目标网站。注意!添加新目标网页配置前,请在脚本头部添加目标网页的匹配,参考// @match *://github.com/*
            'notranslate': {
                'classes': ['sidebar', 'sidebar_children'],  //特定class属性标签不翻译  Specific class attribute labels are not translated
                'ids': [],  //特定id标签不翻译  No translation of specific id tags
                'elements': [],  //特定标签不翻译
                'words': ['Spring Data REST'],  //目标网页下不翻译的关键词 Keyword not translated under the target page
            }
        },
        {
            'website': 'github.com',
            'notranslate': {
                'classes': ['file-navigation', 'flex-wrap', 'js-navigation-open', 'BorderGrid-cell', 'filter-list', 'mr-31', 'topic-tag', 'v-align-middle', 'js-navigation-open',],
                'ids': [],
                'elements': ['pre'],
                'words': [],
            }
        },
        {
            'website': 'www.elastic.co',
            'notranslate': {
                'classes': ['programlisting'],
                'ids': [],
                'elements': [],
                'words': [],
            }
        },
    ]


    function addNotranlate(filterArrray, type) {
        for (let index in filterArrray) {
            console.log(filterArrray)
            let selector;
            if (type === 'classes') {
                selector = '.' + filterArrray[index]
            } else if (type === 'ids') {
                selector = '#' + filterArrray[index]
            } else if (type === 'elements') {
                selector = filterArrray[index]
            } else if (type === 'words') {
                var reg=new RegExp(filterArrray[index],"gi");
                document.body.innerHTML = document.body.innerHTML.replace(reg, '<span class="notranslate">' + filterArrray[index] + '</span>');
                continue;
            }
            const list = document.querySelector(selector)
            list && list.length && Array.from(list).forEach(e => e.classList.add('notranslate'));
            list && list.length && Array.from(list).forEach(e => e.setAttribute('translate', 'no'));
            // $(selector).addClass('cyxy-no-trs'); //对彩云小译的支持  Support for another translation plug-in
        }
    }

    function main() {
        for (let i = 0; i < filterList.length; i++) {
            const web = filterList[i];
            if (web.website !== window.location.host) {
                continue;
            }
            var notranslate = web.notranslate;
            if (notranslate.classes !== null) {
                addNotranlate(notranslate.classes, 'classes');
            }
            if (notranslate.ids !== null) {
                addNotranlate(notranslate.ids, 'ids');
            }
            if (notranslate.elements !== null) {
                addNotranlate(notranslate.elements, 'elements');
            }
            if (notranslate.words !== null) {
                addNotranlate(notranslate.words, 'words');
            }
        }
        if (commonWords.length > 0) {
            addNotranlate(commonWords, 'words');
        }
        const list = document.querySelector("math")
        list && list.length && Array.from(list).forEach(e => e.classList.add('notranslate'));
        list && list.length && Array.from(list).forEach(e => e.setAttribute('translate', 'no'));
    }


    main();
})();