Created
February 18, 2012 16:17
-
-
Save gautamk/1860013 to your computer and use it in GitHub Desktop.
Tumblr bgchanger
This file contains hidden or 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
//(function(){ | |
//Refer http://code.google.com/apis/picasaweb/docs/2.0/reference.html | |
// Album url can be obtained by getting the rss feed of a Public or Limited album | |
var album_url = "https://picasaweb.google.com/data/feed/base/user/104873802064687726116/albumid/5710488196657525265?"+ // The base url | |
//Query Parameters | |
"alt=json"+ // Options are json and rss , | |
"&kind=photo"+ | |
"&authkey=Gv1sRgCIC0zJCjrbqplwE"+//Necessary only because the album's visibility is Limited , link only | |
"&hl=en_GB"+//Language | |
"&prettyprint=true"+ // Only enable in Development mode | |
"&imgmax=1600"; // Max size of each of the images | |
var PicList = new Array(); | |
var slide_show_pic = $("body"); | |
function _generateRandomImageNumber(){ | |
// Not for public use | |
return Math.floor(Math.random() * PicList.length); | |
} | |
function getRandomImage(){ | |
var img = new Image(); | |
img.src = PicList[_generateRandomImageNumber()]; | |
return img; | |
} | |
function paintImage(img){ | |
// @param : an object of type Image | |
img.onload = function(){ | |
slide_show_pic.css('background','url('+img.src+')'); | |
}; | |
} | |
function paintRandomImage(){ | |
paintImage(getRandomImage()); | |
} | |
$(document).ready(function(){ | |
//Get the Feed data from Picasa | |
$.getJSON(album_url, function(data) { | |
//Push the Url of each image | |
$.each(data.feed.entry, function(key, val) { | |
PicList.push(val.content.src); | |
}); | |
// Paint on Page and feed loads | |
paintRandomImage(); | |
// Paint new image every x milli seconds | |
setInterval(paintRandomImage,1000 * 10 ); | |
}); | |
}); | |
//})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment