OLD | NEW |
1 data = null; | 1 data = null; |
2 idx = 0; | 2 idx = 0; |
3 | 3 |
4 nextUpdateId = 0; | 4 nextUpdateId = 0; |
5 | 5 |
6 urlHolder = document.querySelector('#url-holder'); | 6 urlHolder = document.querySelector('#url-holder'); |
7 dataTable = document.querySelector('#data-table'); | 7 dataTable = document.querySelector('#data-table'); |
8 $dataRows = null; | 8 $dataRows = null; |
9 | 9 |
10 baseImage = document.querySelector('#base-img'); | 10 baseImage = document.querySelector('#base-img'); |
11 distilledImage = document.querySelector('#distilled-img'); | 11 distilledImage = document.querySelector('#distilled-img'); |
| 12 baseImageNext = document.querySelector('#base-img-next'); |
| 13 distilledImageNext = document.querySelector('#distilled-img-next'); |
| 14 baseImageNext2 = document.querySelector('#base-img-next2'); |
| 15 distilledImageNext2 = document.querySelector('#distilled-img-next2'); |
12 imageHolder = document.querySelector('#image-holder'); | 16 imageHolder = document.querySelector('#image-holder'); |
13 | 17 |
14 goodButton = document.querySelector('#good'); | 18 goodButton = document.querySelector('#good'); |
15 badButton = document.querySelector('#bad'); | 19 badButton = document.querySelector('#bad'); |
16 resetButton = document.querySelector('#reset'); | 20 resetButton = document.querySelector('#reset'); |
17 poorButton = document.querySelector('#poor'); | 21 poorButton = document.querySelector('#poor'); |
18 errorButton = document.querySelector('#error'); | 22 errorButton = document.querySelector('#error'); |
19 | 23 |
| 24 jumpCheck = document.getElementById('auto-advance'); |
| 25 |
| 26 goodCount = document.querySelector('#good-count'); |
| 27 badCount = document.querySelector('#bad-count'); |
| 28 poorCount = document.querySelector('#poor-count'); |
| 29 errorCount = document.querySelector('#error-count'); |
| 30 |
20 function changeIndex(newIndex) { | 31 function changeIndex(newIndex) { |
21 var oldIndex = idx; | 32 var oldIndex = idx; |
22 idx = Math.max(0, Math.min(data.length - 1, newIndex)); | 33 idx = Math.max(0, Math.min(data.length - 1, newIndex)); |
23 showImage(idx); | 34 showImage(idx); |
24 $dataRows.eq(oldIndex).removeClass('active'); | 35 $dataRows.eq(oldIndex).removeClass('active'); |
25 var $currentRow = $dataRows.eq(idx); | 36 var $currentRow = $dataRows.eq(idx); |
26 $currentRow.addClass('active'); | 37 $currentRow.addClass('active'); |
27 $currentRow[0].scrollIntoViewIfNeeded(); | 38 $currentRow[0].scrollIntoViewIfNeeded(); |
| 39 urlHolder.scrollIntoViewIfNeeded(); |
28 $('.current-position').text(idx + 1); | 40 $('.current-position').text(idx + 1); |
| 41 window.location.hash = data[idx]['index']; |
| 42 } |
| 43 |
| 44 function updateCount() { |
| 45 goodCount.innerText = document.querySelectorAll('tr[class*="good"]').length |
| 46 badCount.innerText = document.querySelectorAll('tr[class*="bad"]').length |
| 47 poorCount.innerText = document.querySelectorAll('tr[class*="poor"]').length |
| 48 errorCount.innerText = document.querySelectorAll('tr[class*="error"]').length |
29 } | 49 } |
30 | 50 |
31 function recordValue(v) { | 51 function recordValue(v) { |
32 var e = data[idx]; | 52 var e = data[idx]; |
33 e['good'] = v; | 53 e['good'] = v; |
34 updateTableRow(idx); | 54 updateTableRow(idx); |
35 sendUpdate(e, function() { | 55 sendUpdate(e, function() { |
36 changeIndex(idx + 1); | 56 changeIndex(nextIndex(idx)); |
37 }); | 57 }); |
| 58 updateCount(); |
38 } | 59 } |
39 | 60 |
40 function recordGood() { | 61 function recordGood() { |
41 recordValue(1); | 62 recordValue(1); |
42 } | 63 } |
43 | 64 |
44 function recordBad() { | 65 function recordBad() { |
45 recordValue(0); | 66 recordValue(0); |
46 } | 67 } |
47 | 68 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 goodButton.onclick = recordGood | 118 goodButton.onclick = recordGood |
98 badButton.onclick = recordBad | 119 badButton.onclick = recordBad |
99 resetButton.onclick = resetEntry | 120 resetButton.onclick = resetEntry |
100 errorButton.onclick = recordError | 121 errorButton.onclick = recordError |
101 $('.right-caret').click(skip); | 122 $('.right-caret').click(skip); |
102 $('.left-caret').click(back); | 123 $('.left-caret').click(back); |
103 | 124 |
104 function showImage(i) { | 125 function showImage(i) { |
105 goodButton.disabled = false; | 126 goodButton.disabled = false; |
106 badButton.disabled = false; | 127 badButton.disabled = false; |
107 var e = data[i] | 128 var e = data[i]; |
108 baseImage.src = '/images/' + e['screenshot'].replace(/.*\//, '') | 129 baseImage.src = '/images/' + e['screenshot'].replace(/.*\//, ''); |
109 distilledImage.src = '/images/' + e['distilled'].replace(/.*\//, '') | 130 distilledImage.src = '/images/' + e['distilled'].replace(/.*\//, ''); |
110 urlHolder.innerText = e['url'] | 131 urlHolder.innerText = decodeURI(e['url']); |
111 urlHolder.href = e['url'] | 132 urlHolder.href = e['url']; |
112 imageHolder.classList.remove('bad'); | 133 imageHolder.classList.remove('bad'); |
113 imageHolder.classList.remove('good'); | 134 imageHolder.classList.remove('good'); |
114 imageHolder.classList.remove('error'); | 135 imageHolder.classList.remove('error'); |
115 imageHolder.classList.remove('poor'); | 136 imageHolder.classList.remove('poor'); |
116 if (typeof e['good'] != 'undefined') { | 137 if (typeof e['good'] != 'undefined') { |
117 imageHolder.classList.add( | 138 imageHolder.classList.add( |
118 e['good'] == 1 | 139 e['good'] == 1 |
119 ? 'good' | 140 ? 'good' |
120 : e['good'] == -1 | 141 : e['good'] == -1 |
121 ? 'error' | 142 ? 'error' |
122 : e['good'] == 2 | 143 : e['good'] == 2 |
123 ? 'poor' | 144 ? 'poor' |
124 : 'bad'); | 145 : 'bad'); |
125 } | 146 } |
| 147 var n = data[i + 1]; |
| 148 if (n) { |
| 149 baseImageNext.src = '/images/' + n['screenshot'].replace(/.*\//, ''); |
| 150 distilledImageNext.src = '/images/' + n['distilled'].replace(/.*\//, ''); |
| 151 } |
| 152 n = data[nextUnrated(i)]; |
| 153 if (n) { |
| 154 baseImageNext2.src = '/images/' + n['screenshot'].replace(/.*\//, ''); |
| 155 distilledImageNext2.src = '/images/' + n['distilled'].replace(/.*\//, ''); |
| 156 } |
126 } | 157 } |
127 | 158 |
| 159 function nextIndex(i) { |
| 160 return jumpCheck.checked ? nextUnrated(i) : (i + 1); |
| 161 } |
| 162 |
| 163 function nextUnrated(i) { |
| 164 i += 1; |
| 165 while (i < data.length) { |
| 166 var e = data[i]; |
| 167 if (typeof e['good'] == 'undefined') { |
| 168 return i; |
| 169 } |
| 170 i += 1; |
| 171 } |
| 172 return -1; |
| 173 } |
| 174 |
| 175 |
128 function updateTableRow(i) { | 176 function updateTableRow(i) { |
129 var row = dataTable.querySelectorAll('tr')[i]; | 177 var row = dataTable.querySelectorAll('tr')[i]; |
130 row.classList.remove('good'); | 178 row.classList.remove('good'); |
131 row.classList.remove('bad'); | 179 row.classList.remove('bad'); |
132 row.classList.remove('error'); | 180 row.classList.remove('error'); |
133 row.classList.remove('poor'); | 181 row.classList.remove('poor'); |
134 var e = data[i]; | 182 var e = data[i]; |
135 if (typeof e['good'] != 'undefined') { | 183 if (typeof e['good'] != 'undefined') { |
136 row.classList.add( | 184 row.classList.add( |
137 e['good'] == 1 | 185 e['good'] == 1 |
138 ? 'good' | 186 ? 'good' |
139 : e['good'] == -1 | 187 : e['good'] == -1 |
140 ? 'error' | 188 ? 'error' |
141 : e['good'] == 2 | 189 : e['good'] == 2 |
142 ? 'poor' | 190 ? 'poor' |
143 : 'bad'); | 191 : 'bad'); |
144 } | 192 } |
145 if (i == idx) { | 193 if (i == idx) { |
146 // forces ui update | 194 // forces ui update |
147 changeIndex(idx); | 195 changeIndex(idx); |
148 } | 196 } |
149 } | 197 } |
150 | 198 |
151 function createTable() { | 199 function createTable() { |
152 var dataRows = []; | 200 var dataRows = []; |
153 for (var i = 0; i < data.length; i++) { | 201 for (var i = 0; i < data.length; i++) { |
154 row = document.createElement('tr'); | 202 row = document.createElement('tr'); |
155 cell = document.createElement('td'); | 203 cell = document.createElement('td'); |
156 row.appendChild(cell); | 204 row.appendChild(cell); |
157 cell.appendChild(document.createTextNode(data[i]['url'])); | 205 cell.appendChild(document.createTextNode(decodeURI(data[i]['url']))); |
158 dataTable.appendChild(row); | 206 dataTable.appendChild(row); |
159 dataRows.push(row); | 207 dataRows.push(row); |
160 } | 208 } |
161 | 209 |
162 $dataRows = $(dataRows); | 210 $dataRows = $(dataRows); |
163 | 211 |
164 $dataRows.each(function(i, r) { | 212 $dataRows.each(function(i, r) { |
165 $(r).click(function() { | 213 $(r).click(function() { |
166 console.log(i); | 214 console.log(i); |
167 // forces ui update | 215 // forces ui update |
168 changeIndex(i); | 216 changeIndex(i); |
169 }); | 217 }); |
170 }) | 218 }) |
171 } | 219 } |
172 | 220 |
173 function setData(d, i) { | 221 function setData(d) { |
174 var needsTable = data == null; | 222 var needsTable = data == null; |
175 data = d; //.slice(0, 100); | 223 data = d; //.slice(0, 100); |
176 $('.total-entries').text(data.length); | 224 $('.total-entries').text(data.length); |
177 if (needsTable) { | 225 if (needsTable) { |
178 createTable(); | 226 createTable(); |
179 } | 227 } |
| 228 idx = getHashIndex(); |
| 229 if (idx == -1) { |
| 230 idx = Math.floor(Math.random() * data.length); |
| 231 } |
180 for (var i = 0; i < data.length; i++) { | 232 for (var i = 0; i < data.length; i++) { |
181 updateTableRow(i); | 233 updateTableRow(i); |
182 } | 234 } |
| 235 updateCount(); |
183 } | 236 } |
184 | 237 |
185 function handleVisibilityChange() { | 238 function handleVisibilityChange() { |
186 if (!document.hidden) sendGetUpdates(1000); | 239 if (!document.hidden) sendGetUpdates(1000); |
187 } | 240 } |
188 | 241 |
189 function getData() { | 242 function getData() { |
190 sendMessage( | 243 sendMessage( |
191 'POST', | 244 'POST', |
192 { | 245 { |
193 'action': 'getData' | 246 'action': 'getData' |
194 }, | 247 }, |
195 function(rsp) { | 248 function(rsp) { |
196 document.addEventListener('visibilitychange', handleVisibilityChange, fa
lse); | 249 document.addEventListener('visibilitychange', handleVisibilityChange, fa
lse); |
197 var data = rsp['response']['data']; | 250 var data = rsp['response']['data']; |
198 nextUpdateId = rsp['response']['nextId']; | 251 nextUpdateId = rsp['response']['nextId']; |
199 setData(data); | 252 setData(data); |
200 var startIndex = parseInt(window.location.hash.substr(1)) - 1; | |
201 if (isNaN(startIndex)) { | |
202 startIndex = 0; | |
203 } | |
204 changeIndex(startIndex); | |
205 sendGetUpdates(1000); | 253 sendGetUpdates(1000); |
206 } | 254 } |
207 ); | 255 ); |
208 } | 256 } |
209 | 257 |
210 | 258 |
211 getUpdatesSent = false; | 259 getUpdatesSent = false; |
212 function sendGetUpdates(delay) { | 260 function sendGetUpdates(delay) { |
213 if (document.hidden) return; | 261 if (document.hidden) return; |
214 if (getUpdatesSent) return; | 262 if (getUpdatesSent) return; |
(...skipping 22 matching lines...) Expand all Loading... |
237 var u = updates[i]; | 285 var u = updates[i]; |
238 var idx = u['index']; | 286 var idx = u['index']; |
239 var entry = u['entry']; | 287 var entry = u['entry']; |
240 var curr = data[idx]; | 288 var curr = data[idx]; |
241 if (curr['url'] != entry['url']) { | 289 if (curr['url'] != entry['url']) { |
242 console.error(curr, entry); | 290 console.error(curr, entry); |
243 } | 291 } |
244 data[idx] = entry; | 292 data[idx] = entry; |
245 updateTableRow(idx); | 293 updateTableRow(idx); |
246 } | 294 } |
| 295 updateCount(); |
247 nextUpdateId = nextUpdateId; | 296 nextUpdateId = nextUpdateId; |
248 delay = 1000; | 297 delay = 1000; |
249 } else { | 298 } else { |
250 delay = Math.min(30 * 1000, 1.5 * delay); | 299 delay = Math.min(30 * 1000, 1.5 * delay); |
251 } | 300 } |
252 console.log('xx: response: ', response, delay); | 301 console.log('xx: response: ', response, delay); |
253 sendGetUpdates(delay); | 302 sendGetUpdates(delay); |
254 }, | 303 }, |
255 'dataType': 'json', | 304 'dataType': 'json', |
256 }); | 305 }); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 switch (e.which) { | 341 switch (e.which) { |
293 case 37: // <-- | 342 case 37: // <-- |
294 back(); | 343 back(); |
295 break; | 344 break; |
296 case 39: // >-- | 345 case 39: // >-- |
297 skip(); | 346 skip(); |
298 break; | 347 break; |
299 } | 348 } |
300 }); | 349 }); |
301 }); | 350 }); |
| 351 |
| 352 function getHashIndex() { |
| 353 if (!window.location.hash) { |
| 354 return -1; |
| 355 } |
| 356 index = parseInt(window.location.hash.substr(1)); |
| 357 if (isNaN(index)) { |
| 358 return -1; |
| 359 } |
| 360 if (data && parseInt(data[idx]['index']) == index) { |
| 361 return idx; |
| 362 } |
| 363 for (var i = 0; i < data.length; i++) { |
| 364 if (parseInt(data[i]['index']) == index) { |
| 365 return i; |
| 366 } |
| 367 } |
| 368 return -1; |
| 369 } |
| 370 |
| 371 $(window).on('hashchange', function () { |
| 372 hashIdx = getHashIndex(); |
| 373 if (hashIdx != idx) { |
| 374 changeIndex(hashIdx); |
| 375 } |
| 376 }); |
OLD | NEW |