Factor out js from background.html