Created
April 5, 2015 11:56
-
-
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)
This file contains 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
//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