search: factor out javascript from macro

Less inline scripts.

**nb** it doesn't fix: #1968
Indeed. No worries, uglifyjs cleanses them.