Refactor javascript code for auto power off settings