Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Author: <mvdw at airmail dot cc> */
- "use strict";
- (function() {
- var JSONLoad = function(file, callback) {
- var x = new XMLHttpRequest();
- x.callback = callback;
- if(x.overrideMimeType)
- x.overrideMimeType("application/json");
- x.open('GET', file, false);
- x.onreadystatechange = function(){
- if(this.readyState == 4) this.callback(this);
- }
- x.send(null);
- };
- var Apply = function() {
- var fx = function() {
- return Math.floor(Math.random() * sources.length)
- };
- while (vx == old) {
- vx = fx();
- if (vx != old) {
- break;
- }
- }
- sl.src = sources[vx];
- old = vx;
- };
- var Reload = function() {
- var timeout = window.setTimeout(function(){
- Apply();
- Reload();
- }, (delay || 1000));
- };
- var sources;
- var delay = 1000;
- var old;
- var sl = document.createElement('img');
- var vx;
- // Apply the element to the body. You can have it appended to a custom
- // element by changing 'document.body' to the requested DOM element.
- document.body.appendChild(sl);
- // Load the .json file to the sources variable.
- JSONLoad("images.json", function(o){
- sources = JSON.parse(o.responseText.split("*/").slice(-1)[0].replace(/[\n ]/,""))[0].images;
- });
- // Apply onload.
- Apply();
- // If you only want a new one when you refresh your page you comment this.
- Reload();
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement