Skip to content

Commit 097bda3

Browse files
authored
Remove technical event information (#389)
* Remove references to Technical_Event_Information * Assume listed events have started
1 parent e67c542 commit 097bda3

File tree

12 files changed

+40
-26748
lines changed

12 files changed

+40
-26748
lines changed

browser-extensions/chrome/manifest.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"description": "Adds challenge progress information to your parkrun athlete results page.",
66
"version": "REPLACE_EXTENSION_BUILD_VERSION.REPLACE_EXTENSION_BUILD_ID",
77

8-
"content_security_policy": "default-src 'self'; connect-src https://www.parkrun.org.uk https://wiki.parkrun.com https://running-challenges.co.uk https://images.parkrun.com",
8+
"content_security_policy": "default-src 'self'; connect-src https://www.parkrun.org.uk https://running-challenges.co.uk https://images.parkrun.com",
99

1010
"browser_action": {
1111
"default_icon": "images/logo/logo-128x128.png"
@@ -192,8 +192,7 @@
192192
"/css/*"
193193
],
194194
"permissions": [
195-
"storage",
196-
"https://wiki.parkrun.com/"
195+
"storage"
197196
],
198197
"options_ui": {
199198
"page": "html/options.html",

browser-extensions/common/js/background.js

Lines changed: 8 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,6 @@ var cache = {
7676
'timeout': 5000,
7777
'last_status': {}
7878
},
79-
'technical_event_information': {
80-
'raw_data': undefined,
81-
'updated_at': undefined,
82-
'last_update_attempt': undefined,
83-
'updating': false,
84-
'max_age': 3 * 24 * 60 * 60 * 1000,
85-
'url': "https://wiki.parkrun.com/index.php/Technical_Event_Information",
86-
'datatype': 'html',
87-
'enabled': true,
88-
'timeout': 5000,
89-
'last_status': {}
90-
},
9179
'data': undefined,
9280
'updated_at': undefined
9381
}
@@ -143,9 +131,6 @@ function get_cache_summary() {
143131
'events': {
144132
'updated_at': cache.events.updated_at
145133
},
146-
'technical_event_information': {
147-
'updated_at': cache.technical_event_information.updated_at
148-
}
149134
}
150135
}
151136

@@ -174,7 +159,6 @@ function get_cache_summary() {
174159

175160
function clear_cache() {
176161
clear_cache_by_name("events")
177-
clear_cache_by_name("technical_event_information")
178162
}
179163

180164
function clear_cache_by_name(name) {
@@ -289,114 +273,14 @@ function addEventToCountryData(data, country_name, event_id, event_name) {
289273
data.countries[country_name]["child_event_names"].push(event_name)
290274
}
291275

292-
function parse_tee_data_event_status(data, result) {
293-
294-
var parseSuccess = false
295-
296-
if (result !== undefined) {
297-
298-
// Reset the event status data to a blank map
299-
data.event_status = {}
300-
301-
// console.log("Attempting to load the Technical Event Information into a virtual DOM")
302-
// var ownerDocument = document.implementation.createHTMLDocument('virtual');
303-
// Load the results into a virtual document, so that it doesn't attempt to load
304-
// inline scripts etc...
305-
// Solution taken from https://stackoverflow.com/questions/15113910/jquery-parse-html-without-loading-images
306-
// referencing https://api.jquery.com/jQuery/ & https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation/createHTMLDocument
307-
308-
// This ends up with a shed load of errors about:
309-
// Refused to apply inline style because it violates the following Content Security Policy directive:
310-
// "default-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-0EZqoz+oBhx7gF4nvY2bSqoGyy4zLjNF+SDQXGp/ZrY='),
311-
// or a nonce ('nonce-...') is required to enable inline execution. Note also that 'style-src' was not explicitly set,
312-
// so 'default-src' is used as a fallback.
313-
// This seems to be because loading the document inlines the styles, which I'd quite happily do away with
314-
// if only I knew how to.
315-
316-
// I have abandoned using the HTML parser directly as it brings too much baggage, instead
317-
// we will parse the wiki page as an XML document until we get to the row we are interested
318-
// in, and then only parse that as a HTML document - thus skipping all the scripts and other
319-
// junk the page loads in elsewhere and it will be as clean as possible.
320-
// This does mean we have to do a few odd things to make a valid HTML doc, but it does mean it
321-
// throws no security errors anymore, and we still get the data we want.
322-
323-
console.log("Attempting to load the Technical Event Information into an XML document")
324-
var xmlDoc = $.parseXML(result)
325-
326-
$(xmlDoc).find('div[id=mw-content-text]>table:first').each(function(table_index) {
327-
var content_table = $(this)
328-
// console.log(content_table)
329-
330-
content_table.find('tr').each(function(row_index) {
331-
// Reconstitute a valid document with a top level tag for the HTML parser
332-
var row_html_content = "<tr>"+$(this).html()+"</tr>"
333-
// Parse it into a JQuery object
334-
var html_row = $(row_html_content)
335-
// Find the td elements
336-
var content_table_row_cell = $('td', html_row)
337-
// Only attempt to parse it if there are enough cells
338-
if (content_table_row_cell[0] !== undefined) {
339-
if (content_table_row_cell.length >= 5) {
340-
var parkrun_info = {
341-
parkrun_name: content_table_row_cell[0].innerText.trim(),
342-
parkrun_event_director: content_table_row_cell[1].innerText.trim(),
343-
parkrun_event_number: content_table_row_cell[2].innerText.trim(),
344-
parkrun_status: content_table_row_cell[3].innerText.trim(),
345-
parkrun_country: content_table_row_cell[4].innerText.trim()
346-
}
347-
data.event_status[parkrun_info.parkrun_event_number] = parkrun_info
348-
// Note that we've parsed at least something successfully.
349-
parseSuccess = true
350-
// console.log(parkrun_info)
351-
}
352-
} else {
353-
// Don't bother printing that the top row is malformed, it's probably the header,
354-
// we'll just flag up if one of the other rows is weird.
355-
if (row_index != 0) {
356-
console.log("Techincal Event Information table row is malformed on row "+row_index+": "+JSON.stringify(content_table_row_cell))
357-
}
358-
}
359-
})
360-
})
361-
console.log("Technical Event Information processing complete")
362-
363-
console.log(Object.keys(data.event_status).length + " event statuses available")
364-
365-
}
366-
367-
return parseSuccess
368-
369-
}
370-
371-
function compute_event_status(data) {
372-
373-
if (data === undefined) {
374-
return
375-
}
376-
377-
// Loop through the existing geo_data, and supplement it with the
378-
// extra event data we have found if there is a match
379-
$.each(data.events, function(event_name, event_info) {
380-
if (data.event_status !== undefined && event_info.id in data.event_status) {
381-
// console.log('Found state '+live_parkrun_event_data[event_info.id].parkrun_status+" for "+event_name)
382-
data.events[event_name].status = data.event_status[event_info.id].parkrun_status
383-
} else {
384-
data.events[event_name].status = 'unknown'
385-
}
386-
})
387-
388-
return
389-
390-
}
391-
392276
function get_geo_data(notify_func, freshen=false) {
393277
var now = new Date()
394278

395279
// Work out if any of the files in 'cache' need updating
396280
// and construct a parallel ajax call to fetch whichever ones we need
397281
// this allows for easy extension in the future by adding data sources
398282
// with not a lot of code changes
399-
var data_sources = ['events', 'technical_event_information']
283+
var data_sources = ['events']
400284
var ajax_calls = []
401285
// Make a not if any deferred ajax calls are created
402286
var update_needed = false
@@ -458,7 +342,7 @@ function get_geo_data(notify_func, freshen=false) {
458342
// retrieved data.
459343
$.when( ajax_calls[0], ajax_calls[1] ).done(
460344
// 20191117 - data_geo replaced with data_events
461-
function ( data_events, data_tee ) {
345+
function ( data_events ) {
462346

463347
// We absolutely need the events data, without which we can't do
464348
// anything.
@@ -478,37 +362,31 @@ function get_geo_data(notify_func, freshen=false) {
478362
console.log('Fresh data available')
479363
}
480364

481-
// Check if we have technical event information and fall back if not
482-
if (data_tee === undefined) {
483-
data_tee = cache.technical_event_information.raw_data
484-
}
485-
486-
update_cache_data(data_events, data_tee)
365+
update_cache_data(data_events)
487366

488367
notify_geo_data(notify_func)
489368
return
490369
}
491370
)
492371
} else {
493372
// Just return the cached data
494-
console.log('Returning cached data for TEE & Geo Data')
373+
console.log('Returning cached data for Geo Data')
495374
notify_geo_data(notify_func)
496375
}
497376

498377
}
499378

500379
function regenerate_cache_data() {
501-
update_cache_data(cache.events.raw_data, cache.technical_event_information.raw_data)
380+
update_cache_data(cache.events.raw_data)
502381
}
503382

504-
function update_cache_data(data_events, data_tee) {
383+
function update_cache_data(data_events) {
505384

506385
if (data_events === undefined) {
507386
cache.data = {
508387
'valid': false,
509388
'data_fetch_status': {
510-
'events': cache.events.last_status,
511-
'event_info': cache.technical_event_information.last_status
389+
'events': cache.events.last_status
512390
}
513391
}
514392
cache.updated_at = undefined
@@ -523,27 +401,13 @@ function update_cache_data(data_events, data_tee) {
523401
'countries': {},
524402
'event_status': undefined,
525403
'data_fetch_status': {
526-
'events': cache.events.last_status,
527-
'event_info': cache.technical_event_information.last_status
404+
'events': cache.events.last_status
528405
}
529406
}
530407

531408
// Replace the complicated events/regions parsing with a single call
532409
parse_events(data, data_events)
533410

534-
// If the technical event information has been obtained, then
535-
// lets parse that.
536-
var parseResult = parse_tee_data_event_status(data, data_tee)
537-
console.log("Techincal Event Information parse result: "+parseResult)
538-
// If the page hasn't been fetched, or the file can't be parsed, parseResult will be false.
539-
// We should do something with that value, like mark that the page should be fetched again.
540-
541-
// This could potentially do nothing if no event info is available
542-
compute_event_status(data)
543-
// console.log(data)
544-
// Create the heirachy of events by region
545-
// compute_geo_data_heirachy(data)
546-
547411
// Update the global cache
548412
cache.data = data
549413
cache.updated_at = new Date()
@@ -607,10 +471,6 @@ function notify_geo_data(f) {
607471
clear_cache_by_name("events")
608472
done = true
609473
break
610-
case "cache-tei-clear":
611-
clear_cache_by_name("technical_event_information")
612-
done = true
613-
break
614474
case "cache-get":
615475
if (cache.data) {
616476
msg = JSON.stringify(cache.data,null,2)
@@ -632,14 +492,6 @@ function notify_geo_data(f) {
632492
cache.events.enabled = false
633493
done = true
634494
break
635-
case "enable-tei":
636-
cache.technical_event_information.enabled = true
637-
done = true
638-
break
639-
case "disable-tei":
640-
cache.technical_event_information.enabled = false
641-
done = true
642-
break
643495
}
644496
if (done) {
645497
sendResponse({

browser-extensions/common/js/content-scripts/content-script-parkrunner.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -623,18 +623,14 @@ function create_page() {
623623
if (!has_geo_data(data)) {
624624
errors.push('! Unable to fetch parkrun event location data: Stats, Challenges, and Maps requiring locations are not available !')
625625
}
626-
if (data.info.has_geo_technical_event_data == false) {
627-
errors.push('! Unable to fetch parkrun event status data: Stats and Challenges, e.g. Regionnaire, may include events that haven\'t started yet !')
628-
}
629-
630626

631627
// Add our final status message
632628
set_complete_progress_message(errors)
633629

634630
}).catch(error => {
635631
console.log(error)
636632
console.error(`An error occurred: ${error}`);
637-
set_progress_message(`Error: ${error}. Data is ${JSON.stringify(data)}`)
633+
set_progress_message(`Error: ${error}. Stack: ${error.stack}. Data is ${JSON.stringify(data)}`)
638634
});
639635

640636
}

browser-extensions/common/js/lib/challenges.js

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -537,8 +537,7 @@ function computeDistanceToParkrunsFromEvent(geo_data, fromEvent) {
537537
var eventDistances = {}
538538

539539
$.each(geo_data.data.events, function (event_name, event_info) {
540-
// Filter on live events, or if we don't know, include it anyway
541-
if ((event_info.status == 'Live' || event_info.status == 'unknown') && event_info.lat && event_info.lon) {
540+
if (event_info.lat && event_info.lon) {
542541
eventDistances[event_name] = calculate_great_circle_distance(event_info, fromEvent)
543542
}
544543
})
@@ -1197,7 +1196,7 @@ function generate_stat_nearest_event_not_done_yet(parkrun_results, geo_data, hom
11971196
Object.keys(geo_data.data.events).forEach(function(event_name) {
11981197
var event_info = geo_data.data.events[event_name]
11991198
if (!(event_name in events_run)) {
1200-
if ((event_info.status == 'Live' || event_info.status == 'unknown') && event_info.lat && event_info.lon) {
1199+
if (event_info.lat && event_info.lon) {
12011200
event_distances[event_name] = calculate_great_circle_distance(event_info, home_parkrun_info)
12021201
}
12031202
}
@@ -1464,13 +1463,11 @@ function group_global_events_by_containing_word(geo_data, words) {
14641463
})
14651464

14661465
$.each(geo_data.data.events, function (event_name, event_info) {
1467-
if (event_info.status == 'Live' || event_info.status == 'unknown') {
1468-
$.each(words, function(index, word) {
1469-
if (event_contains_word(event_name, word)) {
1470-
events[word].push(event_info)
1471-
}
1472-
})
1473-
}
1466+
$.each(words, function(index, word) {
1467+
if (event_contains_word(event_name, word)) {
1468+
events[word].push(event_info)
1469+
}
1470+
})
14741471
})
14751472

14761473
return events
@@ -1484,15 +1481,13 @@ function group_global_events_by_initial_letter(geo_data) {
14841481
// $.each(geo_data.data.events, function (event_name, event_info) {
14851482
Object.keys(geo_data.data.events).forEach(function(event_name) {
14861483
var event_info = geo_data.data.events[event_name]
1487-
1488-
if (event_info.status == 'Live' || event_info.status == 'unknown') {
1489-
// 'shortname' sorts by URL name, 'name' sorts by actual name
1490-
event_letter = get_initial_letter(event_info["name"])
1491-
if (events[event_letter] === undefined) {
1492-
events[event_letter] = []
1493-
}
1494-
events[event_letter].push(event_info)
1484+
1485+
// 'shortname' sorts by URL name, 'name' sorts by actual name
1486+
event_letter = get_initial_letter(event_info["name"])
1487+
if (events[event_letter] === undefined) {
1488+
events[event_letter] = []
14951489
}
1490+
events[event_letter].push(event_info)
14961491
})
14971492

14981493
return events
@@ -2868,20 +2863,11 @@ function calculateCountryCompletionInfo(data) {
28682863
var countryCompletionInfo = {}
28692864
// Pre-populate information about each country
28702865
$.each(data.geo_data.data.countries, function(countryName, countryInfo) {
2871-
// Find out how many of the events are active
2872-
var countryActiveEvents = 0
2873-
countryInfo['child_event_names'].forEach(function(eventName){
2874-
var eventInfo = data.geo_data.data.events[eventName]
2875-
if (eventInfo.status == 'Live' || eventInfo.status == 'unknown') {
2876-
countryActiveEvents += 1
2877-
}
2878-
})
28792866
// Initialise an information object for the country
28802867
countryCompletionInfo[countryName] = {
28812868
"name": countryName,
28822869
"id": countryInfo["id"],
28832870
"childEventsCount": countryInfo['child_event_names'].length,
2884-
"childActiveEventsCount": countryActiveEvents,
28852871
"childEventsCompleted": [],
28862872
"childEventsCompletedCount": 0,
28872873
"firstRanOn": undefined,

0 commit comments

Comments
 (0)