Skip to content

Instantly share code, notes, and snippets.

@thejungwon
Created September 29, 2018 10:14
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 thejungwon/6c525d36451bac5e7d84cfd71eb95889 to your computer and use it in GitHub Desktop.
Save thejungwon/6c525d36451bac5e7d84cfd71eb95889 to your computer and use it in GitHub Desktop.
function newimage(keyword){
if(!ACCESS_KEY){
alert("Please update your access key");
return;
}
var url = `https://api.unsplash.com/search/photos?query=${keyword}&per_page=20&orientation=landscape&client_id=${ACCESS_KEY}`;
$.get(url,function(data){
var picture = data.results[0];
var picture_url = picture.urls.raw;
var photo_by_name = picture.user.name;
var photo_by_url = picture.user.links.html;
setCookie("picture",picture_url,0.5);
setCookie("photo-by-name",photo_by_name,0.5);
setCookie("photo-by-url",photo_by_url,0.5);
$('.interest-text').html(keyword);
$('.photoby').html(photo_by_name);
$('.photoby').attr('href',photo_by_url);
$('body').css('background-image',`url(${picture_url})`);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment