0

I would like to convert this html script into a chrome extension. I followed this short tuto and apparently, I should move all the script ●parts into a .jsfile:

Due to security constraints, we can’t put inline JavaScript into our HTML files inside of our Chrome extensions, so we have to create a separate file to hold any JavaScript code we need and we’ll reference it from the HTML file.

So instead of having just this html:

<!DOCTYPE html>  <html> 
    <head> 
    <title>My Page</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head>  <body> 
    <div class="translate">Тестирование</p>
    <div class="translate_control" lang="en"></div>

    <script>
    function googleSectionalElementInit() {
      new google.translate.SectionalElement({
        sectionalNodeClassName: 'translate',
        controlNodeClassName: 'translate_control',
        background: '#f4fa58'
      }, 'google_sectional_element');
    }
    </script>
    <script src="//translate.google.com/translate_a/element.js?cb=googleSectionalElementInit&ug=section&hl=en"></script>

</body> </html>

I should have one html ...:

<!DOCTYPE html>
<html>
<body>
    <div class="translate">Тестирование</p>
    <div class="translate_control" lang="en"></div>
</body>
</html>

...and one .js. But I am not sure how to go with the .js. How shoudl I call the script //translate.google.com/translate_a/element.js?cb=googleSectionalElementInit&ug=section&hl=en. Also should I add the function googleSectionalElementInit inside a document.addEventListener function?

Also will the script work because it will be stored on my local computer and not a server?

MagTun
  • 5,619
  • 5
  • 63
  • 104
  • I think you need to load it from https:// URL, not just //, using a standard ` – wOxxOm Aug 05 '19 at 16:40
  • Possible duplicate of [How do I include a JavaScript file in another JavaScript file?](https://stackoverflow.com/questions/950087/how-do-i-include-a-javascript-file-in-another-javascript-file) – computercarguy Aug 05 '19 at 18:57

0 Answers0