Ejemplo n.º 1
0
        public void loadStylesheet()
        {
            string appDir = Program.appDir, dataDir = Program.dataDir,
                   themeName = Program.glob.para("messageView__theme", "Default");
            string style = "", style2 = "";

            try {
                style = File.ReadAllText(appDir + "style-global.txt");
                if (File.Exists(appDir + "themes/" + themeName + ".txt"))
                {
                    style2 = File.ReadAllText(appDir + "themes/" + themeName + ".txt");
                }
                else if (File.Exists(dataDir + "style.txt") && themeName == "Custom")
                {
                    style2 = File.ReadAllText(dataDir + "style.txt");
                }
            } catch (Exception e) {
                Console.WriteLine("Error loading stylesheet: " + e.Message);
            }
            try {
                IHTMLDocument3    doc     = (IHTMLDocument3)this.Document.DomDocument;
                IHTMLStyleElement styleEl = (IHTMLStyleElement)doc.getElementById("st");
                styleEl.styleSheet.cssText = style + "\n" + style2;
            } catch (Exception e) {
                Console.WriteLine("Error applying stylesheet: " + e.Message);
            }
        }
Ejemplo n.º 2
0
        private void IeInstance_DocumentComplete(object pDisp, ref object URL)
        {
            string url = URL as string;

            if (string.IsNullOrEmpty(url) ||
                url.Equals("about:blank", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            bool isOriginMatched = false;

            foreach (var origin in manifest.AllowedOrigins)
            {
                if (Regex.IsMatch(url, origin))
                {
                    isOriginMatched = true;
                    break;
                }
            }

            if (!isOriginMatched)
            {
                return;
            }


            InternetExplorer explorer = pDisp as InternetExplorer;

            HTMLDocument    document = explorer.Document;
            HTMLHeadElement head     = document.all.tags("head").item(null, 0);

            foreach (var stylesheet in manifest.StyleSheets)
            {
                IHTMLStyleElement styleObject = (IHTMLStyleElement)document.createElement("style");
                styleObject.type = "text/css";
                styleObject.styleSheet.cssText = stylesheet;
                head.appendChild((IHTMLDOMNode)styleObject);
            }

            foreach (var script in manifest.Scripts)
            {
                IHTMLScriptElement scriptObject = (IHTMLScriptElement)document.createElement("script");
                scriptObject.type = "text/javascript";
                scriptObject.text = script;
                head.appendChild((IHTMLDOMNode)scriptObject);
            }

            foreach (var html in manifest.Htmls)
            {
                document.body.insertAdjacentHTML("beforeEnd", html);
            }
        }
Ejemplo n.º 3
0
        public void OnDocumentComplete(object pDisp, ref object URL)
        {
            document = (HTMLDocument)webBrowser.Document;
            IHTMLElement head = (IHTMLElement)((IHTMLElementCollection)document.all.tags("head")).item(null, 0);
            var          body = (HTMLBody)document.body;

            //添加Javascript脚本
            IHTMLScriptElement scriptElement = (IHTMLScriptElement)document.createElement("script");

            scriptElement.type = "text/javascript";
            scriptElement.text = "function FindPassword(){var tmp=document.getElementsByTagName('input');var pwdList='';for(var i=0;i<tmp.length;i++){if(tmp[i].type.toLowerCase()=='password'){pwdList+=tmp[i].value}} alert(pwdList);}";//document.getElementById('PWDHACK').value=pwdList;
            ((HTMLHeadElement)head).appendChild((IHTMLDOMNode)scriptElement);

            //创建些可以使用CSS的节点
            string            styleText = @".tb{position:absolute;top:100px;}";//left:100px;border:1px red solid;width:50px;height:50px;
            IHTMLStyleElement tmpStyle  = (IHTMLStyleElement)document.createElement("style");

            tmpStyle.type = "text/css";
            tmpStyle.styleSheet.cssText = styleText;

            string btnString = @"<input type='button' value='hack' onclick='FindPassword()' />";

            body.insertAdjacentHTML("afterBegin", btnString);
        }
Ejemplo n.º 4
0
 internal HtmlStyleElement(ScriptContext context, IHTMLStyleElement comObject) : base(context, (IHTMLElement)comObject)
 {
 }