33 lines
1 KiB
JavaScript
Executable file
33 lines
1 KiB
JavaScript
Executable file
var go = function(b, img_id, interval) {
|
|
var i = 0;
|
|
var img0 = document.getElementById(img_id[0]);
|
|
var img1 = document.getElementById(img_id[1]);
|
|
var img = [img0, img1];
|
|
var activeImage = 1; // index of visible image
|
|
var url = 'index.php?mode=zap';
|
|
|
|
if (isNaN(interval)) {
|
|
interval = 5000;
|
|
}
|
|
|
|
// Trigger the next image fetch after the current one has loaded.
|
|
img[0].onload = img[1].onload = function() {
|
|
var inactiveImage = activeImage === 0 ? 1 : 0;
|
|
img[activeImage].style.display = 'none';
|
|
img[inactiveImage].style.display = '';
|
|
activeImage = inactiveImage;
|
|
|
|
setTimeout(function() {
|
|
img[inactiveImage].src = url + '&i=' + (i++);
|
|
}, interval);
|
|
};
|
|
|
|
// When the backend signals completion it returns a small HTML page.
|
|
// Show the ready link and stop fetching new images.
|
|
img[0].onerror = img[1].onerror = function() {
|
|
document.getElementById('ready').innerHTML = '<a href="/">Ready</a>';
|
|
};
|
|
|
|
// Kick off the first request.
|
|
img[activeImage].src = url + '&i=' + (i++);
|
|
};
|