Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Firefox ACC current tab
how do i use ACC to return to the tab where i started my macro?

i need to activate the tab from where i started my actions to run another loop of actions.
in firefox i use a userscript which can be triggered by key press, i give qm a number for rep to send keys (key CQ ;; next tab),
when finished i now send key for the amount of new tabs-1 (key SCT), but simply activating the start-tab would be better.

Macro Macro1867
Copy      Help
int w=win("Firefox" "Mozilla*WindowClass" "" 0x804)
act w

;get current tab name
Acc a.Find(w "DOCUMENT" "" "" 0x3000 2)
str tabName=a.Name

;next tab
key CT

;return to the tabName tab
Acc a1.Find(w "PAGETAB" tabName "" 0x1005)

how do i gather all info from PAGETABLIST? seems that each tab has a unique ID -> a:linkedpanel=panel{someNumberGeneratedByFirefox} and where to put best (array, class, some other kind of structure)
when using unique ID then i would not have to rely on tab title.

how to checked if a tab has finished loading?
and how would i navigate with acc instead of sending key CT?
Maybe you already have this function. It somewhere in forum. It uses these linkedpanel to get web page of tab button.
Function FirefoxGetTabs
Copy      Help
function# [hwndFF] [ARRAY(str)&names] [ARRAY(str)&urls] [ARRAY(Acc)&docObjects] [ARRAY(Acc)&buttonObjects]

;Gets names of Firefox tabs. Optionally gets their URL and accessible objects.
;Returns 0-based index of the selected tab.
;Error if fails.

;hwndFF - Firefox window handle. If 0, finds.
;names - variable for tab names. Can be 0 if don't need.
;urls - variable for addresses. Can be 0 if don't need.
;docObjects - variable for DOCUMENT accessible objects that represent web pages. Can be 0 if don't need.
;buttonObjects - variable for PAGETAB accessible objects that represent tab buttons. Can be 0 if don't need.

;Requires QM 2.3.3 or later.
;Elements of urls and docObjects of non-loaded tabs will be empty. Firefox does not load pages in invisible tabs at startup.

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

ARRAY(str) _names; if(!&names) &names=_names
if(&urls) urls=0
if(&docObjects) docObjects=0
if(&buttonObjects) buttonObjects=0

if(!hwndFF) hwndFF=win("Mozilla Firefox" "Mozilla*WindowClass" "" 0x804); if(!hwndFF) end ERR_WINDOW

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

;enum tabs
Acc a.Find(hwndFF "PAGETAB" "" "class=MozillaWindowClass" 0x1004)
,if(a.Role!ROLE_SYSTEM_PAGETAB) goto next ;;[ + ] button
,if(&buttonObjects) buttonObjects[]=a
,;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.
,a.Navigate("n"); err break

if(r<0) end ERR_FAILED
if(!&urls and !&docObjects) ret r

;enum panes
if(&urls) urls.create(names.len)
if(&docObjects) docObjects.create(names.len)
#if QMVER<0x2030400
a.Find(hwndFF "DOCUMENT" "" "" 0x3000 0 0 "pa3fi")
err a.Find(hwndFF "" "" "" 0x3010 1 0 "pa4fi")
a.Find(hwndFF "" "" "" 0x3000 2 0 "pa3fi")
,;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=names.len) goto next2 ;;should never happen
,;get DOCUMENT object and url
,Acc aa; a.Navigate("fi2" aa); err goto next2
,if(&urls) urls[i]=aa.Value
,if(&docObjects) docObjects[i]=aa
,a.Navigate("n"); err break

ret r

err+ end _error

Also this maybe will be useful.
Function FirefoxSelectTab
Copy      Help
function hwndFF $name [flags] ;;flags: 1 name is URL, 2 wildcard, 4 beginning, 8 end, 16 anywhere, 32 rx

;Finds and selects Firefox tab.
;Error if not found.

;hwndFF - Firefox window handle. If 0, finds.
;name - tab name. If flag 1 - URL.
;;;1 - name is URL.
;;;2-32 - how to compare name. Default: exact match. Always case insensitive.

ARRAY(str) names urls; ARRAY(Acc) a
int selectedTab=FirefoxGetTabs(hwndFF names iif(flags&1 &urls 0) 0 a)
int i
ARRAY(str)& as=iif(flags&1 urls names)
for i 0 names.len
,if SelStr(flags|1 as[i] name)
,,if i!=selectedTab
,,ret 1

end "tab not found"
err+ end _error

Quote:how to checked if a tab has finished loading?
With current tab - function FirefoxWait, look in this forum.
Probably not possible with background tabs. FF fires an accessible event, but it is not reliable.

Forum Jump:

Users browsing this thread: 1 Guest(s)