谷歌翻译绕过代码块

让谷歌翻译插件翻译网页的时候绕过代码块和一些无需翻译的元素

当前为 2019-11-14 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         谷歌翻译绕过代码块
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  让谷歌翻译插件翻译网页的时候绕过代码块和一些无需翻译的元素
// @author       denghaha
// @homeurl      https://github.com/dengyuhan/LardMonkeyScripts
// @homeurl      https://greasyfork.org/zh-CN/scripts/392357
// @match        https://github.com/*
// @match        https://npmjs.com/*
// @match        https://stackoverflow.com/*
// @match        https://*.google.com/*
// @license      MIT
// @grant        none
// ==/UserScript==
/*jshint esversion: 6 */
(function () {
    'use strict'

    const bypassSelectorArray = [
        'pre'
    ]
    if (window.location.hostname.indexOf("github")!==-1) {
        // 如果是github 还需要处理一些别的元素
        const githubSelector = ['.pagehead', '.octotree-sidebar', '.repository-topics-container', '.file-navigation', '.Box-title', '.content']
        bypassSelectorArray.push.apply(bypassSelectorArray, githubSelector)
    }

    bypassSelectorArray.forEach((name) => {
        [...document.querySelectorAll(name)].forEach(node => {
            if (node.className.indexOf('notranslate') === -1) {
                node.classList.add('notranslate')
            }
        })
    })
})()