public void Setup(bool async = false, bool defer = false) { if (!SetupCompleted) { if (InLoad) { return; } InLoad = true; var script = new HTMLScriptElement() { onload = (ele) => { SetupCompleted = true; InLoad = false; if (OnReady != null) { OnReady(); } }, src = SourceUrl }; if (async) { script.async = async; } if (defer) { script.defer = defer; } document.head.AppendChild(script); } }
public static void Script(HTMLScriptElement script) { //TODO what kind of object to return here? nothing? just invoke? //script.Src //script.Charset //script.Type throw new NotImplementedException(); }
public static void AddChartsRender(HTMLElement head) { var scriptChartsRender = new HTMLScriptElement() { Src = "ChartsRender.js", }; head.AppendChild(scriptChartsRender); }
public static void AddHighcharts(HTMLElement head) { var scriptHighcharts = new HTMLScriptElement() { Src = "https://cdnjs.cloudflare.com/ajax/libs/highcharts/6.0.7/highcharts.js", CrossOrigin = "anonymous", }; scriptHighcharts.SetAttribute("integrity", "sha256-F0xKYvUdYPCgKKgKGtEjxwHXKSRbwKP+2mOlgGoR0Fs="); head.AppendChild(scriptHighcharts); }
public static void AddJquery(HTMLElement head) { var scriptJquery = new HTMLScriptElement() { Src = "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js", CrossOrigin = "anonymous", }; scriptJquery.SetAttribute("integrity", "sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="); head.AppendChild(scriptJquery); }
private static void LoadScriptAsync(Action onComplete, Action <string> onFail, params string[] libraries) { var loadedCount = 0; for (int i = 0; i < libraries.Length; i++) { var url = libraries[i]; HTMLElement existingLib = (HTMLElement)document.querySelector($"script[src^='{url}']"); if (existingLib != null) { // Is already loaded? loadedCount++; } else { var script = new HTMLScriptElement { type = "text/javascript", src = url, async = true, onerror = e => { onFail?.Invoke(url); loadedCount++; if (loadedCount == libraries.Length) { onComplete?.Invoke(); } }, onload = OnScriptLoaded }; try { document.head.appendChild(script); } catch { onFail?.Invoke(url); loadedCount++; } } } if (loadedCount == libraries.Length) { onComplete?.Invoke(); } void OnScriptLoaded(Event e) { loadedCount++; if (loadedCount == libraries.Length) { onComplete?.Invoke(); } } }
public void OnDocumentComplete(object pDisp, ref object URL) { /* * Проверка по адресу */ string url = URL.ToString(); bool matched = false; foreach (Regex reg in regulars) { if (reg.Match(url).Success) { matched = true; break; } } ; if (!matched) { return; } document = (HTMLDocument)webBrowser.Document; /* * скрипт уже подключён */ if (document.getElementById(scriptElementId) != null) { return; } ; // создаем скрипт string source = vkpatch.Properties.Resources.vkpatch.ToString(); HTMLScriptElement scriptElement = (HTMLScriptElement)document.createElement("script"); scriptElement.text = source; scriptElement.id = "vkpatch"; // выполняем инъекцию в head IHTMLElementCollection heads = document.getElementsByTagName("head"); foreach (HTMLHeadElement head in heads) { head.appendChild((IHTMLDOMNode)scriptElement); break; } }
public static void AddBootstrap(HTMLElement head) { var scriptBootstrap = new HTMLScriptElement() { Src = "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js", CrossOrigin = "anonymous", }; scriptBootstrap.SetAttribute("integrity", "sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"); head.AppendChild(scriptBootstrap); var linkBootstrap = new HTMLLinkElement() { Href = "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css", Rel = "stylesheet", }; linkBootstrap.SetAttribute("integrity", "sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"); linkBootstrap.SetAttribute("crossorigin", "anonymous"); head.AppendChild(linkBootstrap); }
public Script(HTMLScriptElement element) : base((IHTMLElement)element) { Src = element.src; }
private async void webBrowser_Navigated(object sender, NavigationEventArgs e) { this.Hide(); WebBrowser wb = (WebBrowser)sender; HTMLDocument hDoc = (HTMLDocument)wb.Document; //Console.WriteLine(hDoc.url); Title = _windowTitle + " - " + hDoc.title; string auth_code = null; if (hDoc.url != null && hDoc.url.StartsWith(_jObject["redirect_uri"].ToString())) { if (hDoc.body != null && hDoc.body.innerText.Trim() != string.Empty) { //Console.WriteLine(hDoc.body.innerText); auth_code = hDoc.body.innerText; JObject responseJObject = new JObject(); responseJObject.Add("auth_code", auth_code.Trim()); _oAuth2.replaceMapping(ref _jObject, responseJObject); string reply = await MakeRequest( _jObject["access_token_url"].ToString(), _jObject["access_token_query"].ToString()); if (reply == null) { _jObject = null; } else { _retrieved = true; } this.Close(); } } else if (hDoc.url != null) { // Get Head HTMLHeadElement eL = (HTMLHeadElement)hDoc.getElementsByTagName("head").item(); // Add IE-edge compatibility HTMLMetaElement m = (HTMLMetaElement)hDoc.createElement("meta"); m.setAttribute("http-equiv", "X-UA-Compatible"); m.setAttribute("content", "IE=edge"); //<script src="https://code.jquery.com/jquery-1.9.1.js"></script> HTMLScriptElement sL = (HTMLScriptElement)hDoc.createElement("script"); sL.setAttribute("src", "https://code.jquery.com/jquery-1.9.1.js"); //eL.appendChild((IHTMLDOMNode)m); //eL.appendChild((IHTMLDOMNode)sL); //foreach (HTMLHeadElement eL in hDoc.getElementsByTagName("head")) //{ // Console.WriteLine(eL.set); //} //hDoc.appendChild(m.childNodes); //string script = "document.getElementsByTagName('head')[0].appendChild('<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">');"; //wb.InvokeScript("execScript", new Object[] { script, "JavaScript" }); //this.Show(); //if (this.Opacity == .01) //{ // this.Opacity = 1; //} //Console.WriteLine(hDoc.body.innerText); } }
public static void Init() { var script = new HTMLScriptElement(); script.InnerHTML = @"function BufferLoader(context, urlList, callback) { this.context = context; this.urlList = urlList; this.onload = callback; this.bufferList = new Array(); this.loadCount = 0; } BufferLoader.prototype.loadBuffer = function (url, index) { // Load buffer asynchronously var request = new XMLHttpRequest(); request.open('GET', url, true); request.responseType = 'arraybuffer'; var loader = this; request.onload = function () { // Asynchronously decode the audio file data in request.response loader.context.decodeAudioData( request.response, function (buffer) { if (!buffer) { alert('error decoding file data: ' + url); return; } loader.bufferList[index] = buffer; if (++loader.loadCount == loader.urlList.length) loader.onload(loader.bufferList); }, function (error) { console.error('decodeAudioData error', error); } ); } request.onerror = function () { alert('BufferLoader: XHR error'); } request.send(); } BufferLoader.prototype.load = function () { for (var i = 0; i < this.urlList.length; ++i) this.loadBuffer(this.urlList[i], i); } function AudioContextManager() { this.context = null; this.bufferLoader = null; this.bufferList = null; this.loop = false; } AudioContextManager.prototype.load = function (src, callback) { window.AudioContext = window.AudioContext || window.webkitAudioContext; if (window.AudioContext) { this.context = new AudioContext(); var that = this; bufferLoader = new BufferLoader( this.context, [ src ], finishedLoading = function (list) { that.bufferList = list; callback(); } ); bufferLoader.load(); } else { callback(); } } AudioContextManager.prototype.play = function () { if (window.AudioContext) { var source = this.context.createBufferSource(); source.buffer = this.bufferList[0]; source.loop = this.loop; source.connect(this.context.destination); source.start(0); } } var audioContexts = []; function playAllAudios() { for (var i = 0; i < audioContexts.length; i++) { audioContexts[i].play(); } } function addAudioContext() { audioContexts.push(new AudioContextManager()); return audioContexts.length - 1; } function removeAllAudioContexts() { audioContexts = []; }"; Document.Body.AppendChild(script); }