예제 #1
0
        /// <summary>
        /// 挑入网页加载完毕监听
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Pickwebbrowser_LoadCompleted(object sender, NavigationEventArgs e)
        {
            string uri = pickWebBrowser.Source.ToString();

            if (pickurl.IndexOf(uri) > -1)
            {
                //页面加载完毕执行挑入
                IHTMLDocument2      pickdoc = (IHTMLDocument2)pickWebBrowser.Document;
                IHTMLWindow2        pickwin = (IHTMLWindow2)pickdoc.parentWindow;
                mshtml.HTMLDocument htmlDoc = pickWebBrowser.Document as mshtml.HTMLDocument;
                var head   = htmlDoc.getElementsByTagName("head").Cast <HTMLHeadElement>().First();
                var script = (IHTMLScriptElement)htmlDoc.createElement("script");
                script.src = "https://demo.22com.cn/crm/json2.js";
                head.appendChild((IHTMLDOMNode)script);
                InjectJs inject = new InjectJs(this.pickWebBrowser);
                Thread   thr    = new Thread(() =>
                {
                    //这里还可以处理些比较耗时的事情。
                    Thread.Sleep(1000);//延时10秒
                    this.Dispatcher.Invoke(new Action(() =>
                    {
                        pickwin.execScript(inject.getOverridePickInJs(), "javascript");
                        pickwin.execScript("_shy_.alert_close();", "javascript");//关闭弹窗JS
                        pickwin.execScript("selectOpp.getWidget('').select(0,true);", "javascript");
                        pickwin.execScript("overrDoPick()", "javascript");
                    }));
                });
                thr.Start();
            }
        }
 /// <summary>
 /// 待HTML页面加载完毕修改HTML内容
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void WebBrowser_LoadCompleted(object sender, NavigationEventArgs e)
 {
     try
     {
         HTMLDocument doc = webBrowser.Document as HTMLDocument;//定义HTML
         if (doc == null)
         {
             MessageBox.Show("页面加载失败!", "信息", MessageBoxButton.OK, MessageBoxImage.Error);
             return;
         }
         ;
         //获取窗体
         IHTMLWindow2 window = doc.parentWindow;
         //注入javascript
         StringBuilder script = new StringBuilder();
         script.Append("document.getElementsByTagName('iframe')[0].parentNode.parentNode.parentNode.parentNode.parentNode.style.display='none';");
         //script.Append("document.body.childNodes[7].style.display = 'none';");
         script.Append("document.body.getElementsByTagName('table')[3].style.display = 'none';");
         script.Append("document.body.getElementsByTagName('table')[0].style.display = 'none';");
         script.Append("document.body.getElementsByTagName('div')[0].style.display='none';");
         window.execScript(script.ToString(), "javascript");
     }
     catch (Exception exception)
     {
         LogHelper.Error(exception);
         MessageBox.Show(exception.Message, "信息", MessageBoxButton.OK, MessageBoxImage.Exclamation);
     }
 }
예제 #3
0
        private void SendCodeButton_Click(object sender, RoutedEventArgs e)
        {
            var result = SendCode(_currentDevice.DeviceAddress);

            if (result == null)
            {
                return;
            }
            var errorMessage = result.ErrorMessage;

            if (!String.IsNullOrWhiteSpace(errorMessage))
            {
                if (errorMessage.StartsWith("___EXCEPTION_____At offset: "))
                {
                    var exceptionBody  = errorMessage.Substring("___EXCEPTION_____At offset: ".Length);
                    var exceptionParts = exceptionBody.Split(new[] { "__" }, StringSplitOptions.None);
                    var codeOffset     = int.Parse(exceptionParts[0]) - 1;

                    var position = CodeEditor.Document.CurrentSnapshot.OffsetToPosition(codeOffset);

                    ShowLineError(position.Line + 1, exceptionParts[1]);
                }
                LogToResultsWindow(errorMessage);
            }
            else if (result.Results != null)
            {
                _htmlHolder.innerHTML = String.Join("", result.Results.Select(r => "<h1>" + r.ResultKey + "</h1>" + DumpToXhtml.Dump(r.ResultValue, 0).ToString()));
                _htmlWindow.execScript("Update();", "javascript");
            }
        }
예제 #4
0
        private void SkinButton4_Click(object sender, EventArgs e) //## 断开连接函数
        {
            if (!LoginInternet.checkInternetLink())
            {
                return;
            }

            LoginBW.Url = new Uri("http://down.gwifi.com.cn/");
            while (LoginBW.ReadyState != WebBrowserReadyState.Complete)
            {
                System.Windows.Forms.Application.DoEvents();
            }
            IHTMLDocument2 id2 = LoginBW.Document.DomDocument as IHTMLDocument2;
            IHTMLWindow2   win = id2.parentWindow;

            try
            {
                win.execScript("loginout()", "javascript");
            }
            finally
            {
                GiwifiReg.unALLsettingregedt32();
            }
            //timeOut(2000);
            LoginBW.Url = new Uri("http://down.gwifi.com.cn/");
            while (LoginBW.ReadyState != WebBrowserReadyState.Complete)
            {
                System.Windows.Forms.Application.DoEvents();
            }
            InternetLight(); // 刷新
            GiwifiReg.unALLsettingregedt32();
        }
예제 #5
0
        private void BrowserSubway_LoadCompleted(object sender, NavigationEventArgs e)
        {
            try
            {
                HTMLDocument doc = BrowserSubway.Document as HTMLDocument;
                //获取窗体
                IHTMLWindow2 window = doc.parentWindow;
                //注入javascript
                StringBuilder script = new StringBuilder();
                script.Append("if(document.getElementById('loginmenu')){document.getElementById('loginmenu').style.display='none';}");
                script.Append("if(document.getElementById('huoche_nav')){document.getElementById('huoche_nav').style.display='none';}");
                script.Append("if(document.getElementById('huoche_topbar')){document.getElementById('huoche_topbar').style.display='none';}");
                script.Append("if(document.getElementsByTagName('table')[0]){ document.getElementsByTagName('table')[0].children[0].children[0].children[1].style.display='none';}");
                script.Append("if(document.getElementById('footer')){ document.getElementById('footer').style.display='none';}");

                //script.Append("if(document.getElementsByTagName('iframe')[0]){ document.getElementsByTagName('iframe')[1].style.display='none';document.getElementsByTagName('iframe')[0].style.display='none';}");
                //script.Append("if(document.getElementsByClassName('remenqu')[0]){ document.getElementsByClassName('remenqu')[0].style.display='none';}");
                //script.Append("if(document.getElementsByClassName('content')[0].children[4]){ document.getElementsByClassName('content')[0].children[4].style.display='none';}");
                //script.Append("if(document.getElementsByClassName('content')[0]){ document.getElementsByClassName('content')[0].children[0].children[0].children[0].style.display='none';}");
                //script.Append("if(document.getElementsByClassName('content')[0]){ document.getElementsByClassName('content')[0].children[0].children[0].children[2].style.display='none';}");

                script.Append("if(document.getElementById('BAIDU_SSP__wrapper_u616238_0')){document.getElementById('BAIDU_SSP__wrapper_u616238_0').style.display='none';}");
                window.execScript(script.ToString(), "javascript");

                ProgressBar.Visibility = Visibility.Collapsed;
                _timer.Stop();
            }
            catch (Exception exception)
            {
                LogHelper.Error(exception);
                MessageBox.Show(exception.Message, "信息", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
        }
예제 #6
0
 private async void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
 {
     //var host = new Uri(user.AreaValue).Host;
     if (e.Url.Host.EndsWith(".1360.com") || e.Url.Host.EndsWith(".frxz2.91wan.com") || e.Url.Host.EndsWith(".my4399.com"))
     {
         login_state = 1;
         serverProvider.SendMsg("game-start", user.GameHwnd);
         Gop_OnStateChange("在线");
         gop.operate("init", wb.Handle + "");
     }
     else
     {
         if (login_state == 1)
         {
             //if (gop != null)
             //{
             //    gop.Abort();
             //}
             return;
         }
         string code;
         var    is91   = e.Url.ToString().Contains("91wan.com/user/game_login.php");
         var    is4399 = e.Url.ToString().Contains("web.4399.com/user/login_game.php");
         if (is91)
         {
             code = File.ReadAllText("resources/enter91.js");
         }
         else if (is4399)
         {
             code = File.ReadAllText("resources/enter4399.js");
         }
         else
         {
             code = File.ReadAllText("resources/enter.js");
         }
         IHTMLWindow2 win = wb.Document.Window.DomWindow as IHTMLWindow2;
         //var win = (IHTMLWindow2)doc.parentWindow;
         code = code.Replace("{{Name}}", user.Name).Replace("{{Password}}", user.Password).Replace("{{AreaValue}}", user.AreaValue);
         //MessageBox.Show(code);
         while (login_state == 0 && wb.Url.AbsoluteUri == e.Url.AbsoluteUri)
         {
             //this.Text = new Random().Next().ToString();
             //await Task.Delay(1000);
             try
             {
                 win.execScript(code, "javascript");
                 if (is91 || is4399)
                 {
                     return;
                 }
             }
             catch (Exception)
             {
             }
             await Task.Delay(3000);
         }
     }
 }
예제 #7
0
        // 禁止alert跳出
        private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
        {
            IHTMLWindow2 win = (IHTMLWindow2)webBrowser1.Document.Window.DomWindow;
            string       s   = @"function confirm() {";

            s += @"return true;";
            s += @"}";
            s += @"function alert() {}";
            win.execScript(s, "javascript");
        }
예제 #8
0
        private void Login()
        {
            IHTMLDocument2 doc = (IHTMLDocument2)webBrowser.Document;

            doc.all.item("username").setAttribute("value", "wangcl2");
            doc.all.item("password").setAttribute("value", "314114");

            IHTMLWindow2 window = doc.parentWindow;

            window.execScript("login();");
        }
예제 #9
0
 /// <summary>
 /// Runs the script code in IE.
 /// </summary>
 /// <param name="scriptCode">The script code.</param>
 /// <param name="language">The language.</param>
 /// <param name="window">The parent window of the document.</param>
 public static void RunScript(string scriptCode, string language, IHTMLWindow2 window)
 {
     try
     {
         window.execScript(scriptCode, language);
     }
     catch (Exception ex)
     {
         throw new WatiN.Core.Exceptions.RunScriptException(ex);
     }
 }
예제 #10
0
 /// <summary>
 /// Runs the script code in IE.
 /// </summary>
 /// <param name="scriptCode">The script code.</param>
 /// <param name="language">The language.</param>
 /// <param name="window">The parent window of the document.</param>
 public static void RunScript(string scriptCode, string language, IHTMLWindow2 window)
 {
     try
     {
         window.execScript(scriptCode, language);
     }
     catch (Exception ex)
     {
         throw new RunScriptException(ex);
     }
 }
예제 #11
0
        private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
        {
            HtmlWindowCollection coll = (sender as WebBrowser).Document.Window.Frames;
            string       s            = "function alert(){}; function confirm(){ return true;};";//function open(){};function window.showModalDialog(){};";
            IHTMLWindow2 win1         = null;

            foreach (HtmlWindow win in coll)
            {
                win1 = (IHTMLWindow2)win.DomWindow;
                win1.execScript(s, "javascript");
            }
        }
예제 #12
0
 /// <summary>
 /// Runs the script code in IE.
 /// </summary>
 /// <param name="scriptCode">The script code.</param>
 /// <param name="language">The language.</param>
 /// <param name="window">The parent window of the document.</param>
 public static void RunScript(string scriptCode, string language, IHTMLWindow2 window)
 {
     try
     {
         Logger.LogDebug("[script] {0}", scriptCode);
         window.execScript(scriptCode, language);
     }
     catch (Exception ex)
     {
         throw new RunScriptException(ex);
     }
 }
예제 #13
0
        public void ccc()
        {
            string scriptline01 = @"function cccScript() {";

            string scriptline02 = @"$('.button_primary').click() } ";
            string scriptline03 = @"cccScript();";

            string       strScript = scriptline01 + scriptline02 + scriptline03;
            IHTMLWindow2 win       = (IHTMLWindow2)browser.Document.Window.DomWindow;

            win.execScript(strScript, "Javascript");
        }
예제 #14
0
 /// <summary>
 /// Runs the script code in IE.
 /// </summary>
 /// <param name="scriptCode">The script code.</param>
 /// <param name="language">The language.</param>
 public void RunScript(string scriptCode, string language)
 {
     try
     {
         IHTMLWindow2 window = htmlDocument.parentWindow;
         window.execScript(scriptCode, language);
     }
     catch (Exception ex)
     {
         throw new ItiN.Exceptions.RunScriptException(ex);
     }
 }
        /// <summary>
        /// Raised when a message is sent from the front process
        /// </summary>
        /// <param name="e"></param>
        /// <remarks>
        /// Only confort+ message are processed
        /// </remarks>
        private void OnMessage(object e)
        {
            try
            {
                MessageInfo message = MessageInfo.Create(e);



                IHTMLDocument2 document = this.webBrowser.Document as IHTMLDocument2;
                IHTMLWindow2   window   = document.parentWindow;

                switch (message.Message)
                {
                case "orangeconfort+userprefget":
                    this.LogInfo("orangeconfort+userprefget: Origin={0} Value={1} UserPref={2} blacklist={3}", message.Origin, message.Value, this.info.UserPref, this.info.Blacklist);

                    UriBuilder uriBuilder = new UriBuilder(message.Origin);

                    this.LogInfo("domain={0} blacklist flag={1}", uriBuilder.Host, this.info.GetBlackListFlag(uriBuilder.Host));


                    string script = "function timeoutSetStoredValue() {"
                                    + "if (!accessibilitytoolbar || accessibilitytoolbar == null || !accessibilitytoolbar.userPref || accessibilitytoolbar.userPref == null)"
                                    + "setTimeout(timeoutSetStoredValue,500);"
                                    + "else accessibilitytoolbar.userPref.setStoredValue(\"" + this.info.UserPref + this.info.GetBlackListFlag(uriBuilder.Host) + "\");"
                                    + "}"
                                    + "setTimeout(timeoutSetStoredValue,500);";

                    window.execScript(script);

                    break;

                case "orangeconfort+userprefsave":
                    this.LogInfo("orangeconfort+userprefsave: Value=" + message.Value);
                    this.info.UserPref = message.Value;
                    break;

                case "orangeconfort+blacklistsave":
                    this.LogInfo("orangeconfort+blacklistsave: Value=" + message.Value);
                    this.info.ToggleInBlacklist(message.Value);
                    break;

                case "orangeconfort+help":
                    this.LogInfo("orangeconfort+help: Value=" + message.Value);
                    this.webBrowser.Navigate2("cdu://Resources/help/help_" + message.Value + ".html", 2048);
                    break;
                }
            }
            catch (Exception ex)
            {
                this.LogError("ToggleService", ex);
            }
        }
예제 #16
0
        public void AddJavaScript()
        {
            string scriptline01 = @"function AddScript() {";
            string scriptline02 = @"$('.dialog_ft').parent().css({position:'relative'}); ";
            string scriptline04 = @"$('.dialog_ft').append(""<div id='ld' style ='width:190px;height:42px;position: absolute;z-index:500;margin-top:-42px; margin-left: 146px; '></div >"")  ;}";
            string scriptline05 = @"AddScript();";

            string       strScript = scriptline01 + scriptline02 + scriptline04 + scriptline05;
            IHTMLWindow2 win       = (IHTMLWindow2)browser.Document.Window.DomWindow;

            win.execScript(strScript, "Javascript");
        }
예제 #17
0
        /// <summary>
        /// 查询公司资源
        /// </summary>
        /// <param name="company"></param>
        private void InquireCompany(string company)
        {
            IHTMLDocument2 doc = (IHTMLDocument2)webBrower.Document;
            IHTMLWindow2   win = (IHTMLWindow2)doc.parentWindow;

            /**
             *$('input.shy-input[id]').eq(0).val('内容');//设置输入框内容
             *  searchFormContact.getWidget('')._setValue('0', 'companyName', '内容');//执行js
             *  searchOpportunity('viaContact')//搜索资源
             */
            win.execScript("$('input.shy-input[id]').eq(0).val('" + company + "');searchFormContact.getWidget('')._setValue('0', 'companyName', '" + company + "');searchOpportunity('viaContact');", "javascript");//使用JS
        }
예제 #18
0
파일: IEUtils.cs 프로젝트: exaphaser/WatiN
 /// <summary>
 /// Runs the script code in IE.
 /// </summary>
 /// <param name="scriptCode">The script code.</param>
 /// <param name="language">The language.</param>
 /// <param name="window">The parent window of the document.</param>
 public static void RunScript(string scriptCode, string language, IHTMLWindow2 window)
 {
     try
     {
         Logger.LogDebug("[script] {0}", scriptCode);
         window.execScript(scriptCode, language);
     }
     catch (Exception ex)
     {
         throw new RunScriptException(ex);
     }
 }
예제 #19
0
        //回复指定的字符串
        public void send(string content)
        {
            string scriptline01 = @"function SendMessage() {";
            string scriptline02 = @"    angular.element('#editArea').scope().editAreaCtn = '" + content + "'; ";
            string scriptline03 = @"    angular.element('#editArea').scope().sendTextMessage(); ";
            string scriptline04 = @"      ;}";
            string scriptline05 = @"SendMessage();";

            string       strScript = scriptline01 + scriptline02 + scriptline03 + scriptline04 + scriptline05;
            IHTMLWindow2 win       = (IHTMLWindow2)browser.Document.Window.DomWindow;

            win.execScript(strScript, "Javascript");
        }
예제 #20
0
        public static string Execute(WebBrowser wb, string strScript)
        {
            try
            {
                IHTMLWindow2 win = (IHTMLWindow2)wb.Document.Window.DomWindow;
                win.execScript(strScript, "Javascript");
            }
            catch (Exception ex)
            {
                return(String.Format("Excute Js: {0}", ex.Message));
            }

            return(String.Format("Excute Js {0} Success ", strScript));
        }
예제 #21
0
        /// 向业务系统发送消息-入口
        /// <summary>
        /// 向业务系统发送消息-入口
        /// </summary>
        /// <param name="msg"></param>
        public void SendToWeb(string msg, string webpageid, int recount = 0)
        {
            Loger.Log4Net.Info("[MainJs] [SendToWeb] 发送网页消息:" + recount + " 次数,指定页面ID:" + webpageid);
            try
            {
                IHTMLWindow2 win  = GetIHTMLWindow2ByWebPageID(webpageid);
                string       para = string.Format("&outBoundType={0}", ((int)BusinessProcess.OutBoundType).ToString());
                msg += para;

                //呼入振铃,则弹屏
                if (msg.StartsWith("UserEvent=" + UserEvent.Transferred.ToString()))
                {
                    TimeProgress(null, new string[] { "", "", "start" });

                    Loger.Log4Net.Info("[MainJs] [SendMesToWeb] 弹屏 " + ConfigurationManager.AppSettings["DefaultURL"] + "/CTI/PopTransfer.aspx");
                    NewPageForReq(ConfigurationManager.AppSettings["DefaultURL"] + "/CTI/PopTransfer.aspx?" + msg, true);
                }
                //发送事件
                win.execScript("try{MethodScript('" + msg + "');}catch(e){}", "Javascript");
                var subwin = CrossFrameIE.GetFrameWindowObject(win, SendMsgToIframeSubPageName);
                //给当前Page中iframe子页面发送消息,若子页面没有订阅消息,则不会发送
                if (subwin != null && alowReceiveCallMsg_WebpageIDList.Contains(webpageid))
                {
                    subwin.execScript("try{MethodScript('" + msg + "');}catch(e){}", "Javascript");
                }
                Loger.Log4Net.Info("[MainJs] [SendMesToWeb] CTIEventMsg msg:" + msg);

                if (msg.StartsWith("UserEvent=Released"))
                {
                    CurrentOutBoundTabPageName = "";
                    Loger.Log4Net.Info("[MainJs] [CurrentOutBoundTabPageName] 挂断清空");
                }
            }
            catch (Exception ex)
            {
                Loger.Log4Net.Error("客户端回调函数出错:" + ex.Message + "|" + ex.StackTrace);

                //2秒后重新执行,尝试5次
                if (recount <= 5)
                {
                    Thread thread = new Thread(new ThreadStart(() =>
                    {
                        Thread.Sleep(2 * 1000);
                        this.Invoke(new Action <string, int>(SendToWeb), msg, recount + 1);
                    }));
                    thread.Start();
                }
            }
        }
예제 #22
0
        private void NavigatedEventHandler(object sender, WebBrowserNavigatedEventArgs e)
        {
            IHTMLWindow2 win = (IHTMLWindow2)web.Document.Window.DomWindow;
            string       s   = "window.alert = null;";

            win.execScript(s, "javascript");
            if (e.Url.AbsolutePath == "/areaTopLogo.aspx")
            {
                SetStatus(true);
            }
            else
            {
                Log.log.Error("Get a null object from e.Url.AbsolutePath");
            }
        }
예제 #23
0
파일: main.cs 프로젝트: troj-iii/XinChen
        private void login__Click(object sender, EventArgs e)
        {
            IHTMLDocument2 doc = (IHTMLDocument2)wb_.Document.DomDocument;

            IHTMLWindow2      frameEle = doc.frames.item("SI2_mem_index");
            IHTMLInputElement accEle   = frameEle.document.body.all.item("username");
            IHTMLInputElement pwdEle   = frameEle.document.body.all.item("password");

            var info = GetRegInfo();

            accEle.value = info["username"];
            pwdEle.value = info["password"];

            frameEle.execScript("do_login();");
        }
예제 #24
0
        /// <summary>
        /// Runs given script (e.g. method with parameters) from a given web document.
        /// </summary>
        /// <param name="doc">HTML document containing JavaScript to run</param>
        /// <param name="script">script string to run (e.g. doSomething('param1', 123))</param>
        /// <returns>true if execution of JavaScript was successful or false otherwise</returns>
        public static bool RunJavaScript(HTMLDocument doc, String script)
        {
            IHTMLWindow2 window = doc.parentWindow;

            if (window != null)
            {
                try {
                    window.execScript(script, "JScript");
                    return(true);
                } catch {
                    // ignore
                }
            }
            return(false);
        }
        private void GetInfo()
        {
            IHTMLDocument2 hdoc = doc.DomDocument as IHTMLDocument2;
            IHTMLWindow2   win  = hdoc.parentWindow as mshtml.IHTMLWindow2;
            var            d    = win.execScript(@"function sucdd(){ return popUpWinQm;}", "javascript");

            if (hdoc == null)
            {
                MessageBox.Show("hdoc is null");
            }
            if (win == null)
            {
                MessageBox.Show("win is null");
            }
            HTMLWindow2Class            dddd1    = doc.InvokeScript("sucdd") as HTMLWindow2Class;
            IHTMLWindow2                dddd     = doc.InvokeScript("sucdd") as IHTMLWindow2;
            IHTMLDocument2              popupdoc = dddd.document;
            IHTMLElementCollection      elelist  = popupdoc.all.tags("tr") as IHTMLElementCollection;
            Dictionary <string, string> dic      = new Dictionary <string, string>();
            int i = 0;//申请号,申请人类型(法人或其他组织,自然人),书式类型(中国大陆),申请人名称,身份证明文件号码

            foreach (IHTMLElement item in elelist)
            {
                if (i < 3)
                {
                    continue;
                }
                if (i >= elelist.length - 15)
                {
                    break;
                }
                dic.Add(((item.children as IHTMLElementCollection).item(null, 0) as IHTMLElement).innerText, ((item.children as IHTMLElementCollection).item(null, 1) as IHTMLElement).innerText);
            }
            if (dic.Values.Contains("中国大陆"))
            {
                string regNum            = "";
                string applicantCategory = "";
                string applicant         = "";
                string idCard            = "";
                dic.TryGetValue("申请号", out regNum);
                dic.TryGetValue("申请人类型", out applicantCategory);
                dic.TryGetValue("申请人名称", out applicant);
                dic.TryGetValue("身份证明文件号码", out idCard);
                CommonLibrary.CommonTool.GetResult(currentUrl + string.Format("api/AutoReport/GetAddApplicantRegNum?regNum={0}&category={1}&applicant={2}&idCard={3}&id={4}", regNum, applicantCategory, applicant, idCard, currentId));
            }
            dddd.close();
        }
예제 #26
0
        /// <summary>
        /// 页面加载完成
        /// 注入js
        /// </summary>
        private void replaceJs()
        {
            mshtml.HTMLDocument htmlDoc = webBrower.Document as mshtml.HTMLDocument;
            var head   = htmlDoc.getElementsByTagName("head").Cast <HTMLHeadElement>().First();
            var script = (IHTMLScriptElement)htmlDoc.createElement("script");

            script.src = "https://demo.22com.cn/crm/json2.js";
            head.appendChild((IHTMLDOMNode)script);
            getWinScript();
            if (inject == null)
            {
                inject = new InjectJs(this.webBrower);
            }
            win.execScript(inject.getOverrideJs(), "javascript");//替换JS
        }
예제 #27
0
        private void BrowserLatest_OnLoadCompleted(object sender, NavigationEventArgs e)
        {
            try
            {
                HTMLDocument dom = BrowserLatest.Document as HTMLDocument; //定义HTML

                HTMLDocument doc = BrowserLatest.Document as HTMLDocument;
                //获取窗体
                IHTMLWindow2 window = doc.parentWindow;
                //注入javascript
                StringBuilder script = new StringBuilder();
                script.Append("if(document.getElementById('menu')){document.getElementById('menu').style.display = 'none';}");
                window.execScript(script.ToString(), "javascript");
            }
            catch (Exception exception)
            {
                LogHelper.Log(new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name, exception.Message);
            }
        }
예제 #28
0
        /// <summary>
        /// Load confort+ toolbar
        /// </summary>
        /// <remarks>
        /// Execute confort+ javascript and register to onmessage event
        /// </remarks>
        private void LoadToolbar()
        {
            IHTMLDocument2 document = this.webBrowser.Document as IHTMLDocument2;
            IHTMLWindow2   window   = document.parentWindow;

            this.LogInfo("5. load the toolbar");

            StringBuilder sb = new StringBuilder();

            sb.Append(Tools.GetStringFromRessource("js/hebergement.js"));
            sb.Append(Tools.GetStringFromRessource("js/ToolbarStrings.js"));
            sb.Append(Tools.GetStringFromRessource("js/UciUserPref.js"));
            sb.Append(Tools.GetStringFromRessource("js/UciSimpleStorage.js"));
            sb.Append(Tools.GetStringFromRessource("language/en.js"));
            sb.Append(Tools.GetStringFromRessource("language/es.js"));
            sb.Append(Tools.GetStringFromRessource("language/fr.js"));
            sb.Append(Tools.GetStringFromRessource("language/pl.js"));
            sb.Append(Tools.GetStringFromRessource("js/UciAideMotrice.js"));
            sb.Append(Tools.GetStringFromRessource("js/UciCouleur.js"));
            sb.Append(Tools.GetStringFromRessource("js/UciApparence.js"));
            sb.Append(Tools.GetStringFromRessource("js/UciSettings.js"));
            sb.Append(Tools.GetStringFromRessource("js/UciTypographie.js"));
            sb.Append(Tools.GetStringFromRessource("js/UciHelp.js"));
            sb.Append(Tools.GetStringFromRessource("js/UciValidation.js"));
            sb.Append(Tools.GetStringFromRessource("js/UciProfile.js"));
            sb.Append(Tools.GetStringFromRessource("js/UciIhm.js"));
            sb.Append(Tools.GetStringFromRessource("js/mask.js"));
            sb.Append(Tools.GetStringFromRessource("js/toolbar.js"));

            window.execScript(sb.ToString());

            IHTMLWindow3 window3 = document.parentWindow as IHTMLWindow3;

            if (window3 != null)
            {
                // front events subscription
                bool res = window3.attachEvent("onmessage", new ObjectEventHandler(this.OnMessage));
            }
            else
            {
                this.LogInfo("window3 is null");
            }
        }
예제 #29
0
        private void cbxUrl_SelectedIndexChanged(object sender, EventArgs e)
        {
            //string date = Utils.Timestamp2Date(tbxPostData.Text.Trim());
            //string aaaa = Utils.UnixTimestamp();
            if (tbxPostData.Text.Trim() != string.Empty)
            {
                IHTMLWindow2 js   = (IHTMLWindow2)wbMain.Document.Window.DomWindow;
                string       code = string.Format("alert({0})", tbxPostData.Text.Trim());
                try
                {
                    js.execScript(code, "javascript");
                }
                catch
                {
                }

                //string ccc = wbMain.Document.InvokeScript("recource").ToString();
            }
        }
예제 #30
0
        /// 临时浏览器产生新窗体事件
        /// <summary>
        /// 临时浏览器产生新窗体事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tempBrowser_NewWindow(object sender, CancelEventArgs e)
        {
            //获取触发tempBrowser_NewWindow事件的浏览器
            WebBrowser myBrowser = (WebBrowser)sender;
            //获取触发tempBrowser_NewWindow事件的浏览器所在TabPage
            TabPage mypage = (TabPage)myBrowser.Parent;
            //通过StatusText属性获得新的url
            string NewURL = ((WebBrowser)sender).StatusText;

            if (NewURL == "完成")
            {
                IHTMLWindow2 win = (IHTMLWindow2)myBrowser.Document.Window.DomWindow;
                win.execScript("try{ document.getElementById('" + myBrowser.Document.ActiveElement.Id + "').click();}catch(e){}", "Javascript");
            }
            else
            {
                NewPageForURL(NewURL);
                //使外部无法捕获此事件
                e.Cancel = true;
            }
        }
예제 #31
0
        private void button2_Click(object sender, EventArgs e)
        {
            IHTMLDocument2 hdoc = doc.DomDocument as IHTMLDocument2;
            IHTMLWindow2   win  = hdoc.parentWindow as mshtml.IHTMLWindow2;

            var d = win.execScript(@"function sucdd(){ return popUpWin;}", "javascript");
            HTMLWindow2Class       dddd     = doc.InvokeScript("sucdd") as HTMLWindow2Class;
            IHTMLDocument2         popupdoc = dddd.document;
            IHTMLElementCollection eleclt   = popupdoc.all.tags("span") as IHTMLElementCollection;

            foreach (IHTMLElement item in eleclt)
            {
                if (item.innerText != null)
                {
                    if (item.innerText.Contains("问题十四"))
                    {
                        item.click();
                    }
                }
            }
            //IHTMLElement ele=eleclt.item
        }
예제 #32
0
        private void On_Selector_Click(object sender, RoutedEventArgs e)
        {
            InternetExplorer ieWebBrowser = GetIEWindow();

            if (ieWebBrowser != null)
            {
                // 最小化窗口
                this.WindowState = WindowState.Minimized;

                // 读取欲注入的 JS 脚本
                StreamReader reader        = new StreamReader("Selector.js", Encoding.UTF8);
                string       strSelectorJS = reader.ReadToEnd();
                reader.Close();

                // 向 IE 注入 JS 脚本
                IHTMLWindow2 window2 = (ieWebBrowser.Document as IHTMLDocument2).parentWindow;
                window2.execScript(strSelectorJS);
            }
            else
            {
                MessageBox.Show("IE 浏览器未启动!");
            }
        }
예제 #33
0
        /// <summary>
        /// Try to run the script in the browser window
        /// </summary>
        /// <param name="i">The index of the script in the settings file</param>
        /// <param name="window">The current IHTMLWindow2</param>
        /// <param name="useMenuCommands">Should the menu commands HTML be injected into the page?</param>
        /// <param name="menuContent">The content for the menu commands HTML</param>
        private void TryRunScript(int i, IHTMLWindow2 window, ref bool useMenuCommands, ref string menuContent)
        {
            if (_prefs[i].Type != Script.ValueType.Script)
                return;

            string scriptContent = String.Empty;

            try
            {
                scriptContent = GetScriptFileData(i);

                var content = "function Scriptmonkey_S" + i + "_proto() {";
                if (_prefs.Settings.InjectAPI && _prefs[i].RequiresApi)
                    content += Resources.WrapperJS_Before + i + Resources.WrapperJS_Mid + _apiKeys[i] +
                               Resources.WrapperJS_After + scriptContent;
                else
                    content += scriptContent;

                if (_prefs[i].ShowMenuCommands && _prefs[i].MenuCommands?.Count > 0)
                {
                    foreach (NameFunctionPair command in _prefs[i].MenuCommands)
                    {
                        var internalName = GenerateRandomString();
                        content += "this.SM_" + internalName + " = " + command.Function + ";";
                        menuContent += "<p><a style=\"cursor: pointer; color: #4495d4;\" onclick=\"Scriptmonkey_S" + i + ".SM_" + internalName + "();\">" + command.Name + "</a></p>";
                    }
                    useMenuCommands = true;
                }

                content += "}var Scriptmonkey_S" + i + " = new Scriptmonkey_S" + i + "_proto();";

                //RunScript(content, window, _prefs[i].Name);
                var f = i;
                var t = new Thread(() => RunScript(content, window, _prefs[f].Name,
                    _prefs[f].Require != null && _prefs[f].Require.Count > 0? _prefs[f].Require.Values.ToList() : null));
                t.SetApartmentState(ApartmentState.STA);
                t.Start();
            }
            catch (Exception ex)
            {
                window.execScript("console.log(\"Scriptmonkey: Unable to load script: " + _prefs[i].Name + ". Error: " + ex.Message.Replace("\"", "\\\"") + "\");");
                bool shouldThrow;
                if (_prefs.Settings.LogScriptContentsOnRunError && !ex.Message.Contains("Access is denied"))
                    shouldThrow = LogAndCheckDebugger(ex, "At script: " + _prefs[i].Name + ':' + Environment.NewLine + scriptContent);
                else
                    shouldThrow = LogAndCheckDebugger(ex, "At script: " + _prefs[i].Name);

                if (shouldThrow)
                    throw;

            }
        }
예제 #34
0
        private void SetupWindow(IHTMLWindow2 window)
        {
            // Prevent multiple injections of API
            try
            {
                if (window.execScript("window['Scriptmonkey']") != null)
                {
                    return;
                }
            }
            catch (Exception) { }
            
            // Expose API methods
            try
            {
                var exp = window as IExpando;
                if (exp == null)
                    return;
                var info = exp.AddProperty("Scriptmonkey");
                info?.SetValue(exp, this);
            }
            catch (Exception ex)
            {
                if (ex is AccessViolationException) // Exception: "Attempted to read or write protected memory. _
                    return;                         // This is often an indication that other memory is corrupt." _
                                                    // This is thrown when the memory of the IE process is corrupted, _
                                                    // and thus write protected.
                if (LogAndCheckDebugger(ex, "SetupWindow"))
                    throw;
            }

            // Run Notification.js
            if (!_prefs.Settings.InjectNotificationAPI)
                return;
            try
            {
                window.execScript(Resources.NotificationJS);
            }
            catch (Exception ex)
            {
                if (ex is AccessViolationException)
                    return;

                if (ShouldThrowScriptException(ex, "NotificationWrapper", Resources.NotificationJS))
                    throw;
            }
        }
예제 #35
0
        /// <summary>
        /// Executes JavaScript on the window
        /// </summary>
        /// <param name="content">The JavaScript to execute.</param>
        /// <param name="window">The window.</param>
        /// <param name="name">Name of the script.</param>
        /// <param name="dependencyContent">String array of dependencies to include</param>
        private void RunScript(string content, IHTMLWindow2 window, string name, List<string> dependencyContent)
        {
            if (dependencyContent != null)
            {
                foreach (var dependency in dependencyContent)
                {
                    try
                    {
                        window.execScript(dependency);
                    }
                    catch (Exception ex)
                    {
                        if (ShouldThrowScriptException(ex, name, dependency))
                            throw;
                    }
                }
            }

            try
            {
                window.execScript(content);
            }
            catch (Exception ex)
            {
                if (ShouldThrowScriptException(ex, name, content))
                    throw;
            }

        }