Greasy Fork

替换<code>让谷歌翻译代码更准确

谷歌翻译遇到<code>标签会有点问题

目前为 2022-10-11 提交的版本。查看 最新版本

// ==UserScript==
// @name         替换<code>让谷歌翻译代码更准确
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  谷歌翻译遇到<code>标签会有点问题
// @author       chenjiamian
// @match        http://*/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';
    Array.from(document.getElementsByTagName('code')).forEach(code=>{
    const isLongCode = code.offsetWidth > 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)
    }
})
    // Your code here...
})();