Replace String.match() with RegExp.test(); it's slightly more efficient when we don't need the actual result

This commit is contained in:
Nate Weaver 2020-11-20 11:30:32 -06:00
parent 470b8514e4
commit 755ca7998e

View File

@ -46,7 +46,7 @@ function convertImgSrc() {
document.querySelectorAll("img").forEach(element => {
if (element.hasAttribute("data-canonical-src")) {
element.src = element.getAttribute("data-canonical-src")
} else if (!element.src.match(/^[a-z]+\:\/\//i)) {
} else if (!/^[a-z]+\:\/\//i.test(element.src)) {
element.src = new URL(element.src, document.baseURI).href;
}
});