Scrap all images from a page (IIFE)

JS
S
JavaScript

Immediately Invoked Function Expression (IIFE) -- The script finds all images within elements having the class .masonry-brick, changes their URLs to point to what is presumed to be a much larger version of the same image, and then copies the complete list of these new URLs to the clipboard, with each URL on a new line. This is a typical automation script one might run in a browser's developer console to quickly grab high-resolution image links from a gallery-style webpage.

1(() => {
2  const data = document.querySelectorAll('.masonry-brick img')
3  let arr = []
4  
5  for (let i = 0; i < data.length; i++) {
6    arr.push(data[i].src.replace(/-medium/g, '-xxlarge'))
7  }
8  console.log(arr)
9  let dataToArray = arr.toString().split(',').map(item => item.trim())
10
11  const dummy = document.createElement('textarea')
12  document.body.appendChild(dummy)
13  dummy.value = dataToArray.join('\n')
14  dummy.select()
15  document.execCommand('copy')
16  document.body.removeChild(dummy)
17})()

Created on 6/8/2025