Skip to content

Instantly share code, notes, and snippets.

@jsmrcaga
Created April 5, 2015 11:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsmrcaga/29791e3594a4073ad3c6 to your computer and use it in GitHub Desktop.
Save jsmrcaga/29791e3594a4073ad3c6 to your computer and use it in GitHub Desktop.
JavaScript to get 500px photo URL (remember to always give credit to photographer)
//REMEMBER TO ALWAYS GIVE CREDIT TO THE PHOTOGRAPHER
//NOT INTENDED TO STEAL 500PX PHOTOS
//THEY ARE NOT PUBLIC PROPERTY AND SHOULD NOT BE USED FOR COMERCIAL PURPOSES
function getPhoto () {
// usage:
// function returns object with URL, author and title tags
// simply use getPhoto().URL, or .author or .title
// or store result in variable, var someVar = getPhoto()
// and access values in the same way
var els = document.getElementsByTagName("img");
var photoDOM ="";
for(var i=0; i<els.length; i++){
if (els[i].className == "the_photo"){
photoDOM = els[i];
var photo = {
URL : photoDOM.src,
author: photoDOM.getAttribute("data-protect"),
title: photoDOM.getAttribute("alt"),
}
window.open(photo.URL);
return photo;
}
}
console.warn("Could not find the_photo");
return -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment