The way you did it using content editor webpart might not work because, webpart would be only available on single page. I would suggest you to do following
- Create SPFx extension to add reference to custom js file using application customizer.
Please note that you have to modify this code a bit to add it to top section or bottom section.
Ref link - https://docs.microsoft.com/en-us/sharepoint/dev/spfx/extensions/get-started/using-page-placeholder-with-extensions
var customjs = document.createElement("SCRIPT");
customjs.setAttribute("src", site absolute url + "/SiteAssets/js/Custom.js");
- Add this SPFx extension to app catalog and install on your target site. You should see custom.js file being loaded on every page load and your code will take care of adding elements below search bar.