Make Chrome not Translate Code and Formula

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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




(function () {
    'use strict'

    console.log('not translate ready!');
    const root = document.getElementsByTagName('html')[0];
    root.classList.remove('notranslate');
    root.removeAttribute('translate');

    let action_id = undefined
    function setNotTranslate() {
        const list = [
            ...(document.getElementsByTagName("math") || []),
            ...(document.getElementsByTagName("svg") || []),
            ...(document.getElementsByTagName("tex-math") || []),
            ...(document.getElementsByClassName("MathJax"))
        ];
        Array.from(list).forEach(e => e.classList.add('notranslate'));
        Array.from(list).forEach(e => e.setAttribute('translate', 'no'));
        console.log('not translate complete')
    }
    action_id = setTimeout(setNotTranslate, 500);

    const observerOptions = {
        childList: true,
        subtree: true,
    };

    const observer = new MutationObserver((records, observer) => {
        for (const record of records) {
            // console.log('record is ', record.target.tagName )
            if (["math","svg","tex-math"].includes(record.target.tagName.toLowerCase()) || ["MathJax"].some(class_name => record.target.classList.contains(class_name))) {
                action_id && clearTimeout(action_id)
                action_id = setTimeout(setNotTranslate, 500);
            }

        }
    });
    observer.observe(document.body, observerOptions);



})();