Last active
August 2, 2019 02:45
-
-
Save mtlynch/d28fc1ea7ee402b9c0bfa97e1d0c240c to your computer and use it in GitHub Desktop.
Dump background-image property from every element on a page
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
function getBackgroundUrl(bg) { | |
var match = bg.match(/url\(["']([^'"]+)['"]\)/); | |
if (match && match.length == 2) { return match[1]; } | |
return null; | |
} | |
backgroundUrls = new Set(); | |
document.querySelectorAll('*') | |
.forEach(function(el) { | |
var background = el.style.background || window.getComputedStyle(el).background; | |
if (!background) { | |
return; | |
} | |
var backgroundUrl = getBackgroundUrl(background); | |
if (!backgroundUrl) { | |
return; | |
} | |
backgroundUrls.add(backgroundUrl); | |
}); | |
Array.from(backgroundUrls) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment