Last active
January 6, 2019 05:02
-
-
Save SukkaW/75a38e665fa6920ed712f8dd5aa586a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var isSupportWebp = !![].map && document.createElement('canvas').toDataURL('image/webp').indexOf('data:image/webp') == 0; | |
var WebpName = "!/format/webp"; | |
if (isSupportWebp) { | |
for (var i = 0; i < document.querySelectorAll("div[data-bg]").length; i += 1) { | |
var originSrc = document.querySelectorAll("div[data-bg]")[i].getAttribute('data-bg'), | |
newSrc = originSrc.replace(/((.png)|(.jpg)|(.jpeg))/g, '$1' + WebpName); | |
document.querySelectorAll("div[data-bg]")[i].setAttribute('data-bg', newSrc) | |
} | |
for (var i = 0; i < document.querySelectorAll("div[data-src]").length; i += 1) { | |
var originSrc = document.querySelectorAll("div[data-src]")[i].getAttribute('data-src'), | |
newSrc = originSrc.replace(/((.png)|(.jpg)|(.jpeg))/g, '$1' + WebpName); | |
document.querySelectorAll("div[data-bg]")[i].setAttribute('data-bg', newSrc) | |
} | |
for (var i = 0; i < document.querySelectorAll("img[data-src]").length; i += 1) { | |
var originSrc = document.querySelectorAll("img[data-src]")[i].getAttribute('data-src'), | |
newSrc = originSrc.replace(/((.png)|(.jpg)|(.jpeg))/g, '$1' + WebpName); | |
document.querySelectorAll("img[data-src]")[i].setAttribute('data-src', newSrc) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment