您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
禁止谷歌翻译页面上的文件名和代码,在F辣条要甜点的基础上修改
当前为
// ==UserScript== // @name github一些地方禁止翻译 // @namespace http://5jianzhan.com // @author itldg // @version 1.0.0 // @description 禁止谷歌翻译页面上的文件名和代码,在F辣条要甜点的基础上修改 // @author F辣条要甜点 // @include *://github.com* // @include *://flutter.dev* // @match *://github.com* // @match *://www.npmjs.com* // @grant MIT // @license MIT // ==/UserScript== /*jshint esversion: 6 */ (function() { 'use strict'; const addCodeEle = function (ele) {ele.innerHTML = '<code>' + ele.innerHTML + '</code>'} const hasCodeEleChild = function (ele) {return !!ele.querySelector('code')} const _ = {} _.debounce = function (func, wait) { var lastCallTime var lastThis var lastArgs var timerId function startTimer (timerExpired, wait) { return setTimeout(timerExpired, wait) } function remainingWait(time) { const timeSinceLastCall = time - lastCallTime const timeWaiting = wait - timeSinceLastCall return timeWaiting } function shoudInvoking (time) { return lastCallTime !== undefined && (time - lastCallTime >= wait) } function timerExpired () { const time = Date.now() if (shoudInvoking(time)) { return invokeFunc() } timerId = startTimer(timerExpired, remainingWait(time)) } function invokeFunc () { timerId = undefined const args = lastArgs const thisArg = lastThis let result = func.apply(thisArg, args) lastArgs = lastThis = undefined return result } function debounced (...args) { let time = Date.now() lastThis = this lastArgs = args lastCallTime = time if (timerId === undefined) { timerId = startTimer(timerExpired, wait) } } return debounced } let time = 0 const TV = document.querySelector('body') // 监听DOM变更 const MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver const option = { 'childList': true, 'subtree': true } const doNotTranslateCode = function (mutations, observer) { if (time >= 20) { observer.disconnect() observer.takeRecords() time = 0 setTimeout(function() { mo.observe(TV, option) }, 50) } const files = document.querySelectorAll('.file,div[role=rowheader]') let pres = document.querySelectorAll('pre,div[itemprop=text]') let h = [] ;['1','2','3','4','5','6'].forEach((item)=>{ if (!document.querySelectorAll(`h${item}`)) return false h = [...h,...document.querySelectorAll(`h${item}`)] }) pres = [...pres,...h] if (files.length > 0) { if (window.location.href.search(/.md/i) !== -1) { if (pres.length > 0) { pres.forEach(function(pre){if (!hasCodeEleChild(pre)) addCodeEle(pre)}) } } else { files.forEach(function(file){if (!hasCodeEleChild(file)) addCodeEle(file)}) } } if (pres.length > 0) { pres.forEach(function(pre){if (!hasCodeEleChild(pre)) addCodeEle(pre)}) } time++ } const mo = new MutationObserver(_.debounce(doNotTranslateCode, 50)) mo.observe(TV, option) //----------------------------------技术名 // 选择所有ul.list-style-none和其内部li.d-inline元素 const markNoTranslate = function () { const lists = document.querySelectorAll('ul.list-style-none'); lists.forEach(function (ul) { const items = ul.querySelectorAll('li.d-inline'); items.forEach(function (li) { // 给li添加 notranslate 类 li.classList.add('notranslate'); }); }); const elements = document.querySelectorAll('.react-directory-filename-cell'); elements.forEach(function (element) { // 给元素添加 notranslate 类 element.classList.add('notranslate'); }); const elements2 = document.querySelectorAll('.topic-tag.topic-tag-link'); elements2.forEach(function (element) { // 给元素添加 notranslate 类 element.classList.add('notranslate'); }); const elements3 = document.querySelectorAll('.octicon.octicon-link.flex-shrink-0.mr-2'); elements3.forEach(function (element) { // 给元素添加 notranslate 类 element.classList.add('notranslate'); }); const elements4 = document.querySelectorAll('.AppHeader-context-full .list-style-none'); elements4.forEach(function (element) { // 给元素添加 notranslate 类 element.classList.add('notranslate'); }); const elements5 = document.querySelectorAll('.eg-download'); elements5.forEach(function (element) { // 给元素添加 notranslate 类 element.classList.add('notranslate'); }); const elements6 = document.querySelectorAll('.my-3.d-flex.flex-items-center'); elements6.forEach(function (element) { // 给元素添加 notranslate 类 element.classList.add('notranslate'); }); const elements7 = document.querySelectorAll('.Link.Link--muted'); elements7.forEach(function (element) { // 给元素添加 notranslate 类 element.classList.add('notranslate'); }); const elements8 = document.querySelectorAll('.Box-row.d-flex.flex-column.flex-md-row'); elements8.forEach(function (element) { // 给元素添加 notranslate 类 element.classList.add('notranslate'); }); }; // 使用 MutationObserver 监听 DOM 变化 const TV1 = document.querySelector('body'); const MutationObserver1 = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver; const option1 = { 'childList': true, 'subtree': true }; const mo1 = new MutationObserver(function (mutations, observer) { // 每次 DOM 变化时,标记li.d-inline为不翻译 markNoTranslate(); }); // 启动监听 mo1.observe(TV1, option1); // 还可以在页面加载时立即标记已经存在的元素 markNoTranslate(); })()