Adding check to apply the script on preview mode only