private void SrsMain() {
/* Updated SRS (21/11/2016) */
WebBrowser.Execute(@"
/* Test if content is available and fix register buttons in events list */
[].forEach.call(document.querySelectorAll('input[id^=""btn""][value=""""]'), function(e){
var s = e.parentNode.childNodes[[].indexOf.call(e.parentNode.childNodes, e) + 1].innerHTML;
var t = /top\.__AC\.findTrack\('([^']+)'/.test(s) && RegExp.$1 || null;
var c = []; s.replace(/top\.__AC\.findCar\('([^']+)'/g, function(_, i){ c.push(i); });
e.value = window.external.ContentExists(t, JSON.stringify(c)) ? 'Register' : 'Missing';
});
/* Set next race params */
var o = {}, found = false;
/* Take quit URL from its button */
try {
var quitButton = document.querySelector('input[onclick*=""unregsrs.php""]');
var quitUrl = location.host + '/' + quitButton.getAttribute('onclick').match(/'(?:\.\/)?([^']*unregsrs[^']+)'/)[1];
quitButton.onclick = function(){ location = '//' + quitUrl; };
o['quit'] = quitUrl;
} catch(e){}
/* Go through every script tag and analyze stuff */
[].forEach.call(document.querySelectorAll('script'), function(e){
var s = e.innerHTML;
if (s.indexOf('top.__AC.findTrack(') !== -1){
o['track'] = /top\.__AC\.findTrack\('([^']+)'/.test(s) ? RegExp.$1 : null;
o['car'] = /top\.__AC\.Cars\.(\w+)/.test(s) ? RegExp.$1 : null;
}
if (s.indexOf('new Countdown(') !== -1 && /\s+time:(\d+),/.test(s)){
o['time'] = +RegExp.$1;
}
if (/\$\('#mainbuttondiv'\).load\('([^']+)'/.test(s) && window.$){
$.ajax(RegExp.$1).done(function(r){
r.replace(/\/\/setsetting\/race\?(\w+\/\w+)=([^']*)/g, function(_, k, v){ o[k] = v == '' ? null : v; });
window.external.SetParams(JSON.stringify(o));
});
found = true;
}
});
if (!found){
window.external.SetParams(null);
}
/* Catch all $.get requests */
if (window.$){
if (!$._get_orig) $._get_orig = $.get;
$.get = function(p){
var s = p.split('?');
switch (s[0]){
case 'ac://start/':
window.external.Go();
break;
case 'ac://setsetting/race':
if (/^(\w+\/\w+)=([\s\S]*)$/.test(s[1])){
window.external.SetParam(RegExp.$1, RegExp.$2);
}
break;
default:
$._get_orig.apply($, arguments);
break;
}
};
}
/* Modify car’s block until data will arrive (outside) */
if (o['car']){
var e = document.querySelector('#' + o['car'] + '4');
if (e) e.textContent = 'Please, wait…';
}
/* Set car names */
/*[].forEach.call(document.querySelectorAll('#regdriversupdate td:nth-child(3)'), function(e){
e.textContent = window.external.GetCarName(e.textContent.trim());
});*/", true);
}