Update Main.js

Optimize a bit and add support of onhashchange event