I'm happy to work on this later, so this is mostly a reminder for myself.
Currently, if using a CSP, then there are multiple errors caused by inline scripts/styles being blocked. Some of this code will need to be refactored to work correctly in this setting.