JS: save endtime only on exit