$('#tracker_tracking').removeClass('hidden');
$('#tracker_form').addClass('hidden');
update_tracker();
+ var lastfetch = localStorage.getItem('tracker_lastfetch');
+ if(Date.now() - lastfetch > 60 * 10 * 1000)
+ refresh_tracker();
+ }
+
+ function refresh_tracker(){
+ var user = localStorage.getItem('tracker_username');
var xhr = new XMLHttpRequest();
xhr.open('GET', '/us/' + user + '?format=json');
xhr.onload = function () {
localStorage.setItem('tracker_data', this.responseText);
+ localStorage.setItem('tracker_lastfetch', Date.now());
update_tracker();
};
xhr.send();
}
+ window.refresh_tracker = refresh_tracker;
window.start_tracking = start_tracking;
function stop_tracking(){
clean_tracker();
localStorage.removeItem('tracker_username');
localStorage.removeItem('tracker_data');
+ localStorage.removeItem('tracker_lastfetch');
$('#tracker_tracking').addClass('hidden');
$('#tracker_form').removeClass('hidden');
}
$('#tracker_button').on('click', function() { start_tracking($('#tracker_username').val()) });
$('#tracker_stop').on('click', stop_tracking);
$('#track_user').on('click', function() { stop_tracking(); start_tracking($(this).data('user')) });
+ $('#submitform').on('submit', function() { localStorage.removeItem('tracker_lastfetch') });
if(localStorage.getItem('tracker_username'))
start_tracking(localStorage.getItem('tracker_username'));
</div>
<div id="submit">
-<form action="/action/submit" method="POST" enctype="multipart/form-data" role="form">
+<form id="submitform" action="/action/submit" method="POST" enctype="multipart/form-data" role="form">
<input type="hidden" name="problem" value="problem_id">
<input type="hidden" name="contest" value="contest_id">