// ==UserScript== // @name 替换让谷歌翻译更准确 // @namespace http://tampermonkey.net/ // @version 0.41 // @description 谷歌翻译不能正确翻译带的元素 // @author You // @match http*://*/* // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== // @grant none // @license MIT // @downloadURL none // ==/UserScript== (function() { 'use strict'; const func = ()=>{ setTimeout(()=>{ Array.from(document.getElementsByTagName('code')).forEach(code=>{ const isLongCode = code.offsetWidth > 200 //document.documentElement.offsetWidth/3 if (!isLongCode) { const span = document.createElement('span') span.textContent = code.textContent span.style.cssText = "background-color: #f1f1f1;"; code.parentNode.insertBefore(span, code) code.parentElement.removeChild(code) } } ) console.log('替换完成') } , 1000) } func(); //修改native以拦截popstate事件 var pushState = history.pushState; history.pushState = function() { var ret = pushState.apply(history, arguments); window.dispatchEvent(new Event("pushstate")); window.dispatchEvent(new Event("locationchangefathom")); return ret; } window.addEventListener("popstate", function() { window.dispatchEvent(new Event("locationchangefathom")) }); window.addEventListener("locationchangefathom", trackPageview) function trackPageview() { func(); } } )();