// empty event APIs to be redefined
function customFunctionOnPgnTextLoad() {}
this event fires each time the GameText updates.
So, you can redefine this function and check if the length of the inner text of the Div GameText is shorter than previously.
This trick is usefull only for the displayed game, updating the table at the end of each viewed game, or in changing channel.
function clock_tick() // called every second
{
update_clocks(); // always make active clock decrement
if(current_move < downloaded_moves) {
play_one_move(++current_move); // auto-play next move
delay = 0;
return;
}
// all moves have been played; try to fetch new ones
if(delay-- > 0) return;
game_text = get_url(URL_OF_GAME);
delay = 10; // wait 10 sec before doing next probe
move_list = game_text.split(';'); // assumes moves are separated by semi-colons.
downloaded_moves = move_list.length;
if(downloaded_moves < current_move) { // fetched gameis shorter than what we had!
// new game must have started. Do whatever you need to do in that case
...
current_move = 0; // start auto-playing new game from start
}
}
Rebel wrote:I am testing a live broadcast of 4 games (channel 1-4) and at the same time maintain a live ranking as you can see from the link I gave. So if a new game is started I want to automatically refresh the page that shows the new ranking.
Then you should better load the new ranking table and update only that portion of the page.
What you are doing at the moment looks like re-building your entire house every spring only because your wife wants new flowers in the garden
The easiest way of doing that is to load the ranking table in a separate html file in an iframe of the main page, then reload the iframe only. Some people here will tell you that using iframes is not a good idea and of course you should use ajax calls to load the ranking data dynamically and update the html element instead; much neater solution but requires more learning efforts for a javascript newbie.
casaschi wrote: What you are doing at the moment looks like re-building your entire house every spring only because your wife wants new flowers in the garden
Well, with women, in the end it comes down to that anyway (no escape) so I am thinking a few plies ahead