]>
iEval git - gruntmaster-page.git/blob - js/90-tracker.js
1fa4905ed0887ba2f36221591fb3fe59b6b3bdb2
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');
14 function update_tracker(){
15 var data
= localStorage
.getItem('tracker_data');
16 var user
= localStorage
.getItem('tracker_username');
19 data
= JSON
.parse(data
);
24 data
.problems
.forEach(function(e
){
26 solved
[e
.problem
] = 1;
29 attempted
[e
.problem
] = 1;
35 data
.contests
.forEach(function(e
){
36 contests
[e
.contest
] = 1;
40 $('#tracker_userlink').html(data
.name
);
41 $('#tracker_solved').html(solvednr
);
42 $('#tracker_attempted').html(attemptednr
);
43 $('#tracker_contests').html(data
.contests
.length
);
44 $('#tracker_log').attr('href', '/log/?owner=' + user
);
46 if(location
.pathname
== '/pb/')
47 $('table').find('.name').find('a').each(function() {
48 var id
= $(this).attr('href').split('?', 2)[0];
50 $(this).parent().prepend(tick());
51 else if(attempted
[id
])
52 $(this).parent().prepend(xmark());
55 if(location
.pathname
== '/ct/')
56 $('table').find('.name').find('a').each(function() {
57 var id
= $(this).attr('href').substr(4);
59 $(this).parent().prepend(tick());
62 if(location
.pathname
== '/log/')
63 $('table').find('tbody').find('tr').each(function() {
64 if($(this).find('.owner').find('a').attr('href') != '/us/' + user
)
66 $(this).find('.id').append($(this).find('.r0').size() ? tick() : xmark());
69 if(location
.pathname
.match(/^\/st\//) || location
.pathname
== '/us/')
70 $('table').find('tbody').find('tr').each(function() {
71 if($(this).find('.user').find('a').attr('href') == '/us/' + user
)
72 $(this).addClass('info tracker-info');
76 function start_tracking(user
){
77 localStorage
.setItem('tracker_username', user
);
78 $('#tracker_userlink').attr('href', '/us/' + user
).html(user
);
79 tracker
.removeClass('hidden');
81 var lastfetch
= localStorage
.getItem('tracker_lastfetch');
82 if(Date
.now() - lastfetch
> 60 * 10 * 1000)
86 function refresh_tracker(){
87 var user
= localStorage
.getItem('tracker_username');
88 var xhr
= new XMLHttpRequest();
89 xhr
.open('GET', '/us/' + user
+ '?format=json');
90 xhr
.onload = function () {
91 localStorage
.setItem('tracker_data', this.responseText
);
92 localStorage
.setItem('tracker_lastfetch', Date
.now());
97 window
.refresh_tracker
= refresh_tracker
;
98 window
.start_tracking
= start_tracking
;
100 function stop_tracking(){
102 localStorage
.removeItem('tracker_username');
103 localStorage
.removeItem('tracker_data');
104 localStorage
.removeItem('tracker_lastfetch');
105 tracker
.addClass('hidden');
108 $( document
).ready(function(){
109 tracker
= $('<div id="tracker" class="hidden">Tracking <a id="tracker_userlink"></a>.<br><a id="tracker_stop" role="button">Stop tracking</a><br><a id="tracker_log">Job log</a><dl class="dl-horizontal"><dt>Solved</dt> <dd id="tracker_solved">?</dd><dt>Attempted</dt> <dd id="tracker_attempted">?</dd><dt>Contests</dt> <dd id="tracker_contests">?</dd></dl></div>');
110 tracker
.prependTo($('#sidebar'));
111 $('#tracker_stop').on('click', stop_tracking
);
112 $('#track_user').on('click', function() { stop_tracking(); start_tracking($(this).data('user')) });
113 $('#submitform').on('submit', function() { localStorage
.removeItem('tracker_lastfetch') });
115 if(localStorage
.getItem('tracker_username'))
116 start_tracking(localStorage
.getItem('tracker_username'));
This page took 0.052187 seconds and 3 git commands to generate.