How to organize this code: an extension that launches different code depending on the input data.
I'm building a chrome extension that will need to execute a different js script depending on input data the extension gives it. There will very quickly be 1000's of unique scripts to execute depending on the input.
How would you model this?
I don't think if/else statements are efficient in this case, but I can't store js code in a sqlite db either.
Posted Dec 15, 2018, 6:16 PM UTC · edited
You should definitely not be storing executed code in a database. You definitely should be using an if/else statement or equivalent to make decisions based on user input.
I will update the description to add that there will possibly be 1000's of different scripts, so I don't feel like a huge if/else list is a good option.
Okay. So, if I was designing this, I would try and store each script in a separate file. Then, in the database, I would give each file an ID, and a path. Then, someone could select "I want to execute script 5567 whenever I go to google.com". Then my JS would do something like:
This is pretty much what I was looking for and confirms what I was doing already. thanks.