Skip to content

Instantly share code, notes, and snippets.

@myesn
Forked from abel533/notranslate.user.js
Created August 6, 2021 13:42
Show Gist options
  • Save myesn/7eee3030727de9c0bf3e7b6e4870c36d to your computer and use it in GitHub Desktop.
Save myesn/7eee3030727de9c0bf3e7b6e4870c36d to your computer and use it in GitHub Desktop.
浏览器翻译时排除代码片段
// ==UserScript==
// @name notranslate
// @namespace https://gist.github.com/abel533/5839d3eca4686646baba113fc47e9b22
// @version 1.0
// @description 浏览器翻译时排除代码片段
// @author isea533
// @match *://**/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
window.addEventListener('load', function() {
noTranslate(document.getElementsByTagName('pre'));
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');
}
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment