Google Translate Page

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

目前为 2020-05-28 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Google Translate Page
  3. // @namespace 432346-fke9fgjew89gjwe89
  4. // @match *://*/*
  5. // @grant GM_registerMenuCommand
  6. // @noframes
  7. // @version 1.0
  8. // @icon https://translate.google.com/favicon.ico
  9. // @author -
  10. // @description Display option to translate the current page with google translate in violentmonkey menu
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15.  
  16. if (window.top != window.self)
  17. return;
  18. var d = document;
  19.  
  20. function translate() {
  21. var d, b, o, v, p;
  22. b = (d = document).body;
  23. o = d.createElement('script');
  24. o.setAttribute('src', 'https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit');
  25. o.setAttribute('type', 'text/javascript');
  26. b.appendChild(o);
  27. v = b.insertBefore(d.createElement('div'), b.firstChild);
  28. v.id = 'google_translate_element';
  29. v.style.display = 'none';
  30. p = d.createElement('script');
  31. p.text = 'function googleTranslateElementInit(){new google.translate.TranslateElement({pageLanguage:"auto"},"google_translate_element");}';
  32. p.setAttribute('type', 'text/javascript');
  33. b.appendChild(p);
  34. }
  35.  
  36. GM_registerMenuCommand("Translate this page", translate)
  37.  
  38. })();