AutoHotkey Community

It is currently May 27th, 2012, 2:26 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 29 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: February 9th, 2010, 4:22 pm 
Offline

Joined: September 2nd, 2008, 4:20 pm
Posts: 50
So I have this internal webpage that has a URL at the bottom of the page that contains the unique ID to make some javascript work.

What I'd like to do is find that URL on the page, parse it for the ID, then paste a javascript command into the address bar and hit enter.

When searching for help/ideas on this I see COM is talked about a lot with IE, but I don't understand what it is or how to use it, so I'm not sure if it applies in this situation.

All suggestions and/or help is appreciated.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 9th, 2010, 4:31 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
Can you copy the shortcut to get the data? Or have you tried COM to click the link/execute the JS instead?

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 9th, 2010, 4:54 pm 
Offline

Joined: September 2nd, 2008, 4:20 pm
Posts: 50
sinkfaze wrote:
Can you copy the shortcut to get the data?


The only way I could think to do that would be by scrolling the page and using mouse clicks which seems pretty kludgey to me, but yes the url is copyable with a right mouse click.

Quote:
Or have you tried COM to click the link/execute the JS instead?


No, because the whole COM issue is rather large to me. I can understand most of what I'm doing with AHK through using the online documentation and asking for help here, but COM seems to be a whole different language that people just seem to say "use COM."

Is there a beginners guide to COM somewhere that explains it and how one might integrate it into an AHK script?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 9th, 2010, 5:13 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
Could you copy the URL and post it here? I'm assuming it's a JS call?

There are a lot of tutorials in the forums for COM, most of them sorely need to be updated (jethrow's tutorial is the most recent one). A few of us have been working on some tools to make working with COM much easier but it's a lot longer process than it seems. You can check out the iWeb recorder and the iWeb functions we've been working on from this post; the recorder in particular should make it easier to identify page elements and create iWeb function calls to manipulate those elements.

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 9th, 2010, 5:35 pm 
Offline

Joined: September 2nd, 2008, 4:20 pm
Posts: 50
the URL at the bottom of the page copied to my clipboard and pasted here gives us

Code:
javascript:runThing('m_b390c984u4526fh98adhj2343245620', 'Stuff','');


Part of the code changed to disguise anything that might be considered proprietary.

From that I want to grab b390c984u4526fh98adhj2343245620 and make this line and run it in IE:

Code:
javascript saveThing('Stuff', 'b390c984u4526fh98adhj2343245620');


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 9th, 2010, 6:26 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
I'm assuming the function being called is unique on the page, you can try this (requires COM Standard Library and iWeb function library), I added some comments so you can follow along:

Code:
jMatch:="i)^javascript:runThing\('m_(\w+)', 'Stuff',''\);" ; regular expression to match the desired js call, if it matches it will capture the needed subpattern.  Adjust it for the information you redacted but leave these as is: \(, \) and (\w+).

iWeb_Init() ; starts COM
ControlGet,hWnd,Hwnd,,Internet Explorer_Server1, ahk_class IEFrame ; gets the window handle for the document interface in Internet Explorer
pDoc:=IE_GetDocument(hWnd) ; creates an pointer to access the page document
Loop % iWeb_getTagLen(pDoc,"A") { ; loops through all of the link elements on the page
  if RegExMatch(iWeb_getTagObj(pDoc,"A",A_Index-1,-1,-1,"href"),jMatch,m) { ; checks to see if the href of the element matches our regular expression search
    iWeb_execScript(pDoc,"javascript:saveThing('Stuff', '" m1 "');") ; will execute the javascript with the saved pattern, again adjust any redacted information as needed
    break
  }
}
iWeb_Release(pDoc) ; releases the pointer to the page document
iWeb_Term() ; stops COM


iWeb_getTagLen(pdsp,tag,t="-1",r="-1",frm="") {

   If pWin:=iWeb_DomWin(pdsp,frm) ; doesn't this cover the frames already?
      result:=COM_Invoke(pWin,"document.all.tags[" tag "]"
       . ((tag="table" && t>=0) ? ".item[" t "].rows" : "") ((tag="table" && r>=0) ? "[" r "].cells" : "")
       . ".length")
   COM_Release(pWin)
   return result

}

iWeb_getTagObj(pdsp,tag,itm,r="-1",c="-1",type="innerText",frm="") {

   If pWin:=iWeb_DomWin(pdsp,frm)
      result:=COM_Invoke(pWin,"document.all.tags[" tag "].item[" itm "]"
       . ((tag="table" && r>=0) ? ".rows[" r "]" : "") ((tag="table" && c>=0) ? ".cells[" c "]" : "")
       . "." type)
   COM_Release(pWin)
   return result

}

IE_GetDocument(hWnd)
{
   Static
   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
}

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 9th, 2010, 7:40 pm 
Offline

Joined: September 2nd, 2008, 4:20 pm
Posts: 50
Oh man :D I love this place.

Thank you sinkfaze. I have no idea whether what you've given me works or not yet, but you've given me enough to be dangerous.

So from the look of it, I can take the entirety of COM and iWeb and merge them into my own AHK script, as libraries, correct?

Then I can play around with what you've given me as far as integration and debugging goes, correct?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 9th, 2010, 7:50 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
It's best to #Include them in your scripts rather than merging the code directly into them, but yes you could if you wanted to. Then you can play around with it a bit and see if you can get it to work. Since I don't have the page in front of me what I wrote should work in the abstract, but that's not a guarantee. Report back with any problems and download a copy of the iWeb recorder I mentioned earlier so you'll be able to check some things out for us in that event.

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 11th, 2010, 5:33 pm 
Offline

Joined: September 2nd, 2008, 4:20 pm
Posts: 50
I'd really like to get this to work so I'm going to post the exactly what I'm doing. The original unchanged link on the page is

Code:
javascript:runBreadCrumb('m_bdd982370a0a3c1b00cb7721a7e52b4c', 'incident','');


This is the test script I put together trying to get the script to execute on an F11 press:

Code:
SetTitleMatchMode 2
#SingleInstance Force
#Persistent
#Include com.ahk
#Include iweb.ahk

F11::jMatch:="i)^javascript:runBreadCrumb\('m_(\w+)', 'incident',''\);" ; regular expression to match the desired js call, if it matches it will capture the needed subpattern.  Adjust it for the information you redacted but leave these as is: \(, \) and (\w+).

iWeb_Init() ; starts COM
ControlGet,hWnd,Hwnd,,Internet Explorer_Server1, ahk_class IEFrame ; gets the window handle for the document interface in Internet Explorer
pDoc:=IE_GetDocument(hWnd) ; creates an pointer to access the page document
Loop % iWeb_getTagLen(pDoc,"A") { ; loops through all of the link elements on the page
  if RegExMatch(iWeb_getTagObj(pDoc,"A",A_Index-1,-1,-1,"href"),jMatch,m) { ; checks to see if the href of the element matches our regular expression search
    iWeb_execScript(pDoc,"javascript:saveAttachment('incident', '" m1 "');") ; will execute the javascript with the saved pattern, again adjust any redacted information as needed
    break
  }
}
iWeb_Release(pDoc) ; releases the pointer to the page document
iWeb_Term() ; stops COM


iWeb_getTagLen(pdsp,tag,t="-1",r="-1",frm="") {

   If pWin:=iWeb_DomWin(pdsp,frm) ; doesn't this cover the frames already?
      result:=COM_Invoke(pWin,"document.all.tags[" tag "]"
       . ((tag="table" && t>=0) ? ".item[" t "].rows" : "") ((tag="table" && r>=0) ? "[" r "].cells" : "")
       . ".length")
   COM_Release(pWin)
   return result

}

iWeb_getTagObj(pdsp,tag,itm,r="-1",c="-1",type="innerText",frm="") {

   If pWin:=iWeb_DomWin(pdsp,frm)
      result:=COM_Invoke(pWin,"document.all.tags[" tag "].item[" itm "]"
       . ((tag="table" && r>=0) ? ".rows[" r "]" : "") ((tag="table" && c>=0) ? ".cells[" c "]" : "")
       . "." type)
   COM_Release(pWin)
   return result

}

IE_GetDocument(hWnd)
{
   Static
   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
}
return


So I'm hitting F11 and on the page I'd like this to work on and nothing happens.

When I look at the AHK log I see:

010: Return (23.73)
010: jMatch := "i)^javascript:runBreadCrumb\('m_(\w+)', 'incident',''\);"
010: Return (33.39)
010: jMatch := "i)^javascript:runBreadCrumb\('m_(\w+)', 'incident',''\);"
010: Return (3.03)

Thats for 2 different presses of F11


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 11th, 2010, 6:38 pm 
Offline

Joined: October 15th, 2007, 3:10 pm
Posts: 790
Location: England
Add a newline after your hotkey:
Code:
F11::
jMatch:="i)^javascript:runBreadCrumb\('m_(\w+)', 'incident',''\);"


This seemed to make it work for me, for a test page I made.

If you get a COM error about execScript, it probably means there is something wrong with your javascript function call (e.g. it doesn't exist), so check that.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 11th, 2010, 6:57 pm 
Offline

Joined: September 2nd, 2008, 4:20 pm
Posts: 50
Ah, better, with the carriage return now I get this in the log when I press F11:

Code:
deleted


Last edited by iguru42 on February 11th, 2010, 9:52 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 11th, 2010, 9:05 pm 
Offline

Joined: October 15th, 2007, 3:10 pm
Posts: 790
Location: England
That doesn't really help... did it do anything in your web page?

Try changing this:
Code:
iWeb_execScript(pDoc,"javascript:saveAttachment('incident', '" m1 "');")


to this (temporarily):
Code:
iWeb_execScript(pDoc,"javascript:alert('hello');")


Run the script again - did your web page say "hello" with an alert message box?

Maybe you got an IE warning "information bar" about some script that "is trying to run active content bla bla bla" - you will have to allow the script to do this and then try again.

Post what you get.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 11th, 2010, 9:11 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
iWeb_clickHref is capable of clicking a link that is a partial match for the parameter, try this:

Code:
iWeb_clickHref(pwb,"javascript:saveAttachment('incident',")

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 11th, 2010, 9:56 pm 
Offline

Joined: September 2nd, 2008, 4:20 pm
Posts: 50
OceanMachine wrote:
That doesn't really help... did it do anything in your web page?

Try changing this:
Code:
iWeb_execScript(pDoc,"javascript:saveAttachment('incident', '" m1 "');")


to this (temporarily):
Code:
iWeb_execScript(pDoc,"javascript:alert('hello');")


Run the script again - did your web page say "hello" with an alert message box?

Maybe you got an IE warning "information bar" about some script that "is trying to run active content bla bla bla" - you will have to allow the script to do this and then try again.

Post what you get.


K since the posted code wasn't helpful and was widening the page for no reason I deleted it.

made the change you suggested, hit F11, nothing.

edited the script down to

Code:
F11::iWeb_execScript(pDoc,"javascript:alert('hello');") ; will execute the javascript with the saved pattern, again adjust any redacted information as needed


Nothing.

Pasted

Code:
javascript:alert('hello')


into the address bar and hit enter, got the hello box to pop up.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 11th, 2010, 10:06 pm 
Offline

Joined: July 6th, 2009, 9:58 pm
Posts: 678
I'm not sure if this will help, but it seems that in at least some capacity you can drop java into the command shell as well.

Start > run > javascript:alert('hello')
Code:
Run, javascript:alert('hello')


They just load and close an IE window, probably displaying the alert beforehand, however my thinking in posting this is that it might work with whatever java code you are actually using from the page (maybe while the page is open and focused)...

Or perhaps,
Code:
Run, iexplore.exe "javascript:alert('hello')"


Should be the same. Not sure if this helps you guys. Doesn't seem to keep a page active but there might be java for that as well.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 29 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Alpha Bravo, LazyMan, rbrtryn and 26 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group