{
let imgs = $$('img').map(img=>img.src)
const observer = new MutationObserver(function(mutationList, observer) {
for(const mutationItem of mutationList) {
if(mutationItem.target.matches('img')) {
checkImg(mutationItem.target)
}
const subImgs = $$('img', mutationItem.target)
subImgs.forEach(checkImg)
}
})
observer.observe(
document.body,
{
attributes: true,
childList: true,
subtree: true
}
)
{
var btnEl = document.createElement('button')
addStyles(btnEl,{
position:'fixed',
right: '1rem',
bottom: '1rem',
padding: '1rem',
background: 'black',
color: 'white'
})
btnEl.textContent = 'Add Them'
btnEl.onclick = addThem
document.body.appendChild(btnEl)
}
function checkImg(imgNode) {
if(!imgs.includes(imgNode.src)) {
imgs.push(imgNode.src)
console.log(imgs.length)
}
}
function addThem() {
let el = $$('#img-download-thing-s34F4x')[0]
if(el == undefined) {
el = document.createElement('div')
el.id = 'img-download-thing'
document.body.appendChild(el)
}
empty(el)
for(const imgSrc of imgs) {
const imgEl = document.createElement('img')
imgEl.src = imgSrc
el.appendChild(imgEl)
}
}
function addStyles(el, styleObj) {
for(let k in styleObj) {
el.style[k] = styleObj[k]
}
}
function $$(selector, rootNode=document) {
return Array.from(rootNode.querySelectorAll(selector))
}
function empty(el) {
let fc = el.firstChild
while(fc) {
el.removeChild(fc)
fc = el.firstChild
}
}
}
|