Refactor javascript [ci skip]