index: move js code to js file