public WebBrowserHtmlCatalog(System.Windows.Forms.HtmlDocument doc, params string[] fragments) { foreach (var fragment in fragments) { var container = doc.CreateElement("div"); container.InnerHtml = fragment; var root = container.Children[0]; var exports = root.Children.OfType <System.Windows.Forms.HtmlElement>().Where(e => !String.IsNullOrEmpty(e.GetAttribute(exportAttributeName))); if (exports.Any()) { foreach (var export in exports) { htmlParts.Add(new HTMLComposablePartDefinition(export)); } } } }
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { if (e.Url.AbsolutePath != (sender as WebBrowser).Url.AbsolutePath) { return; } if (menuItems[0].Text.Equals("Stop")) { if (webBrowser1.Url.ToString() == "https://impweb.cuny.edu/oam/Portal_Login1.html") { System.Windows.Forms.HtmlDocument source = webBrowser1.Document; HtmlElement head = source.GetElementsByTagName("head")[0]; HtmlElement s = source.CreateElement("script"); s.SetAttribute("text", "document.getElementById('login').value = '" + textBox1.Text + "'; void(0);"); head.AppendChild(s); s.SetAttribute("text", "document.getElementById('password').value = '" + textBox2.Text + "'; void(0);"); head.AppendChild(s); s.SetAttribute("text", "document.getElementsByName(\"submit\")[0].click();"); head.AppendChild(s); } else if (webBrowser1.Url.ToString().Contains("https://impweb.cuny.edu/oam/InvalidLogin.html")) { trayIcon.ShowBalloonTip(1000, "Class Notifier", "Invalid login. Please check your username/password.", ToolTipIcon.Error); timer1.Enabled = false; menuItems[0].Text = "Start"; menuItems[1].Enabled = true; } else if (webBrowser1.Url.ToString() == "https://impweb.cuny.edu/xlWebApp/") { trayIcon.ShowBalloonTip(1000, "Class Notifier", "Successfully logged in. Will now run in the background and check for classes every " + textBox3.Text + " seconds.", ToolTipIcon.Info); webBrowser1.Navigate("https://hrsa.cunyfirst.cuny.edu/psc/cnyhcprd/EMPLOYEE/HRMS/c/SA_LEARNER_SERVICES.SSR_SSENRL_CART.GBL?"); } else if (webBrowser1.Url.ToString() == "https://hrsa.cunyfirst.cuny.edu/psc/cnyhcprd/EMPLOYEE/HRMS/c/SA_LEARNER_SERVICES.SSR_SSENRL_CART.GBL?&") { HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument(); string source = webBrowser1.DocumentText; htmlDoc.LoadHtml(source); var pageTitle = htmlDoc.GetElementbyId("DERIVED_REGFRM1_SS_TRANSACT_TITLE"); if (pageTitle != null) { if (pageTitle.InnerText == "Add Classes") { checkClasses(); timer1.Enabled = true; } } else { System.Windows.Forms.HtmlDocument source1 = webBrowser1.Document; HtmlElement head = source1.GetElementsByTagName("head")[0]; HtmlElement s = source1.CreateElement("script"); s.SetAttribute("text", "var buttons = document.getElementsByName(\"SSR_DUMMY_RECV1$sels$0\"); buttons[1].checked = true; void(0);"); head.AppendChild(s); s.SetAttribute("text", "submitAction_win0(document.win0, 'DERIVED_SSS_SCT_SSR_PB_GO');"); head.AppendChild(s); } } //confirm classes if (webBrowser1.Url.ToString().Contains("https://hrsa.cunyfirst.cuny.edu/psc/cnyhcprd/EMPLOYEE/HRMS/c/SA_LEARNER_SERVICES.SSR_SSENRL_ADD.GBL?Page=SSR_SSENRL_ADD_C")) { webBrowser1.Navigate("javascript: document.getElementsByName(\"DERIVED_REGFRM1_SSR_PB_SUBMIT\")[0].click();"); } //finished enrolling if (webBrowser1.Url.ToString() == "https://hrsa.cunyfirst.cuny.edu/psc/cnyhcprd/EMPLOYEE/HRMS/c/SA_LEARNER_SERVICES.SSR_SSENRL_ADD.GBL") { trayIcon.ShowBalloonTip(1000, "Class Notifier", "Finished enrolling. Will continue checking for other classes to open.", ToolTipIcon.Info); } } }
private HtmlElement GetScript(HtmlDocument pDoc) { HtmlElement script; script = pDoc.CreateElement("script"); script.SetAttribute("id", "CUITe_Script"); script.SetAttribute("type", "text/javascript"); script.SetAttribute("text", @" var isCodeLanguageVB = " + isCodeLanguageVB.ToString().ToLowerInvariant() + @"; var oStyle; var sCode; var sOutHtml; var sFilter; var objInQuestion; var vTempCounter = 0; /** * http://www.javascripttoolbox.com/lib/objectposition/source.php * Copyright (c)2005-2009 Matt Kruse (javascripttoolbox.com) * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * 'Software'), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ var Position = (function() { // Resolve a string identifier to an object // ======================================== function resolveObject(s) { if (document.getElementById && document.getElementById(s) != null) { return document.getElementById(s); } else if (document.all && document.all[s] != null) { return document.all[s]; } else if (document.anchors && document.anchors.length && document.anchors.length > 0 && document.anchors[0].x) { for (var i = 0; i < document.anchors.length; i++) { if (document.anchors[i].name == s) { return document.anchors[i] } } } } var pos = {}; pos.$VERSION = 1.0; // Set the position of an object // ============================= pos.set = function(o, left, top) { if (typeof(o) == 'string') { o = resolveObject(o); } if (o == null || !o.style) { return false; } // If the second parameter is an object, it is assumed to be the result of getPosition() if (typeof(left) == 'object') { var pos = left; left = pos.left; top = pos.top; } o.style.left = left + 'px'; o.style.top = top + 'px'; o.style.width = pos.width; o.style.height = pos.height; return true; }; // Retrieve the position and size of an object // =========================================== pos.get = function(o) { var fixBrowserQuirks = true; // If a string is passed in instead of an object ref, resolve it if (typeof(o) == 'string') { o = resolveObject(o); } if (o == null) { return null; } var left = 0; var top = 0; var width = 0; var height = 0; var parentNode = null; var offsetParent = null; offsetParent = o.offsetParent; var originalObject = o; var el = o; // 'el' will be nodes as we walk up, 'o' will be saved for offsetParent references while (el.parentNode != null) { el = el.parentNode; if (el.offsetParent == null) { } else { var considerScroll = true; if (fixBrowserQuirks && window.opera) { if (el == originalObject.parentNode || el.nodeName == 'TR') { considerScroll = false; } } if (considerScroll) { if (el.scrollTop && el.scrollTop > 0) { top -= el.scrollTop; } if (el.scrollLeft && el.scrollLeft > 0) { left -= el.scrollLeft; } } } // If this node is also the offsetParent, add on the offsets and reset to the new offsetParent if (el == offsetParent) { left += o.offsetLeft; if (el.clientLeft && el.nodeName != 'TABLE') { left += el.clientLeft; } top += o.offsetTop; if (el.clientTop && el.nodeName != 'TABLE') { top += el.clientTop; } o = el; if (o.offsetParent == null) { if (o.offsetLeft) { left += o.offsetLeft; } if (o.offsetTop) { top += o.offsetTop; } } offsetParent = o.offsetParent; } } if (originalObject.offsetWidth) { width = originalObject.offsetWidth; } if (originalObject.offsetHeight) { height = originalObject.offsetHeight; } return {'left':left, 'top':top, 'width':width, 'height':height }; }; // Retrieve the position of an object's center point // ================================================= pos.getCenter = function(o) { var c = this.get(o); if (c == null) { return null; } c.left = c.left + (c.width / 2); c.top = c.top + (c.height / 2); return c; }; return pos; })(); document.onmouseover = function(e) { var evt = window.event || e; evt.returnValue = false; evt.cancelBubble = true; if (evt.stopPropagation) evt.stopPropagation(); objInQuestion = evt.srcElement; if (objInQuestion != null && objInQuestion.id != 'CUITe_div2') { if (sFilter != null && sFilter != 'Filter:') { objInQuestion = FindParentForFilter(objInQuestion); } if (objInQuestion != null && !isElementIframe(objInQuestion.nodeName)) { sOutHtml = objInQuestion.outerHTML; var posdic = Position.get(objInQuestion); var divTag2 = AddDiv2(); divTag2.style.left = posdic.left + 'px'; divTag2.style.top = parseInt(posdic.top) + 4 + parseInt(posdic.height) + 'px'; divTag2.style.width = document.body.clientWidth - posdic.left - 10; divTag2.innerHTML = '<span style=\'background:orange;\'><xmp>' + sOutHtml + '</xmp></span>'; oStyle = objInQuestion.style.cssText; objInQuestion.style.border = '2px solid red'; } } } document.onmouseout = function(e) { var evt = window.event || e; evt.returnValue = false; evt.cancelBubble = true; if (evt.stopPropagation) evt.stopPropagation(); if (objInQuestion != null && objInQuestion.id != 'CUITe_div2') { objInQuestion.style.cssText = oStyle; document.getElementById('CUITe_div2').style.visibility = 'hidden'; } } document.onclick = function(e) { var evt = window.event || e; evt.returnValue = false; evt.cancelBubble = true; if (evt.stopPropagation) evt.stopPropagation(); if (event.preventDefault) event.preventDefault(); sCode = isCodeLanguageVB ? 'Public ReadOnly Property var() As type Get Return Find(Of type)(By.SearchProperties(searchparams)) End Get End Property' : 'public type var { get { return Find<type>(By.SearchProperties(searchparams)); } }'; var sProperties = ''; var sNodeName, sNodeType, sId, sName, sClass, sInnerText, sTitle, sValue; if (objInQuestion != null && objInQuestion.id != 'CUITe_div2') { sNodeName = objInQuestion.nodeName != null ? objInQuestion.nodeName.toLowerCase() : ''; sNodeType = objInQuestion.getAttribute('type') != null ? objInQuestion.getAttribute('type').toLowerCase() : ''; sId = objInQuestion.id != null ? objInQuestion.id : ''; sName = objInQuestion.name != null ? objInQuestion.name : ''; sClass = objInQuestion.getAttribute('class') != null ? objInQuestion.getAttribute('class') : ''; sInnerText = objInQuestion.innerText != null ? objInQuestion.innerText : ''; sTitle = objInQuestion.getAttribute('title') != null ? objInQuestion.getAttribute('title') : ''; sValue = objInQuestion.getAttribute('value') != null ? objInQuestion.getAttribute('value') : ''; } var sVarPrefix; if (sNodeName == 'button') { sVarPrefix = 'btn'; sCode = sCode.replace(/type/g, 'HtmlButton'); } if (sNodeName == 'input' && (sNodeType == 'button' || sNodeType == 'submit' || sNodeType == 'image')) { sVarPrefix = 'btn'; sCode = sCode.replace(/type/g, 'HtmlInputButton'); } if (sNodeName == 'input' && sNodeType == 'checkbox') { sVarPrefix = 'chk'; sCode = sCode.replace(/type/g, 'HtmlCheckBox'); } if (sNodeName == 'input' && sNodeType == 'radio') { sVarPrefix = 'rad'; sCode = sCode.replace(/type/g, 'HtmlRadioButton'); } if (sNodeName == 'a') { sVarPrefix = 'lnk'; sCode = sCode.replace(/type/g, 'HtmlHyperlink'); } if (sNodeName == 'input' && sNodeType == 'text') { sVarPrefix = 'txt'; sCode = sCode.replace(/type/g, 'HtmlEdit'); } if (sNodeName == 'input' && sNodeType == 'password') { sVarPrefix = 'txt'; sCode = sCode.replace(/type/g, 'HtmlPassword'); } if (sNodeName == 'textarea') { sVarPrefix = 'txt'; sCode = sCode.replace(/type/g, 'HtmlTextArea'); } if (sNodeName == 'img') { sVarPrefix = 'img'; sCode = sCode.replace(/type/g, 'HtmlImage'); } if (sNodeName == 'table') { sVarPrefix = 'tbl'; sCode = sCode.replace(/type/g, 'HtmlTable'); } if (sNodeName == 'label') { sVarPrefix = 'lbl'; sCode = sCode.replace(/type/g, 'HtmlLabel'); } if (sNodeName == 'select') { sVarPrefix = 'cbo'; sCode = sCode.replace(/type/g, 'HtmlComboBox'); } if (sNodeName == 'div') { sVarPrefix = 'div'; sCode = sCode.replace(/type/g, 'HtmlDiv'); } if (sNodeName == 'span') { sVarPrefix = 'spn'; sCode = sCode.replace(/type/g, 'HtmlSpan'); } if (sNodeName == 'td') { sVarPrefix = 'cel'; sCode = sCode.replace(/type/g, 'HtmlCell'); } if (sId != '') { sProperties += ';Id=' + sId; } else { if (sName != '') { sProperties += ';Name=' + sName; } if (sClass != '') { sProperties += ';Class=' + sClass; } if (sName != '') { sProperties += ';Name=' + sName; } if (sInnerText != '') { sProperties += ';InnerText=' + sInnerText; } if (sTitle != '') { sProperties += ';Title=' + sTitle; } if (sValue != '') { sProperties += ';Value=' + sValue; } } sProperties = sProperties.substring(1); var sVarNameEval = setVarNameFromId(sId); if (sVarNameEval == '') { sVarNameEval = sVarPrefix + getVarName(sInnerText, sTitle, sValue, sName, sId).replace(/ /g, ''); } sCode = sCode.replace('searchparams', String.fromCharCode(34) + sProperties + String.fromCharCode(34)); sCode = isCodeLanguageVB ? sCode.replace(' var() ', ' ' + sVarNameEval + '() ') : sCode.replace(' var ', ' ' + sVarNameEval + ' '); top.sCode = sCode; } function isElementIframe(elementName) { return elementName !== undefined && elementName !== null && elementName.toString() === 'iframe'; } function AddDiv2() { var divTag2 = document.getElementById('CUITe_div2'); if (divTag2 == null) { divTag2 = document.createElement('div'); divTag2.id = 'CUITe_div2'; divTag2.style.margin = '0px auto'; divTag2.style.filter = 'alpha(opacity=\'100\')'; divTag2.style.position = 'fixed'; divTag2.style.wordWrap = 'break-word'; divTag2.style.zIndex = 77777; document.body.appendChild(divTag2); } divTag2.style.border = 'none'; divTag2.style.visibility = 'visible'; return divTag2; } function getValues() { return top.sCode; } function getHtmlCode() { return sOutHtml; } function removeScript() { var scriptele = document.getElementById('CUITe_Script'); scriptele.parentNode.removeChild(scriptele); scriptele = null; document.onmouseover = null; document.onmouseout = null; document.onclick = null; } function setVarNameFromId(sId) { var sVarEval = ''; if (sId.indexOf('_btn') > 0) { sVarEval = sId.substring(sId.indexOf('_btn') + 1); } else if (sId.indexOf('_chk') > 0) { sVarEval = sId.substring(sId.indexOf('_chk') + 1); } else if (sId.indexOf('_rad') > 0) { sVarEval = sId.substring(sId.indexOf('_rad') + 1); } else if (sId.indexOf('_txt') > 0) { sVarEval = sId.substring(sId.indexOf('_txt') + 1); } else if (sId.indexOf('_lst') > 0) { sVarEval = sId.substring(sId.indexOf('_lst') + 1); } else if (sId.indexOf('_cbo') > 0) { sVarEval = sId.substring(sId.indexOf('_cbo') + 1); } else if (sId.indexOf('_lnk') > 0) { sVarEval = sId.substring(sId.indexOf('_lnk') + 1); } else if (sId.indexOf('_dg') > 0) { sVarEval = sId.substring(sId.indexOf('_dg') + 1); } return sVarEval; } function getVarName(sInnerText, sTitle, sValue, sName, sId) { var sVarName; if (sInnerText != '') { sVarName = sInnerText; } else if (sTitle != '') { sVarName = sTitle; } else if (sValue != '') { sVarName = sValue; } else if (sName != '') { sVarName = sName; } else if (sId != '') { sVarName = sId; } sVarName = sVarName.camelCase(); sVarName = sVarName.replace(/ /g, ''); sVarName = sVarName.replace(/[^a-zA-Z 0-9]+/g, ''); if (sVarName.length > 25) { vTempCounter++; sVarName = 'Temp' + vTempCounter.toString(); } return sVarName; } function getWindowTitle() { return String.fromCharCode(34) + document.title + String.fromCharCode(34); } function getWinTitForClassName() { return document.title.camelCase().replace(/ /g, '').replace(/[^a-zA-Z 0-9]+/g, ''); } function setFilter(sFil) { sFilter = sFil; } function FindParentForFilter(child) { while (child.nodeName != sFilter) { child = child.parentNode; if (child != null) { return FindParentForFilter(child); } else { break; } } return child; } String.prototype.camelCase = function() { var s = this; return ( /\S[A-Z]/.test(s) ) ? s.replace(/(.)([A-Z])/g, function(t, a, b) { return a + ' ' + b.toUpperCase(); }) : s.replace(/( )([a-z])/g, function(t, a, b) { return b.toUpperCase(); }); }; "); return script; }
public void JQ(HtmlDocument HD) { HtmlElement HE = HD.CreateElement("SCRIPT"); HE.SetAttribute("src", "https://code.jquery.com/jquery-1.11.1.min.js"); HD.Body.AppendChild(HE); HtmlElement HE2 = HD.CreateElement("SCRIPT"); HE2.SetAttribute("text", Properties.Resources.attrNodeTopLeft); HD.Body.AppendChild(HE2); HD.InvokeScript("attrNodeTopLeft"); }
void webLogs_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { logDoc = webLogs.Document; logDocRaw = (IHTMLDocument2)logDoc.DomDocument; IHTMLStyleSheet ss = logDocRaw.createStyleSheet("", 0); ss.cssText = Properties.Resources.defaultTemplate; var myScript = logDoc.CreateElement("script"); ((IHTMLScriptElement)myScript.DomElement).text = Properties.Resources.hoverJavaScript; // logDoc.Body.AppendChild(myStyle); logDoc.Body.AppendChild(myScript); Debug.WriteLine(logDoc.Body.InnerHtml); }