This question might be redundant or similar to ones already posted but is there a way for me to import a js file from another js file while coding for a google extension?
I did some research and found answers that work only if you are importing js into html using the "" tag. I know the require function from node is one method but I'm not sure if the extension will still work for other people when they download my extension for their own usage. (As they won't have Node installed)
Additionally, when I hard code my array elements without importing and do
document.getElementById('Some random id').textContent = "This works!";
The textContent only changes for the first iteration of that id present in the website html. I understand the logic behind this but want it to change the textContent for every single iteration of that specific id.
The manifest.json has 2 content scripts loaded, main.js, and catalog.js. Catalog.js contains an array while main.js does the heavy lifting.
"name": "Test Extension",
"description": "Learning how to make google extensions",
"manifest_version": 2,
"version": "1.0",
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["main.js", "catalog.js"]
}
]
}
main.js:
var ids = require('./catalog.js');
console.log("Testing...")
for (i = 0; i < ids.length; i++)
{
document.getElementById(ids[i]).textContent = "This works!";
}
catalog.js:
var ids = [
"video-title"
]
module.exports = {ids};