Skip to content

Instantly share code, notes, and snippets.

@ngs
Last active January 8, 2023 15:48
Show Gist options
  • Save ngs/beb49f012f027184d29b43084d2d8099 to your computer and use it in GitHub Desktop.
Save ngs/beb49f012f027184d29b43084d2d8099 to your computer and use it in GitHub Desktop.
// https://developer.mozilla.org/en-US/docs/Web/API/StyleSheetList
var allCSS =
[].slice.call(document.styleSheets)
.reduce(function (prev, styleSheet) {
try {
return prev +
[].slice.call(styleSheet.cssRules)
.reduce(function (prev, cssRule) {
return prev + cssRule.cssText;
}, ''); } catch(e) { console.error(e); return prev }
}, '');
var allBackgroundImages =
[].slice.call(document.styleSheets)
.reduce((prev, styleSheet) => {
try {
return prev.concat(
[].slice.call(styleSheet.cssRules)
.reduce((prev, cssRule) => {
var img = (((cssRule.style || {}).backgroundImage || '').match(/^url\("(.+)"\)$/) || [])[1];
if (img) {
var cssURL = (cssRule.parentStyleSheet || {}).href || document.location.href
if (!/^(https?|data):\/\//.test(img)) {
img = new URL(img, cssURL).href
}
prev.push(img);
}
return prev;
}, [])
)
} catch (e) {}
return prev
}, []);
var allImages =
[].slice.call(document.querySelectorAll('img'))
.reduce((prev, img) => {
if (img.src) {
prev.push(img.src)
}
return prev
}, allBackgroundImages)
allImages = allImages.filter((img, i) => { return allImages.indexOf(img) === i })
allImages.join('\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment