search: factor out javascript from macro

less scripts.