notranslate-防止chrome翻译代码段和公式

A tampermonkey script aims to prevent unnecessary translation of code segment and math equations.

Versión del día 26/03/2020. Echa un vistazo a la versión más reciente.

Tendrás que instalar una extensión para tu navegador como Tampermonkey, Greasemonkey o Violentmonkey si quieres utilizar este script.

Necesitarás instalar una extensión como Tampermonkey o Violentmonkey para instalar este script.

Necesitarás instalar una extensión como Tampermonkey o Violentmonkey para instalar este script.

Necesitarás instalar una extensión como Tampermonkey o Userscripts para instalar este script.

Necesitará instalar una extensión como Tampermonkey para instalar este script.

Necesitarás instalar una extensión para administrar scripts de usuario si quieres instalar este script.

(Ya tengo un administrador de scripts de usuario, déjame instalarlo)

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

(Ya tengo un administrador de estilos de usuario, déjame instalarlo)

// ==UserScript==
// @name         notranslate-防止chrome翻译代码段和公式
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  A tampermonkey script aims to prevent unnecessary translation of code segment and math equations.
// @author       winding
// @supportURL   https://github.com/windingwind/notranslate/blob/master/README.md
// @include      *
// @require      http://code.jquery.com/jquery-3.4.1.min.js
// @grant        GM_setValue
// @grant        GM_getValue
// ==/UserScript==

(function() {
    'use strict';
    /* You can add your settings here.
       "type" can be "id", "class", or "element".
       "param" is how you  trace the target element.
    */
    const behaviorList = [
        {
            'type':'class',
            'param':'prettyprint',
        },
        {
            'type':'class',
            'param':'mjx-chtml',
        },
        {
            'type':'class',
            'param':'MathJax_Display',
        },
        {
            'type':'class',
            'param':'katex--display',
        },
        {
            'type':'class',
            'param':'syntaxhighlighter',
        },
    ];
    function addNotranslate (selector, loop, interval) {
        $(selector).attr("class", function(i,origValue){
            return origValue + " notranslate";
        });
    }
    function run () {
        console.log($);
        for(let i = 0; i < behaviorList.length; i++) {
            //console.log(behaviorList[i]);
            let selector = '';
            switch (behaviorList[i].type){
                case 'class':
                    selector = "."+behaviorList[i].param;
                    break;
                case 'id':
                    selector = "#"+behaviorList[i].param;
                    break;
                case 'element':
                    selector = behaviorList[i].param;
                    break;
            }
            addNotranslate(selector, behaviorList[i].loop, behaviorList[i].interval);
        }
    }
    function main(){
        $(function(){
            $("body").keyup(function(event){
                if (event.ctrlKey && event.keyCode === 81){
                    if(confirm('Will add "notranslate" to some elements on his page. Continue?')){
                        run();
                        console.log('finish');
                    }
                }
            });
        });
    }
    main();
})();// ==UserScript==
// @name         notranslate-防止chrome翻译代码段和公式
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  A tampermonkey script aims to prevent unnecessary translation of code segment and math equations.
// @author       winding
// @supportURL   https://github.com/windingwind/notranslate/blob/master/README.md
// @include      *
// @require      http://code.jquery.com/jquery-3.4.1.min.js
// @grant        GM_setValue
// @grant        GM_getValue
// ==/UserScript==

(function() {
    'use strict';
    /* You can add your settings here.
       "type" can be "id", "class", or "element".
       "param" is how you  trace the target element.
    */
    const behaviorList = [
        {
            'type':'class',
            'param':'prettyprint',
        },
        {
            'type':'class',
            'param':'mjx-chtml',
        },
        {
            'type':'class',
            'param':'MathJax_Display',
        },
        {
            'type':'class',
            'param':'katex--display',
        },
        {
            'type':'class',
            'param':'syntaxhighlighter',
        },
    ];
    function addNotranslate (selector, loop, interval) {
        $(selector).attr("class", function(i,origValue){
            return origValue + " notranslate";
        });
    }
    function run () {
        console.log($);
        for(let i = 0; i < behaviorList.length; i++) {
            //console.log(behaviorList[i]);
            let selector = '';
            switch (behaviorList[i].type){
                case 'class':
                    selector = "."+behaviorList[i].param;
                    break;
                case 'id':
                    selector = "#"+behaviorList[i].param;
                    break;
                case 'element':
                    selector = behaviorList[i].param;
                    break;
            }
            addNotranslate(selector, behaviorList[i].loop, behaviorList[i].interval);
        }
    }
    function main(){
        $(function(){
            $("body").keyup(function(event){
                if (event.ctrlKey && event.keyCode === 81){
                    if(confirm('Will add "notranslate" to some elements on his page. Continue?')){
                        run();
                        console.log('finish');
                    }
                }
            });
        });
    }
    main();
})();