private void SrsMainOld() { /* Old SRS (let’s keep it for now just in case) */ WebBrowser.Execute(@" /* User is not registered to any race yet, hide params */ var b = document.querySelector('[onclick*=""REMOTE/REQUESTED_CAR""]'); if (!b){ window.external.SetParams(null); return; } /* Set next race params */ var o = {}; b.getAttribute('onclick').replace(/\/\/setsetting\/race\?(\w+\/\w+)=([^']*)/g, function(_, k, v){ o[k] = v == '' ? null : v; }); try { o['time'] = +b.parentNode.querySelector('script').innerHTML.match(/time:(\d+)/)[1]; } catch(e){} try { if (b.value == 'Quit'){ o['quit'] = location.host + '/' + b.getAttribute('onclick').match(/'(?:\.\/)?([^']*unregsrs[^']+)'/)[1]; } } catch(e){} window.external.SetParams(JSON.stringify(o)); b.removeAttribute('onclick'); b.addEventListener('click', function (){ window.external.Go(); }, false)", true); }
private void WebBrowser_OnPageLoaded(object sender, PageLoadedEventArgs e) { var uri = e.Url; var match = Regex.Match(uri, @"\beventId=(\d+)"); if (match.Success) { Model.EventId = match.Groups[1].Value; } else { var trackId = Regex.Match(uri, @"\btrack(?:Id)?=(\d+)"); var carId = Regex.Match(uri, @"\bcar(?:Id)?=(\d+)"); if (trackId.Success && carId.Success) { Model.EventId = trackId.Groups[1].Value + @"/" + carId.Groups[1].Value; } else { Model.EventId = null; } } if (uri.Contains(@"page=setups")) { WebBrowser.Execute(@" window.addEventListener('load', function(){ var ths = document.getElementsByTagName('th'); for (var i=0; i<ths.length; i++) if (ths[i].innerHTML == 'Download') ths[i].innerHTML = 'Install'; var hs = document.getElementsByTagName('a'); for (var i=0, m; i<hs.length; i++) if (m = hs[i].href.match(/=download_setup&id=(\d+)/)) hs[i].href = 'acmanager://rsr/setup?id=' + m[1]; }, false);"); } }
private void SrsSelectCar() { WebBrowser.Execute(@" /* Fix cars list */ var a = []; var b = document.querySelectorAll('[onclick*=""./regsrs.php?""]'); for (var i = 0; i < b.length; i++){ var c = (b[i].getAttribute('onclick').match(/&h=(\w+)/)||{})[1]; if (c) a.push(c); } window.external.SetCars(JSON.stringify(a));", true); }
private void OnPageLoaded(object sender, PageLoadedEventArgs e) { WebBrowser.Execute(@" document.addEventListener('mouseup', function(){ window.external.Update(window.getSelection().toString()); }, false); document.addEventListener('mousedown', function(e){ if (e.target.getAttribute('target') == '_blank'){ e.target.setAttribute('target', '_parent'); } }, false);"); }
private void SrsCommon() { WebBrowser.Execute($@" /* Set user Steam ID */ var g = document.getElementById('gui'); if (g){{ g.innerHTML = {JsonConvert.SerializeObject(SteamIdHelper.Instance.Value ?? "")}; }} else {{ window.external.Log('Nothing to set GUID to (' + location + ')'); }} /* Modify labels */ var t = document.querySelector('#shoutbox input.text'); if (t){{ t.setAttribute('placeholder', 'Join the chat'); }}", true); }
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); }