-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathiWeb.ahk
634 lines (587 loc) · 21.5 KB
/
iWeb.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
;~ This library is the Product of tank
;~ based on COM.ahk from Sean http://www.autohotkey.com/forum/topic22923.html
;~ standard library is the work of tank and updates may be downloaded from
;~ http://www.autohotkey.net/~tank/iWeb.zip
;~ http://www.autohotkey.com/forum/viewtopic.php?t=51270
;~ complete API
/*
iWeb_Init()
iWeb_Term()
iWeb_NewIe()
iWeb_Model(h=550,w=900)
iWeb_GetWin(Name="")
iWeb_GetIE(Name="A")
iWeb_GetDocument(title="A")
iWeb_BRSRfromOBJ(obj)
iWeb_Release(pdsp)
iWeb_Nav(pwb,url)
iWeb_complete(pwb)
iWeb_DomWin(pdsp,frm="")
iWeb_inpt(i)
iWeb_getDomObj(pwb,obj,frm="")
iWeb_setDomObj(pwb,obj,t,frm="")
iWeb_FindbyText(needle,win="A",property="",offset=0,frm="")
iWeb_Checked(pwb,obj,checked=1,sIndex=0,frm="")
iWeb_SelectOption(pdsp,sName,selected,method="selectedIndex",frm="")
iWeb_TableParse(pdsp,table,row,cell,frm="")
iWeb_GetElementByAll(pdsp,obj,index=0,frm="")
iWeb_GetElementsByTag(pdsp,obj,index=0,frm="")
iWeb_Offset(pdsp,offset=0)
iWeb_FireEvents(ele)
iWeb_Attributes(element)
iWeb_TableLength(pdsp,TableRows="",TableRowsCells="",frm="")
iWeb_clickDomObj(pwb,obj,frm="")
iWeb_clickText(pwb,t,frm="")
iWeb_clickHref(pwb,t,frm="")
iWeb_clickValue(pwb,t,frm="")
iWeb_execScript(pwb,js,frm="")
iWeb_getVar(pwb,var,frm="")
iWeb_escape_text(txt)
iWeb_striphtml(HTML)
iWeb_UrlEncode( String )
iWeb_uriDecode(str)
iWeb_Txt2Doc(t)
iWeb_Activate(sTitle)
*/
;~ Library initialisers
;inititalize the library
iWeb_Init()
{
Return COM_CoInitialize()
}
;~ close the library
iWeb_Term()
{
Return COM_CoUninitialize()
}
;~ getting/destroying browser handles*
;~ A new internet explorer window
iWeb_NewIe()
{
Return pwb := (pwb := COM_CreateObject("InternetExplorer.Application") ) ? (pwb,COM_Invoke(pweb , "Visible=", "True")) : 0
}
;~ New internet explorer window always on top with titlebar only
iWeb_Model(h=550,w=900)
{
If pwb := (pwb := iWeb_newIe()) ? (pwb, COM_Invoke(pwb,"MenuBar",0),COM_Invoke(pwb,"ToolBar",0),COM_Invoke(pwb,"Resizable",0), COM_Invoke(pwb,"AddressBar",0), COM_Invoke(pwb,"StatusBar",0), COM_Invoke(pwb,"Height",h), COM_Invoke(pwb,"Width",w)) :
WinSet,AlwaysOnTop,On,% "ahk_ID " COM_Invoke(pwb,"hwnd")
Return pwb
}
;~ reuse an existing tab or window
iWeb_GetWin(Name="")
{
;~ COM_GetActiveObject("InternetExplorer.Application")
IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame ; Get active window if no parameter
Name := RegExReplace(Name," - (Windows|Microsoft) Internet Explorer")
if name
If psh := COM_CreateObject("Shell.Application") {
If psw := COM_Invoke(psh, "Windows") {
COM_Error(0)
Loop, % COM_Invoke(psw, "Count")
If pwb := (InStr(COM_Invoke(psw,"Item[" A_Index-1 "].FullName"), "iexplore.exe") && InStr(COM_Invoke(psw,"Item[" A_Index-1 "].LocationName"),Name)) ? COM_Invoke(psw,"Item",A_Index-1) :
Break
COM_Release(psw)
;~ COM_Error(1)
}
COM_Release(psh)
}
Return pwb ? pwb : iWeb_GetIE(Name)
}
;~ Usefull for particularly stubborn windows but be aware it can fail you if the page navigates and doesnt give you access to browser objects and properties
iWeb_GetIE(Name="A")
{ ;;this function is an addaption made by jethrow http://www.autohotkey.com/forum/topic318694.html
If Name
{
WinGet, winList, List, ahk_class IEFrame
While (winList%A_Index% && !m)
{
n := A_Index, ErrorLevel := 0
While (!ErrorLevel && !m)
{
ControlGetText, tabText, TabWindowClass%A_Index%, % "ahk_id" winList%n%
If InStr(tabText, Name)
m := A_Index
}
}
ControlGet, hIESvr, hWnd, , Internet Explorer_Server%m%, % "ahk_id" winList%n%
}
Else ControlGet, hIESvr, hWnd, , Internet Explorer_Server1, ahk_class IEFrame
If Not hIESvr
Return
DllCall("SendMessageTimeout", "Uint", hIESvr, "Uint", DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT"), "Uint", 0, "Uint", 0, "Uint", 2, "Uint", 1000, "UintP", lResult)
DllCall("oleacc\ObjectFromLresult", "Uint", lResult, "Uint", COM_GUID4String(IID_IHTMLDocument2,"{332C4425-26CB-11D0-B483-00C04FD90119}"), "int", 0, "UintP", pdoc)
pwb := iWeb_BRSRfromOBJ(pdoc), COM_Release(pdoc)
Return pwb
}
;~ Usefull for particularly stubborn windows but be aware it can fail you if the page navigates and doesnt give you access to browser objects and properties
iWeb_GetDocument(title="A")
{
Static
;~ Compliments Sean taken nearly un modified from the IE Spy http://www.autohotkey.com/forum/viewtopic.php?t=48470
ControlGet,hWnd,Hwnd,,Internet Explorer_Server1,%title% ahk_class Internet Explorer_TridentDlgFrame
If !Hwnd
ControlGet,hWnd,Hwnd,,Internet Explorer_Server1,%title% ahk_class ahk_class IEFrame
If !Hwnd
Return
If Not pfn
pfn := DllCall("GetProcAddress", "Uint", DllCall("LoadLibrary", "str", "oleacc.dll"), "str", "ObjectFromLresult")
, msg := DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT")
, COM_GUID4String(iid, "{00020400-0000-0000-C000-000000000046}")
If DllCall("SendMessageTimeout", "Uint", hWnd, "Uint", msg, "Uint", 0, "Uint", 0, "Uint", 2, "Uint", 1000, "UintP", lr:=0) && DllCall(pfn, "Uint", lr, "Uint", &iid, "Uint", 0, "UintP", pdoc:=0)=0
Return pdoc
}
iWeb_BRSRfromOBJ(obj)
{ ;; accepts any child object and returns an instance of iexplore.exe
Return COM_QueryService(pdoc,"{0002DF05-0000-0000-C000-000000000046}","{0002DF05-0000-0000-C000-000000000046}")
}
;~ this is just a wrapper for COM_Release()
iWeb_Release(pdsp)
{
COM_Release(pdsp)
}
;~ Navigate to a url
iWeb_Nav(pwb,url) ; returns bool
{
If (!pwb || !url) ; test to see if we have a valid interface pointer
{
MsgBox, 262160, Browser Navigation, The Browser you tried to Navigate to `n%url%`nwith is not valid
Return ; ExitApp if we dont
}
;~
;~ http://msdn.microsoft.com/en-us/library/aa752133(VS.85).aspx
navTrustedForActiveX = 0x0400
COM_Invoke(pwb, "Navigate", url, navTrustedForActiveX, "_self")
iWeb_complete(pwb)
Return ; return the result(bool) of the complete function
} ; nav function end
;~ wait for a page to finish loading
iWeb_complete(pwb) ; returns bool for success or failure
{
If !pwb ; test to see if we have a valid interface pointer
sleep, 5000 ; ExitApp if we dont
Else
{
loop 20 ; sets limit if itenerations to 40 seconds 80*500=40000=40 secs
If not (rdy:=COM_Invoke(pwb,"readyState") = 4)
Break ; return success
Else Sleep,100 ; sleep .1 second between cycles
loop 80 ; sets limit if itenerations to 40 seconds 80*500=40000=40 secs
If (rdy:=COM_Invoke(pwb,"readyState") = 4)
Break
Else Sleep,500 ; sleep half second between cycles
Loop 80
If ((rdy:=COM_Invoke(pwb,"document.readystate"))="complete")
Return 1 ; return success
Else Sleep,100
}
Return 0 ; lets face it if it got this far it failed
} ; end complete
;~ get the window onject from an object
iWeb_DomWin(pdsp,frm="")
{
If pWin := COM_QueryService(pdsp, "{332C4427-26CB-11D0-B483-00C04FD90119}", "{332C4427-26CB-11D0-B483-00C04FD90119}")
{
Loop, Parse, frm, `,
{
frame:=COM_Invoke(pWin,"document.all.item['" A_LoopField "'].contentwindow")
COM_Release(pWin)
pWin:=COM_QueryService(frame, "{332C4427-26CB-11D0-B483-00C04FD90119}", "{332C4427-26CB-11D0-B483-00C04FD90119}")
COM_Release(frame)
If !pWin
Return False
}
Return pWin
}
Return False
}
;~ Determin if an element is a form input
iWeb_inpt(i)
{
;~ http://msdn.microsoft.com/en-us/library/ms534657(VS.85).aspx tagname property
typ := COM_Invoke(i, "tagName")
inpt := "BUTTON,INPUT,OPTION,SELECT,TEXTAREA" ; these things all have value attribute and is likely what i need instead of innerHTML
Loop,Parse,inpt,`,
if (typ = A_LoopField ? 1 : "")
Return 1
Return
}
;~ Functions that manipulate DOM
iWeb_getDomObj(pwb,obj,frm="")
{
/*********************************************************************
pwb - browser object
obj - object reference; optionally, a comma delimited list of references (name, id or index) of all value can be used
frm - frame reference; optionally, a comma delimited list of frames (name, id or index ) of all value can be used
example of usage
The below will try to get an object called 'username'
iWeb_getDomObj(pwb,"username")
*/
If itm := iWeb_GetElementByAll(pwb,obj,0,frm) ;if this fails there really isnt any need to do below
{
rslt .= iWeb_uriDecode(COM_Invoke(itm,T:=iWeb_inpt(itm) ? "value" : "innerHTML")) ","
iWeb_FireEvents(itm)
COM_Release(itm)
}
Return rslt
}
iWeb_setDomObj(pwb,obj,t,frm="")
{
/*********************************************************************
pwb - browser object
obj - object reference; optionally
t - text to place in object;
frm - frame reference; optionally,
Example Usage
The below will take a browser object, try to get an object called 'username' and set its value/innerHTML to 'john'
iWeb_setDomObj(pwb,"username","john")
*/
If itm := iWeb_GetElementByAll(pwb,obj,0,frm) ;if this fails there really isnt any need to do below
{
;~ making invoke take integers as Strings ", VT_BSTR:=8"
;~ http://www.autohotkey.com/forum/viewtopic.php?p=221631#221631 iWeb_uriDecode(str)
COM_Invoke_(itm,v:=iWeb_inpt(itm) ? "Value=" : "innerHTML=",8,iWeb_UrlEncode(t))
iWeb_FireEvents(itm)
COM_Release(itm)
d=1
}
Return d
}
iWeb_FindbyText(needle,win="A",property="",offset=0,frm="")
{
If pWin := iWeb_DomWin(pwb,frm)
{
If oRange:=COM_Invoke(pWin,"document.body.createTextRange")
{
COM_Invoke(oRange,"findText",needle)
_res:=property ? COM_Invoke(pWin,"Document.all.item[" COM_Invoke(oRange,"parentElement.sourceIndex")+offset "]." property) : COM_Invoke(pWin,"Document.all.item", COM_Invoke(oRange,"parentElement.sourceIndex")+offset)
COM_Release(oRange)
}
}
Return _res
}
iWeb_Checked(pwb,obj,checked=1,sIndex=0,frm="")
{
If pWin := iWeb_DomWin(pwb,frm)
{
COM_Invoke(pWin,(string:=sIndex ? "document.all[" obj "].item[" sIndex "]" : "document.all[" obj "]") ".checked",checked)
Checkmark := COM_Invoke(pWin,string ".checked") ? True : False
iWeb_FireEvents(ele:=COM_Invoke(pWin,string))
COM_Release(ele)
COM_Release(pWin)
}
Return Checkmark
}
iWeb_SelectOption(pdsp,sName,selected,method="selectedIndex",frm="")
{
If pWin := iWeb_DomWin(pdsp,frm)
{
COM_Invoke(pWin,"document.all[" sName "].selectedIndex" ,selected)
iWeb_FireEvents(ele:=COM_Invoke(pWin,"document.all[" sName "]."))
COM_Release(ele)
COM_Release(pWin)
}
Return
}
iWeb_TableParse(pdsp,table,row,cell,frm="")
{
;~ http://www.w3schools.com/jsref/dom_obj_table.asp
ErrorLevel:=
If ErrorLevel:=!(pWin := iWeb_DomWin(pdsp,frm)) ? "failed to get a window handle" : false
Return ErrorLevel
;~ COM_Error(0)
cell:=pWin ? COM_Invoke(pWin,"document.all.tags[table].item[" table "].rows[" row "].cells[" cell "]") : false
;~ COM_Error(1)
COM_Release(pWin)
If !cell
Return ErrorLevel:="**** failed to get the cell reference ****"
result:=cell ? COM_Invoke(cell,"innerHTML") :
iWeb_FireEvents(cell)
COM_Release(cell)
Return result
}
iWeb_GetElementByAll(pdsp,obj,sindex=0,frm=""){ ;; returns object
;~ COM_Error(0)
Return element := (pWin := iWeb_DomWin(pdsp,frm) ) ? ((sindex > 0 ? COM_Invoke(pWin,"document.all.['" obj "'].item",sindex) : COM_Invoke(pWin,"document.all.item", obj )),COM_Release(pWin)) :
}
iWeb_GetElementsByTag(pdsp,tag,obj=0,frm=""){ ;; returns object
Return element := (pWin := iWeb_DomWin(pdsp,frm) ) ? (COM_Invoke(pWin,"document.all.tags['" tag "'].item",obj),COM_Release(pWin)) :
}
iWeb_Offset(pdsp,offset=0){
Return element := (pWin := iWeb_DomWin(pdsp,frm) ) ? (COM_Invoke(pWin,"document.all",COM_Invoke(pdsp,"sourceIndex") + offset),COM_Release(pWin)) :
}
iWeb_FireEvents(ele)
{
attributes:=iWeb_Attributes(ele)
Loop,Parse,attributes, `n
If InStr(A_LoopField,"on")
COM_Invoke(ele,A_LoopField)
}
iWeb_Attributes(element)
{ ;;http://msdn.microsoft.com/en-us/library/ms537438.aspx
n=0
appliesTo=A,ABBR,ACRONYM,ADDRESS,APPLET,AREA,attribute,B,BASE,BASEFONT,BDO,BGSOUND, ,BIG,BLOCKQUOTE,BODY,BR,BUTTON,CAPTION,CENTER,CITE,CODE,COL,COLGROUP,COMMENT,DD,DEL, ,DFN,DIR,DIV,DL,DT,EM,EMBED,FIELDSET,FONT,FORM,FRAME,FRAMESET,HEAD,hn,HR,HTML,I,IFRAME, ,IMG,INS,INPUT,KBD,LABEL,LEGEND,LI,LINK,LISTING,MAP,MARQUEE,MENU,nextID,OBJECT,OL, ,OPTION,P,PLAINTEXT,PRE,Q,S,SAMP,SCRIPT,SELECT,SMALL,SPAN,STRIKE,STRONG,SUB,SUP, ,TABLE,TBODY,TD,TEXTAREA,TFOOT,TH,THEAD,TITLE,TR,TT,U,UL,VAR,XMP
applies:=
If !tagname:=COM_Invoke(element,"tagname")
Return
Loop,Parse,appliesTo,`,
If (A_LoopField = tagname)
{
applies:=1
Break
}
If !applies || !cAttr:= COM_Invoke(element,"attributes")
Return ;; error getting the attributes
Loop,% COM_Invoke(cAttr,"length")
If oAttr:=COM_Invoke(cAttr,"item", n++ )
{
If COM_Invoke(oAttr,"specified") ;; true if the attribute is defined in the attribute
the_attributes.=COM_Invoke(oAttr,"nodeName") "`n"
;~ the_attributes.=COM_Invoke(oAttr,"nodeName") "=""" COM_Invoke(oAttr,"nodeValue") """`n"
COM_Release(oAttr),oAttr:=
}
Else Break
StringTrimRight,the_attributes,the_attributes,1
Return the_attributes
}
iWeb_TableLength(pdsp,TableRows="",TableRowsCells="",frm="")
{
/*
TableRows - table index id or name for the table whos rows you wish to count
TableRowsCells - row index id or name for the table whos rows you wish to count TableRows is required for this
*/
ErrorLevel:=
If ErrorLevel:=!(pWin := iWeb_DomWin(pdsp,frm)) ? "failed to get a window handle" : false
Return ErrorLevel
string:="document.all.tags[table]" (t:=(StrLen(TableRows) ? (".item[" TableRows "].rows" (r:=StrLen(TableRowsCells) ? ("[" TableRowsCells "].cells") : "")) : ""))
;~ COM_Error(0)
ref:=pWin ? COM_Invoke(pWin,string) : false
;~ COM_Error(1)
COM_Release(pWin)
If !ref
Return ErrorLevel:="**** failed to get the iWeb_TableLength reference ****"
result:=ref ? COM_Invoke(ref,"length") :
COM_Release(ref)
Return result
}
;~ functions that click
iWeb_clickDomObj(pwb,obj,frm="")
{
/*********************************************************************
pwb - browser object
obj - object reference; optionally, a comma delimited list of references (name, id or index) of all value can be used
frm - frame reference; optionally, a comma delimited list of frames (name, id or index ) of all value can be used
Example of Usage
The below will take a browser object and try to click an object called username
iWeb_getDomObj(pwb,"username")
This will cycle thru and attempt to click 3 separate objects (username, pass and 3)
iWeb_clickDomObj(pwb,"username,pass,3")
This will recurse into the 'left' frame and try to click an object called 'results'
iWeb_clickDomObj(pwb,"results","left")
*/
If pWin := iWeb_DomWin(pwb,frm)
{
COM_Invoke(pWin,"Document.all.item['" obj "'].click")
d=1
COM_Release(pWin)
}
Return d
}
iWeb_clickText(pwb,t,frm="")
{
/*********************************************************************
pwb - browser object
t - text with in the link to check against
frm - frame reference; optionally, a comma delimited list of frames (name, id or index ) of all value can be used
Example Usage
The below will take a browser object and try to click an object with the text 'Click Here'
iWeb_clickText(pwb,"Click Here")
This will recurse into the 'left' frame and try to click an object with the text 'Contact Us'
iWeb_clickText(pwb,"Contact Us","left")
*/
If pWin := iWeb_DomWin(pwb,frm)
{
Loop,% COM_Invoke(pWin,"document.links.length")
If InStr(COM_Invoke(pWin,"document.links.item[" A_Index-1 "].innertext"),t)
{
COM_Invoke(pWin,"document.links.item[" A_Index-1 "].click")
d=1
Break
}
COM_Release(pWin)
} ;;If pWin
Return d
}
iWeb_clickHref(pwb,t,frm="")
{
/*********************************************************************
pwb - browser object
t - text with in the href to check against
frm - frame reference; optionally, a comma delimited list of frames (name, id or index ) of all value can be used
Example Usage
This will click a link with the text below in the href attribute even if there were more following that entry in the href
iWeb_clickHref(pwb,"javascript:alert('this was in a link')")
This will recurse into the 'left' frame and try to click an object with the url for AutoHotkey's forum in an href
iWeb_clickHref(pwb,"http://www.autohotkey.com/forum/","left")
*/
If pWin := iWeb_DomWin(pwb,frm)
{
Loop,% COM_Invoke(pWin,"document.links.length")
If InStr(COM_Invoke(pWin,"document.links.item[" A_Index-1 "].href"),t)
{
COM_Invoke(pWin,"document.links.item[" A_Index-1 "].click")
d=1
Break
}
COM_Release(pWin)
} ;;If pWin
Return d
}
iWeb_clickValue(pwb,t,frm="")
{
/*********************************************************************
pwb - browser object
t - text to match from visible button or other inputs
frm - frame reference; optionally, a comma delimited list of frames (name, id or index ) of all value can be used
Example Usage
The below will click an element that has a value attribute equal to 'Submit'
iWeb_clickValue(pwb,"Submit")
This will recurse into the 'left' frame and try to click an object with the value 'Enter'
iWeb_clickValue(pwb,"Enter","left")
*/
If pWin := iWeb_DomWin(pwb,frm)
{
Loop,% COM_Invoke(pWin,"document.all.length")
If iWeb_inpt(itm:=COM_Invoke(pWin,"document.all.item", A_Index-1)) ? InStr(COM_Invoke(pWin,"document.all.item[" A_Index-1 "].value"),t) : 0
{
COM_Invoke(itm,"click")
COM_Release(itm)
d=1
Break
}
Else COM_Release(itm)
COM_Release(pWin)
} ;;If pWin
Return d
}
;~ Functions used to interact with scripts embeded in a web page
;~ insert and execute a javascript statement into an exisiting document window
iWeb_execScript(pwb,js,frm="")
{
If (js && (pWin:= iWeb_DomWin(pwb,frm)))
{
COM_Invoke(pWin, "execScript", js)
COM_Release(pWin)
}
Return
}
;~ retreive a global variable value from a page
iWeb_getVar(pwb,var,frm="")
{
If (var && (pWin:= iWeb_DomWin(pwb,frm)))
{
rslt:= COM_Invoke(pWin, var)
COM_Release(pWin)
}
Return rslt
}
;~ this helper function is really designed to return only
;~ useable un formated text that can be used within javascript
iWeb_escape_text(txt)
{
StringReplace,txt,txt,',\',ALL
StringReplace,txt,txt,"",\"",ALL
;~ StringReplace,txt,txt,`.`.,`.,ALL
StringReplace,txt,txt,`r,%a_space%,ALL
StringReplace,txt,txt,`n,%a_space%,ALL
StringReplace,txt,txt,`n`r,%a_space%,ALL
StringReplace,txt,txt,%a_space%%a_space%,%a_space%,ALL
return txt
}
;~ simply stripts html tags from a string
iWeb_striphtml(HTML)
{
;~ thanks lazlo http://www.autohotkey.com/forum/viewtopic.php?p=71935#71935
Loop Parse, HTML, <>
If (A_Index & 1)
noHTML .= A_LoopField
Return noHTML
}
iWeb_UrlEncode( String )
{
OldFormat := A_FormatInteger
SetFormat, Integer, H
Loop, Parse, String
{
if A_LoopField is alnum
{
Out .= A_LoopField
continue
}
Hex := SubStr( Asc( A_LoopField ), 3 )
Out .= "%" . ( StrLen( Hex ) = 1 ? "0" . Hex : Hex )
}
SetFormat, Integer, %OldFormat%
return Out
}
iWeb_uriDecode(str) {
Loop
If RegExMatch(str, "i)(?<=%)[\da-f]{1,2}", hex)
StringReplace, str, str, `%%hex%, % Chr("0x" . hex), All
Else Break
Return, str
}
;~ takes an html fragment and creates a DOM document from a string
iWeb_Txt2Doc(t)
{
If doc := COM_CreateObject("{25336920-03F9-11CF-8FD0-00AA00686F13}")
COM_Invoke(doc, "write", t),COM_Invoke(doc, "close")
Return doc
}
;~ Sets a window and tab as active by the page title
iWeb_Activate("Home")
iWeb_Activate(sTitle)
{
DllCall("LoadLibrary", "str", "oleacc.dll")
HWND:=oIE_get(sTitle).HWND
DetectHiddenWindows, On
WinActivate,% "ahk_id " HWND
WinWaitActive,% "ahk_id " HWND,,5
ControlGet, hTabBand, hWnd,, TabBandClass1, ahk_class IEFrame
ControlGet, hTabUI , hWnd,, DirectUIHWND1, ahk_id %hTabBand%
VarSetCapacity(CLSID, 16)
nSize=38
wString := sString := "{618736E0-3C3D-11CF-810C-00AA00389B71}"
if(nSize = "")
nSize:=DllCall("kernel32\MultiByteToWideChar", "Uint", 0, "Uint", 0, "Uint", &sString, "int", -1, "Uint", 0, "int", 0)
VarSetCapacity(wString, nSize * 2 + 1)
DllCall("kernel32\MultiByteToWideChar", "Uint", 0, "Uint", 0, "Uint", &sString, "int", -1, "Uint", &wString, "int", nSize + 1)
DllCall("ole32\CLSIDFromString", "Uint",&wString , "Uint", &CLSID)
If hTabUI && DllCall("oleacc\AccessibleObjectFromWindow", "Uint", hTabUI, "Uint",-4, "Uint", &CLSID , "UintP", pacc)=0
{
pacc := ComObject(9, pacc, 1), ObjAddRef(pacc)
Loop, % pacc.accChildCount
If paccChild:=pacc.accChild(A_Index)
If paccChild.accRole(0+0) = 0x3C
{
paccTab:=paccChild
Break
}
Else ObjRelease(paccChild)
ObjRelease(pacc)
}
If pacc:=paccTab
{
Loop, % pacc.accChildCount
If paccChild:=pacc.accChild(A_Index)
If paccChild.accName(0+0) = sTitle
{
ObjRelease(pwb)
paccChild.accDoDefaultAction(0)
ObjRelease(paccChild)
Break
}
Else ObjRelease(paccChild)
ObjRelease(pacc)
}
WinActivate,% sTitle
}