From: Marius Gavrilescu Date: Thu, 19 Feb 2015 20:08:39 +0000 (+0200) Subject: Make tracker less automatic and more resource-friendly X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=63b23993665aaa966bc328c5bfbc979760cbb5fe;p=gruntmaster-page.git Make tracker less automatic and more resource-friendly --- diff --git a/js/90-tracker.js b/js/90-tracker.js index 2f8271c..16b9d87 100644 --- a/js/90-tracker.js +++ b/js/90-tracker.js @@ -77,20 +77,30 @@ $('#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'); } @@ -100,6 +110,7 @@ $('#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')); diff --git a/tmpl/pb_entry.en b/tmpl/pb_entry.en index 1518841..be31a1b 100644 --- a/tmpl/pb_entry.en +++ b/tmpl/pb_entry.en @@ -24,7 +24,7 @@ To submit solutions to this problem, please visit the problem o
-
+