Use document.scripts instead of head.querySelector() for detecting whether the script already exists.