You should be able to insert your HTML code in a copy of the default master page you are already using, download it locally and and then publish it and set it as masterpage for your sites using O365 dev PnP Powershell cmdlts.
As i'm not using O365 myself i haven't been able to try it out but should be doable.
There are some prerequisites to be able to use the commands but after that you should be able to do something like this:
Connect-SPOnline –Url https://yoursite.sharepoint.com –Credentials (Get-Credential)
$sites = Get-SPOSite
foreach ($site in $sites)
Add-SPOMasterPage -SourceFilePath "page.master" -Title "MasterPage" -Description "MasterPage for Web" -DestinationFolderHierarchy "SubFolder"
Set-SPOMasterPage -MasterPageServerRelativeUrl /sites/projects/_catalogs/masterpage/oslo.master
Add masterpage: https://github.com/OfficeDev/PnP-PowerShell/blob/master/Documentation/AddSPOMasterPage.md
Set masterpage: https://github.com/OfficeDev/PnP-PowerShell/blob/master/Documentation/SetSPOMasterPage.md
Be aware that i have not tested this out myself so no guarantees. It might be a good start if anything.
Deploying Artifacts to Office 365 using PowerShell