js refactor for player button functionality