Blog Web Developer

These articles are more for me to save the code somewhere, so I can find it later on, but if you read this, waddup! I made a mini-script which adds a link under every pictures on an idealista ad so you can easily download them.

The problem

The pictures on idealista are protected, you can’t right-click on them and do “Save Image As…”, which means you need to get the URL from the source code and blablabla… it’s long.

The solution

is simple… enough. We loop through all the divs with a specific class, find the img in that div, get its src attribute, and then append a link which downloads the picture (and renames it so it’s not a URL).

// dat specific class i was talkin aboot

  // dat delicious image url, saved in a source variable (mmh, mmmmh)
  var source = this.getElementsByClassName("detail-image-gallery")[0].getAttribute("src");

  // taking the innerHTML of the div and appending the <a> element to DL that delicious image
  this.innerHTML += "<a href='" + source + "' download='" + source.substring(source.lastIndexOf('/') + 1) + "'>Download</a>";

// closing the loop

// nothing

and, tada.

Now, if you click on the link it just opens it in a new page, and blurgh… so, just alt + click the link and the image will download in your preferred folder (Downloads, usually).

Oh yeah, and make sure all the images are loaded on the page by scrolling-down before injecting script.
Oh yeah, how to inject the script… Inspect Element > Console and then copy-and-paste the code there.