For modern SharePoint Sites, you can use the Modern Script Editor web part.
It is developed by community members and works the same as the Content Editor web part.
Get the source code from below.
Follow the steps mentioned in the README and you will be able to add the web part in your modern SharePoint Page.
How to create SPFx Application Customizer extension