]> iEval git - gruntmaster-page.git/commitdiff
Make tracker less automatic and more resource-friendly
authorMarius Gavrilescu <marius@ieval.ro>
Thu, 19 Feb 2015 20:08:39 +0000 (22:08 +0200)
committerMarius Gavrilescu <marius@ieval.ro>
Thu, 19 Feb 2015 20:08:39 +0000 (22:08 +0200)
js/90-tracker.js
tmpl/pb_entry.en

index 2f8271c12ab8295ad7d300e8e5d4c90603b90117..16b9d8739f0e614b2f9b634cd453680f356d494f 100644 (file)
                $('#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'));
index 15188417ed432bc0b5842e2ff47951b591a79e42..be31a1b778be3a8adccafc90818a0b0bf463375b 100644 (file)
@@ -24,7 +24,7 @@ To submit solutions to this problem, please visit the problem <a href="/pb/id">o
 </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">
 
This page took 0.02775 seconds and 4 git commands to generate.