]>
iEval git - gruntmaster-page.git/blob - js/90-tracker.js
4 function tick() { return $('<span class="tick tracker-mark">✔</span>') }
5 function xmark() { return $('<span class="x tracker-mark">✘</span>') }
7 function clean_tracker(){
8 $('.tracker-mark').detach();
9 $('.tracker-info').removeClass('tracker-info info');
12 function update_tracker(){
13 var data
= localStorage
.getItem('tracker_data');
14 var user
= localStorage
.getItem('tracker_username');
17 data
= JSON
.parse(data
);
22 data
.problems
.forEach(function(e
){
24 solved
[e
.problem
] = 1;
27 attempted
[e
.problem
] = 1;
33 data
.contests
.forEach(function(e
){
34 contests
[e
.contest
] = 1;
38 $('#tracker_userlink').html(data
.name
);
39 $('#tracker_solved').html(solvednr
);
40 $('#tracker_attempted').html(attemptednr
);
41 $('#tracker_contests').html(data
.contests
.length
);
42 $('#tracker_log').attr('href', '/log/?owner=' + user
);
44 if(location
.pathname
== '/pb/')
45 $('table').find('.name').find('a').each(function() {
46 var id
= $(this).attr('href').split('?', 2)[0];
48 $(this).parent().prepend(tick());
49 else if(attempted
[id
])
50 $(this).parent().prepend(xmark());
53 if(location
.pathname
== '/ct/')
54 $('table').find('.name').find('a').each(function() {
55 var id
= $(this).attr('href').substr(4);
57 $(this).parent().prepend(tick());
60 if(location
.pathname
== '/log/')
61 $('table').find('tbody').find('tr').each(function() {
62 if($(this).find('.owner').find('a').attr('href') != '/us/' + user
)
64 $(this).find('.id').append($(this).find('.r0').size() ? tick() : xmark());
67 if(location
.pathname
.match(/^\/st\//) || location
.pathname
== '/us/')
68 $('table').find('tbody').find('tr').each(function() {
69 if($(this).find('.user').find('a').attr('href') == '/us/' + user
)
70 $(this).addClass('info tracker-info');
74 function start_tracking(user
){
75 localStorage
.setItem('tracker_username', user
);
76 $('#tracker_userlink').attr('href', '/us/' + user
).html(user
);
77 $('#tracker_tracking').removeClass('hidden');
79 var lastfetch
= localStorage
.getItem('tracker_lastfetch');
80 if(Date
.now() - lastfetch
> 60 * 10 * 1000)
84 function refresh_tracker(){
85 var user
= localStorage
.getItem('tracker_username');
86 var xhr
= new XMLHttpRequest();
87 xhr
.open('GET', '/us/' + user
+ '?format=json');
88 xhr
.onload = function () {
89 localStorage
.setItem('tracker_data', this.responseText
);
90 localStorage
.setItem('tracker_lastfetch', Date
.now());
95 window
.refresh_tracker
= refresh_tracker
;
96 window
.start_tracking
= start_tracking
;
98 function stop_tracking(){
100 localStorage
.removeItem('tracker_username');
101 localStorage
.removeItem('tracker_data');
102 localStorage
.removeItem('tracker_lastfetch');
103 $('#tracker_tracking').addClass('hidden');
106 $( document
).ready(function(){
107 $('#tracker').detach().prependTo($('#sidebar'));
108 $('#tracker_stop').on('click', stop_tracking
);
109 $('#track_user').on('click', function() { stop_tracking(); start_tracking($(this).data('user')) });
110 $('#submitform').on('submit', function() { localStorage
.removeItem('tracker_lastfetch') });
112 if(localStorage
.getItem('tracker_username'))
113 start_tracking(localStorage
.getItem('tracker_username'));
This page took 0.057515 seconds and 4 git commands to generate.