Last active
January 8, 2023 15:48
-
-
Save ngs/beb49f012f027184d29b43084d2d8099 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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 } | |
}, ''); |
This file contains hidden or 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 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