]>
iEval git - gruntmaster-page.git/blob - js/90-tracker.js
1 var TICK
= '<span class="tick tracker-mark">✔</span>';
2 var XMARK
= '<span class="x tracker-mark">✘</span>';
4 function clean_tracker(){
5 $('.tracker-mark').each(function(e
){
6 e
.parentNode
.removeChild(e
);
8 $('.tracker-info').each(function(e
){
9 e
.classList
.remove('tracker-info');
10 e
.classList
.remove('info');
16 function update_tracker(){
17 var data
= localStorage
.getItem('tracker_data');
18 var user
= localStorage
.getItem('tracker_username');
21 data
= JSON
.parse(data
);
26 data
.problems
.forEach(function(e
){
28 solved
[e
.problem
] = 1;
31 attempted
[e
.problem
] = 1;
37 data
.contests
.forEach(function(e
){
38 contests
[e
.contest
] = 1;
42 $('#tracker_userlink')[0].innerHTML
= data
.name
;
43 $('#tracker_solved')[0].innerHTML
= solvednr
;
44 $('#tracker_attempted')[0].innerHTML
= attemptednr
;
45 $('#tracker_contests')[0].innerHTML
= data
.contests
.length
;
46 $('#tracker_log')[0].setAttribute('href', '/log/?owner=' + user
);
48 if(location
.pathname
== '/pb/')
49 $('table .name a').each(function(el
) {
50 var id
= el
.getAttribute('href').split('?', 2)[0];
52 el
.insertAdjacentHTML('beforebegin', TICK
);
53 else if(attempted
[id
])
54 el
.insertAdjacentHTML('beforebegin', XMARK
);
57 if(location
.pathname
== '/ct/')
58 $('table .name a').each(function(el
) {
59 var id
= el
.getAttribute('href').substr(4);
61 el
.insertAdjacentHTML('beforebegin', TICK
);
64 if(location
.pathname
== '/log/')
65 $('table tbody tr').each(function(el
) {
66 var owner
= el
.querySelector('.owner a');
67 if(!owner
|| owner
.getAttribute('href') != '/us/' + user
)
69 var state
= el
.getElementsByClassName('r0').length
? TICK
: XMARK
;
70 el
.getElementsByClassName('id')[0].innerHTML
+= state
;
73 if(location
.pathname
.match(/^\/st\//) || location
.pathname
== '/us/')
74 $('table tbody tr').each(function(el
) {
75 if(el
.querySelector('.user a').getAttribute('href') == '/us/' + user
){
76 el
.classList
.add('info');
77 el
.classList
.add('tracker-info');
82 function start_tracking(user
){
83 localStorage
.setItem('tracker_username', user
);
84 $('#tracker_userlink')[0].setAttribute('href', '/us/' + user
);
85 $('#tracker_userlink')[0].innerHTML
= user
;
86 tracker
.classList
.remove('hidden');
88 var lastfetch
= localStorage
.getItem('tracker_lastfetch');
89 if(Date
.now() - lastfetch
> 60 * 10 * 1000)
93 function refresh_tracker(){
94 var user
= localStorage
.getItem('tracker_username');
95 var xhr
= new XMLHttpRequest();
96 xhr
.open('GET', '/us/' + user
+ '?format=json');
97 xhr
.onload = function () {
98 localStorage
.setItem('tracker_data', this.responseText
);
99 localStorage
.setItem('tracker_lastfetch', Date
.now());
105 function stop_tracking(){
107 localStorage
.removeItem('tracker_username');
108 localStorage
.removeItem('tracker_data');
109 localStorage
.removeItem('tracker_lastfetch');
110 tracker
.classList
.add('hidden');
114 tracker
= m('<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>');
115 var sidebar
= $('#sidebar')[0];
116 sidebar
.insertBefore(tracker
, sidebar
.firstChild
);
117 $('#tracker_stop').on('click', stop_tracking
);
118 $('#track_user').on('click', function() { stop_tracking(); start_tracking(this.dataset
.user
) });
119 $('#submitform').on('submit', function() { localStorage
.removeItem('tracker_lastfetch') });
121 if(localStorage
.getItem('tracker_username'))
122 start_tracking(localStorage
.getItem('tracker_username'));
This page took 0.055972 seconds and 4 git commands to generate.