Timed actions in JavaScript simplified