-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathtranslation_bypass.js
58 lines (55 loc) · 2.03 KB
/
translation_bypass.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// ==UserScript==
// @name 谷歌翻译绕过代码块
// @namespace http://tampermonkey.net/
// @version 0.4
// @description 让谷歌翻译插件翻译网页的时候,绕过代码块和一些无需翻译的元素
// @author xiandan
// @homeurl https://github.com/xiandanin/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'
function noTranslate (array) {
array.forEach((name) => {
[...document.querySelectorAll(name)].forEach(node => {
if (node.className.indexOf('notranslate') === -1) {
node.classList.add('notranslate')
}
})
})
}
const bypassSelectorArray = [
'pre'
]
if (window.location.hostname.indexOf("github") !== -1) {
// 如果是github 还需要处理一些别的元素
const githubSelector = [
'#repository-container-header > div:nth-child(1)',
'summary.btn.css-truncate',
'.commit-author',
'.js-navigation-open.link-gray-dark',
'.Box-title',
'.BorderGrid-cell > div.mt-3 > a.Link--muted',
'.BorderGrid-cell > a[data-pjax="#repo-content-pjax-container"] > div > div:first-child',
'.BorderGrid-cell > ul.list-style-none',
'div[role="rowheader"]'
]
bypassSelectorArray.push.apply(bypassSelectorArray, githubSelector)
//如果还有github的插件 还需要延迟追加一些
setTimeout(function () {
const githubPluginSelector = [
'.github-repo-size-div',
'.octotree-tree-view'
]
noTranslate(githubPluginSelector)
}, 3000)
}
noTranslate(bypassSelectorArray)
})()