Google整页翻译

类似谷歌浏览器自带翻译

// ==UserScript==
// @name         Google整页翻译
// @namespace    https://greasyfork.org/zh-CN/users/
// @version      0.9
// @description  类似谷歌浏览器自带翻译
// @author       zs6
// @license      GPL-3.0-only
// @match        http://*/*
// @include      https://*/*
// @include      file://*/*
// @run-at document-end
// @noframes
// ==/UserScript==

(function () {
    'use strict';
    function addNewElement(innerhtml,node,src) {
        var element = document.createElement(node);
        if(src){
            element.src = innerhtml;
        }else{
            element.innerHTML = innerhtml;
        }
        document.getElementsByTagName('head')[0].appendChild(element);
    }
    if (/en/.test(document.documentElement.lang)) {

        var google_translate_element = document.createElement('div');
        google_translate_element.id = 'google_translate_element';
        google_translate_element.style = 'position:fixed; bottom:5px; left:5px; cursor:pointer;Z-INDEX: 99999;opacity:0.8;';
        document.documentElement.appendChild(google_translate_element);

        var gtehtml="function googleTranslateElementInit() {" +
            "new google.translate.TranslateElement({" +
            "autoDisplay: true,"+
            "layout: google.translate.TranslateElement.InlineLayout.SIMPLE," +
            "multilanguagePage: true," +
            "pageLanguage: 'auto'," +
            "includedLanguages: 'zh-CN,zh-TW'" +
            "}, 'google_translate_element');}";
        addNewElement(gtehtml,'script',false);
        addNewElement('https://cdn.jsdelivr.net/gh/zs6/gugefanyijs@1.9/element.js','script',true);
        }

}());