Separate UI code from HTML to ui.js

I think it’s easier to maintain.