location.protocol can be used to detect the protocol that the current site is using.

For example: