change javascrip to new api