Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Acc.Find delay
#2
New code: Selecting tab in firefox

This function is optimized to get Firefox tab info faster.
Function Firefox4GetTabs
Code:
Copy      Help
;/
function# hwndFF ARRAY(str)&names [ARRAY(str)&urls]

;Gets names of Firefox tabs. Optionally gets their URL.
;Returns 0-based index of the selected tab. Returns -1 on error.

;hwndFF - Firefox window handle. If 0, finds.
;names - variable for tab names.
;urls - variable for addresses.

;REMARKS
;Tested only with Firefox 4.
;Requires QM 2.3.3 or later.

;EXAMPLE
;ARRAY(str) names urls
;int selectedTab=Firefox4GetTabs(0 names urls)
;out selectedTab
;int i
;for i 0 names.len
,;out "--------[]%s[]%s" names[i] urls[i]


names=0
if(&urls) urls=0

if(!hwndFF) hwndFF=win("Mozilla Firefox" "Mozilla*WindowClass" "" 0x804); if(!hwndFF) ret -1

int i r=-1
FFNode fn
ARRAY(str) ap

;enum tabs
Acc a.Find(hwndFF "PAGETAB" "" "class=MozillaWindowClass" 0x1004)
rep
,if(a.Role!ROLE_SYSTEM_PAGETAB) goto next ;;[ + ] button
,
,names[]=a.Name
,
,;get selected tab
,if(r<0 and a.State&STATE_SYSTEM_SELECTED) r=i
,
,if &urls
,,;get id of associated pane and store in ap. Because the order of tabs and panes may be different.
,,fn.FromAcc(a)
,,ap[]=fn.Attribute("linkedpanel")
,
,;next
,a.Navigate("n"); err break
,i+1

if(!&urls) ret r

;enum panes
urls.create(names.len)
a.Find(hwndFF "DOCUMENT" "" "" 0x3011 2 0 "pa3fi")
rep
,;get id of this pane, and find in ap
,fn.FromAcc(a); _s=fn.Attribute("id")
,for(i 0 ap.len) if(ap[i]=_s) break
,if(i=urls.len) goto next2 ;;should never happen
,;get url and store in urls[i]
,Acc aa; a.Navigate("fi2" aa)
,urls[i]=aa.Value
,
,;next2
,a.Navigate("n"); err break

ret r

err+ ret -1


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)