Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@fjallstrom
Last active November 18, 2016 12:51
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 fjallstrom/a7533c7e565cc7c5ba09d7b9e06b6d15 to your computer and use it in GitHub Desktop.
Save fjallstrom/a7533c7e565cc7c5ba09d7b9e06b6d15 to your computer and use it in GitHub Desktop.
<html><head>
<script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
<script>
function checkApi(){
// CRAPPY JQUERY SCRIPT BECAUSE I AM NOT A DEVELOPER (anymore)
// fetch latest from api
var apixhr = $.ajax({
url: 'http://yourserver.com/yourdbpollscript.php',
dataType: "jsonp"
}).done(function(data) {
if(data){
// fetch giphy on this subject
var giphyxhr = $.get('http://api.giphy.com/v1/gifs/search?q='+data+'&api_key=XXX&limit=5');
giphyxhr.done(function(giphydata) {
console.log(giphydata.data.length)
if(giphydata.data.length){
var idleUrl = 'https://media.giphy.com/media/xaMg6NGwH2fFS/giphy.gif';
// set img src
$('#giphy').attr('src',giphydata.data[0].images.original.url);
// show gif 8 secs
setTimeout(function(){
$('#giphy').attr('src',idleUrl);
}, 8000);
}
});
}
});
setTimeout(function(){
console.log('check api again')
checkApi();
}, 10000);
}
$(document).ready(function() {
console.log('check api first run')
checkApi();
});
</script>
</head><body bgcolor="black">
<img src="https://media.giphy.com/media/xaMg6NGwH2fFS/giphy.gif" id="giphy" width="100%" height="100%">
</body></html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment