Script only work when I inspected it at least once

Please edit your post to add code-tags and properly layout the code to make it easier for people to help you:

Please post the exact/entire error message you get.