您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
避免google网页翻译github和npm```<pre>```标签内的内容
当前为
// ==UserScript== // @name 不要翻译github上的代码 // @namespace http://floatsyi.com/ // @version 0.30 // @description 避免google网页翻译github和npm```<pre>```标签内的内容 // @author floatsyi // @include *://github.com* // @include *://www.npmjs.com* // @match *://github.com* // @match *://www.npmjs.com* // @grant 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 githubTV = document.querySelector('.application-main') const npmTV = document.querySelector('main') // 监听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() { !!githubTV && observer.observe(githubTV, option) !!npmTV && observer.observe(npmTV, option) }, 50) } const files = document.querySelectorAll('.file') const pres = document.querySelectorAll('pre') if (!(files.length > 0) && !(pres.length > 0)) return false 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)}) } } else if (pres.length > 0) { pres.forEach(function(pre){if (!hasCodeEleChild(pre)) addCodeEle(pre)}) } else { console.log('不要翻译github上的代码: 执行条件不足') } time++ // console.log('不要翻译github上的代码:', time) } const mo = new MutationObserver(_.debounce(doNotTranslateCode, 50)) !!githubTV && mo.observe(githubTV, option) !!npmTV && mo.observe(npmTV, option) // window.addEventListener('popstate', doNotTranslateCode) })();
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址