Google Translate Page

Display option to translate the current page with google translate in violentmonkey menu

目前為 2020-05-28 提交的版本,檢視 最新版本

// ==UserScript==
// @name        Google Translate Page
// @namespace   432346-fke9fgjew89gjwe89
// @match       *://*/*
// @grant       GM_registerMenuCommand
// @noframes
// @version     1.0
// @icon        https://translate.google.com/favicon.ico
// @author      -
// @description Display option to translate the current page with google translate in violentmonkey menu
// ==/UserScript==

(function () {
  'use strict';

  if (window.top != window.self)
    return;
  var d = document;

  function translate() {
    var d, b, o, v, p;
    b = (d = document).body;
    o = d.createElement('script');
    o.setAttribute('src', 'https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit');
    o.setAttribute('type', 'text/javascript');
    b.appendChild(o);
    v = b.insertBefore(d.createElement('div'), b.firstChild);
    v.id = 'google_translate_element';
    v.style.display = 'none';
    p = d.createElement('script');
    p.text = 'function googleTranslateElementInit(){new google.translate.TranslateElement({pageLanguage:"auto"},"google_translate_element");}';
    p.setAttribute('type', 'text/javascript');
    b.appendChild(p);
  }

  GM_registerMenuCommand("Translate this page", translate)

})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址