Advertisement
nrzmalik

Storyline Dynamic Translation

Nov 24th, 2023 (edited)
1,167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.73 KB | Source Code | 0 0
  1. function createGoogleTranslateWidget() {
  2.     const translateDiv = document.createElement('div');
  3.     translateDiv.id = 'google_translate_element';
  4.  
  5.     const targetDiv = document.querySelector('.slide-window-slide-container');
  6.  
  7.     targetDiv.parentNode.insertBefore(translateDiv, targetDiv);
  8.  
  9.     const script1 = document.createElement('script');
  10.     script1.type = 'text/javascript';
  11.     script1.src = 'https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit';
  12.     document.body.appendChild(script1);
  13.  
  14.     if (!window.googleTranslateElementInit) {
  15.         window.googleTranslateElementInit = function() {
  16.             new google.translate.TranslateElement({
  17.                 pageLanguage: 'en',
  18.                 layout: google.translate.TranslateElement.InlineLayout.HORIZONTAL
  19.             }, 'google_translate_element');
  20.         }
  21.     }
  22. }
  23.  
  24.  
  25. function addCssToHead(cssRules) {
  26.     var styleElement = document.createElement('style');
  27.  
  28.     styleElement.textContent = cssRules;
  29.  
  30.     document.head.appendChild(styleElement);
  31. }
  32.  
  33. var css = `
  34.     iframe[id=":1.container"] {
  35.         display: none !important;
  36.     }
  37.     body {
  38.         top: 0 !important;
  39.     }
  40.     .goog-logo-link {
  41.         display: none !important;
  42.     }
  43.     .goog-te-gadget {
  44.         color: transparent !important;
  45.     }
  46.     .VIpgJd-ZVi9od-l4eHX-hSRGPd {
  47.         display: none;
  48.     }
  49.     #goog-gt-tt #goog-gt-vt {
  50.         display: none !important;
  51.     }
  52.     .VIpgJd-ZVi9od-aZ2wEe-wOHMyf.VIpgJd-ZVi9od-aZ2wEe-wOHMyf-ti6hGc {
  53.         display: none !important;
  54.     }
  55. body {
  56.     overflow: auto !important;
  57. }
  58. `;
  59.  
  60. if (!document.getElementById('google_translate_element')) {
  61.     addCssToHead(css);
  62.     createGoogleTranslateWidget();
  63. }
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement