DoNotTranslateCode

浏览器翻译时排除代码片段

目前为 2022-01-18 提交的版本。查看 最新版本

// ==UserScript==
// @name         DoNotTranslateCode
// @version      0.1
// @description  浏览器翻译时排除代码片段
// @match        *://**/*
// @license      MIT
// @namespace https://greasyfork.org/users/866136
// ==/UserScript==

(function() {
    'use strict';
    window.addEventListener('load', function() {
        noTranslate(document.getElementsByTagName('pre'));
        noTranslate(document.getElementsByTagName('code'));
        noTranslate(document.getElementsByClassName('gist'));
        noTranslate(document.getElementsByClassName('CodeMirror-code'));
    }, false);
    function noTranslate(items) {
        if(items && items.length > 0) {
            for(var i = 0; i < items.length; i++) {
                items[i].classList.add('notranslate');
            }
        }
    }
})();