Background
I've set-up rrdtool to generate graphs of various data elements. I'm using a tiddlywiki to display those graphs. The graphs are refreshed every 5 minutes (some will be refreshed less often in the future). I would like to have TiddlyWiki refresh the images periodically (once every 5 minutes initially).
What I think I want to do
I think the way I should do this is to create a javascript macro that gets called when the tiddler is displayed and uses setInterval() to periodically refresh the images within the tiddler.
How do I get from "this" to the list of image elements within a tiddler?
I can't figure out how to identify the images in question. I've currently got the following in the javascript macro (based on the example from TW5 Magick:
/*\
title: $:/macros/lost/5mImgRefresh.js
type: application/javascript
module-type: macro
<<5mImgRefresh>>
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
exports.name = "5mImgRefresh";
exports.params = [];
/*
Run the macro
*/
exports.run = function() {
var imgElements = this.getElementsByTagName('img');
/* loop through elements in imgElements and update once every 5 minutes */
setInterval(function() {
for (var i = 0; i < imgElements.length; i++) {
var img = imgElements[i];
img.src = img.src + '?c=' + Math.random();
}, 300000);
/* for debugging, print the source list once */
var output = 'Img Urls:';
for (var i = 0; i < imgElements.length; i++) {
var img = imgElements[i];
output += img.src;
}
return output;
};
})();
Alternative
I'm quite happy to tie this specifically to the image being displayed (in some way). I will eventually want to define the refresh time and
probably limit the which images get refreshed.
I would also be happy to have a refresh that doesn't need to include a pointless query parameter to the image.
Future
I would like to modify it so that I can insert data other than images. Like possibly logs put inside a div or converted into tables.