Importing external libraries
Last updated
Was this helpful?
Last updated
Was this helpful?
A lot of really cool and/or powerful JavaScript libraries and frameworks exist out there that you might want to leverage in a character sheet. Instead of trying to copy-paste their entire codebase into the JavaScript field of a character sheet, you can import them by adding a script
element to the DOM with its source pointing to a content delivery network. Just keep in mind that your plugin might not be approved if it uses obscure libraries or loads them from dubious sources!
The code below is copied almost verbatim from , so kudos to him. The function he came up with will let you chain multiple script imports very cleanly and run your code only if and when they have all been loaded successfully. This last part is important because while your JS runs as soon as the page is loaded, external imports like this can take a couple extra seconds to load and get added to the DOM. If you go and call functions that haven’t been defined yet, you won’t get far without a fatal error!
Simply replace the script’s URL on line 15, remove the others on lines 16-17 if you don’t need more than one, or replace their URLs as well as needed. Place your code after (within) the last then()
, or call one or several functions defined elsewhere so your main logic isn’t in the middle of loadScript()
, for clarity.