unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, OleCtrls, SHDocVw, ExtCtrls, StdCtrls, ComCtrls, SynEditHighlighter, SynHighlighterJScript, SynEdit, SynHighlighterHtml;type TForm1 = class(TForm) Panel1: TPanel; Button1: TButton; PageControl1: TPageControl; TabSheet1: TTabSheet; TabSheet2: TTabSheet; Panel2: TPanel; WebBrowser1: TWebBrowser; SynEdit1: TSynEdit; SynJScriptSyn1: TSynJScriptSyn; CheckBox1: TCheckBox; CheckBox2: TCheckBox; Button2: TButton; TabSheet3: TTabSheet; SynEdit2: TSynEdit; SynHTMLSyn1: TSynHTMLSyn; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure Button2Click(Sender: TObject); procedure PageControl1Change(Sender: TObject); private { Private declarations } public jsfn: string; procedure execScript(Script: string); end;var Form1: TForm1;implementation{$R *.dfm}uses MSHTML, ActiveX;function GetHTMLCode(WB: TWebBrowser; ACode: TStrings): Boolean;var ps: IPersistStreamInit; s: string; ss: TStringStream; sa: IStream;begin ps := WB.document as IPersistStreamInit; s := ''; ss := TStringStream.Create(s); try sa := TStreamAdapter.Create(ss, soReference) as IStream; Result := Succeeded(ps.Save(sa, Bool(True))); if Result then ACode.Add(ss.Datastring); finally ss.Free; end;end;procedure TForm1.FormCreate(Sender: TObject);begin jsfn := ExtractFilePath(Application.ExeName) + 'Script.js'; if FileExists(jsfn) then begin SynEdit1.Lines.LoadFromFile(jsfn); end; WebBrowser1.Navigate('http://s17.sg.9wee.com/index.php?p=NoData');end;procedure TForm1.execScript(Script: string);begin WebBrowser1.OleObject.Document.parentWindow.execScript(Script, 'javascript');end;procedure TForm1.Button1Click(Sender: TObject);begin execScript(SynEdit1.Lines.Text);end;procedure TForm1.FormDestroy(Sender: TObject);begin SynEdit1.Lines.SaveToFile(jsfn);end;procedure TForm1.Button2Click(Sender: TObject);begin SynEdit1.Lines.SaveToFile(jsfn);end;procedure TForm1.PageControl1Change(Sender: TObject);begin if PageControl1.ActivePageIndex = 2 then begin SynEdit2.Lines.Text := WebBrowser1.OleObject.Document.body.outerHtml; //GetHTMLCode(WebBrowser1, SynEdit2.Lines); end;end;end./////////Script.jsfunction getCookie(name) { var s=''; var prefix = name + "=" var cookieStartIndex = document.cookie.indexOf(prefix) if (cookieStartIndex == -1) return '' var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length) if (cookieEndIndex == -1) cookieEndIndex = document.cookie.length s= unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex)) ; if (s==null) s=''; return s; } function wg(){var username = document.getElementById('username');if (username!= undefined ) { // 登陆 document.getElementById('username').value='h....'; document.getElementById('password').value='d....'; document.getElementById('Input').click(); document.cookie='cmd=登陆'; return; }var cmd= getCookie('cmd');if (cmd=='') cmd='城池动态';alert(cmd);var div;var div2;var div3;var table;var row;var element; var idx;var list; var s;if ( cmd=='建造' ){ document.getElementById('city_build_resource_a').click(); //资源建筑 document.cookie='cmd=资源建筑'; return;}if ( cmd=='资源建筑' ){ document.cookie='cmd=资源建筑'; div = document.getElementById('city_build_resource'); div = div.childNodes[0]; list=new Array(); idx=0; for(var i=1;i<div.childNodes.length;i++){ div2= div.childNodes; for(var j=0;j<div2.childNodes.length;j++) { div3=div2.childNodes[j]; if (div3.childNodes.length==4) { s=div3.childNodes[3].innerHTML; if(s.indexOf('onclick')>=0) { idx=list.length; list[idx]=div3; } } } } var minLevel=999; var Level=0; var idx=-1; for(var i=1;i<list.length;i++){ div=list; Level=0+div.childNodes[1].innerText; if (Level <minLevel) { minLevel= Level; idx=i; if (minLevel=0 ) break; } } if (idx<0) return; div=list[idx].childNodes[3]; if (div.innerText!='建') return ; document.cookie='cmd=资源建筑_建'; div.childNodes[0].click(); return;}if ( cmd=='资源建筑_建' ){ alert('1'); return;}if ( cmd=='城池动态' ){ document.getElementById('city_a').click(); //城池 document.getElementById('city_manage_a').click(); //管理 document.getElementById('city_manage_0_a').click(); //城池动态 div=document.getElementById('city_manage_0'); for(var i=0;i<div.childNodes.length;i++){ if ( div.childNodes.tagName=='TABLE' ) { table= div.childNodes; break; } } alert(table.rows.length) ; for(var arow=1;arow<table.rows.length;arow++){ row=table.rows[arow]; if (row.cells[8].innerText != '2' ) // 建造中 { alert(row.cells[0].innerText); row.cells[11].childNodes[0].click(); //查看 document.getElementById('city_resource_building_a').click(); document.cookie='cmd=建造'; break; } } return;} }wg();