Create a gist now

Instantly share code, notes, and snippets.

<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