Update autoschedule.js

newest code after refactor