Hi @Mirza Hassan Baig ,
Welcome to Q&A forum!
Unfortunately, currently for the SharePoint Online modern experience, you cannot use JavaScript.
This extensibility option is only available for classic SharePoint experiences. You cannot use this option with modern experiences in SharePoint Online, like with communication sites. Notice also that you should not take a dependency on the html page structure or on the out-of-the-box CSS style names as these might be adjusted without a notice.
For your reference:
You can try to use SPFX. For more details, please refer to:
https://learn.microsoft.com/en-us/sharepoint/dev/spfx/use-theme-colors-in-your-customizations
Good day!
If the answer is helpful, please click "Accept as Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.