Google Translate Page

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

  1. // ==UserScript==
  2. // @name Google Translate Page
  3. // @namespace 432346-fke9fgjew89gjwe89
  4. // @match *://*/*
  5. // @grant GM_registerMenuCommand
  6. // @noframes
  7. // @version 1.2
  8. // @icon https://translate.google.com/favicon.ico
  9. // @author 432346-fke9fgjew89gjwe89
  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. document.cookie = "googtrans=/auto/en; path=/";
  22.  
  23. var d, b, o, v, p;
  24. b = (d = document).body;
  25. o = d.createElement('script');
  26. o.setAttribute('src', 'https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit');
  27. o.setAttribute('type', 'text/javascript');
  28. b.appendChild(o);
  29. v = b.insertBefore(d.createElement('div'), b.firstChild);
  30. v.id = 'google_translate_element';
  31. v.style.display = 'none';
  32. p = d.createElement('script');
  33. p.text = 'function googleTranslateElementInit(){new google.translate.TranslateElement({pageLanguage:"auto"},"google_translate_element");}';
  34. p.setAttribute('type', 'text/javascript');
  35. b.appendChild(p);
  36. }
  37.  
  38. GM_registerMenuCommand("Translate this page", translate)
  39.  
  40. })();