Get img src onmouseover. Also read Properties popup window.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Visioneer
Posts: 140
Joined: 07 Oct 2013, 18:51

Get img src onmouseover. Also read Properties popup window.

31 Aug 2017, 14:36

Hi,

I almost had this years ago in this old post which is obsolete now anyway.

https://autohotkey.com/board/topic/3078 ... up-window/

Maybe tank could finish it up.

I want to get the src of any image "img" picture, jpg, png, gif etc., whether in a frame or not,
which is under the mouse's cursor, or onmouseover by simple moving the mouse a little.
No clicking, as the photo is often a link itself.

I do it now with IE_Inject which mostly succeeds.

Code: Select all

 
myL = var QxQ = ""; var i,x; for(i=0; x=document.getElementsByTagName("img")[i];++i) { x.onmouseover=function(){ QxQ=this.src; } }
IE_InjectJS(WinExist("ahk_class IEFrame"), myL)

IE_InjectJS(WinExist("ahk_class IEFrame"), myL)
MouseMove, %myX%, %myY%   ;to trigger the js onmouseover.

fURL := IE_InjectJS(WinExist("ahk_class IEFrame"), "", "QxQ")
This gets the js src value.

Maybe not in frames. I would like a COM way that works in frames or not.

Another way to do this, and many other things BTW, is to right-click on the image, and send r
to open the Properties popup window. Then I could try to read the values inside. Although, some websites
block the right-click, so maybe it can be opened by COM? Then reading the Property window consistently
has been difficult also.

I am also interested in latest COM ways to inject JavaScript.
I'm using AHK_L Unicode with W7, IE11 but I want it to work with all IE and Windows OSS.

Thanks
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Get img src onmouseover. Also read Properties popup window.

01 Sep 2017, 02:31

I just use the code here, I've since turned the original code into a function. And then do oElt.src to get the image url. Cheers.
Internet Explorer get element under cursor (show borders, show text) (any zoom percentage) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 48#p168248
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Visioneer
Posts: 140
Joined: 07 Oct 2013, 18:51

Re: Get img src onmouseover. Also read Properties popup window.

01 Sep 2017, 20:22

Wow. jeeswg. Wow.

I don't know whether to reply here or on the post you linked to. That is divine fantastic work.
I don't for sure yet, but could the function possibly be inhibiting the StatusBarGetText that
I use when the src is Google (and possible others) using data:image... for element src.
If src starts with that I do.

StatusBarGetText, myL, 1, ahk_class IEFrame
myL := urlDecode(myL)
myL = var mySS = "%myL%"; mySS = mySS.split('imgurl=')[1].split('&')[0];
fURL := IE_InjectJS(WinExist("ahk_class IEFrame"), myL, "mySS")
I could probably parse it with AHK but this was so easy I used IE_Inject
and JavaScript.

But it seems that more than usual the StatusBarGetText comes up null,
even when I can see it on the screen.

Could your function somehow get the URL of photo even when they use
that data:image thing? It is easy for the StatusBar to get blank, for example
if I refresh the page, it goes blank. I imagine some folks are trying to get
it to not be displayed anyway.

What is all the data:image/jpeg;base64,/9j/4AAQSkZJRg...... about
anyway? Could it yield altenate url somehow?

Thanks
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Get img src onmouseover. Also read Properties popup window.

01 Sep 2017, 21:07

base64 is a bit like hex, it's a way of storing data in a string from, if you search for 'AutoHotkey base64' you'll find some functions to help convert the base64 string to binary data, you can then use an AutoHotkey File object with RawWrite to save that data to a file.

I don't know whether my function would interfere with the status bar or not, the only thing I can think of is to try clearing objects, but I don't have much specific knowledge on how COM objects work behind the scenes in Internet Explorer, AutoHotkey or other programs.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Visioneer
Posts: 140
Joined: 07 Oct 2013, 18:51

Re: Get img src onmouseover. Also read Properties popup window.

01 Sep 2017, 22:58

Ok, a little detective work. I looked at the true outerHTML of this Google page for an img in question.
https://www.google.com/search?tbm=isch& ... 4DR2Sgcn1k

One of many in a long notepad string of outerHTML. The [img] is actually part of an [a} element.
The href of the [a] is what I would need to start with.
So if your function saw "data:image..." in the src, it could try to get the img "parent' [a]'s href.

which is this:
href="/imgres?imgurl=https%3A%2F%2Fstatic.pexels.com%2Fphotos%2F87452%2Fflowers-background-butterflies-beautiful-87452.jpeg&imgrefurl=https%3A%2F%2Fwww.pexels.com%2Fsearch%2Fflowers%2F&docid=nVrbZ6x84_QItM&tbnid=ok3Ujapxrx5yrM%3A&vet=10ahUKEwialcGnp4XWAhXBOSYKHYuhBSAQMwiNAigDMAM..i&w=2144&h=1424&bih=658&biw=1280&q=flowers&ved=0ahUKEwialcGnp4XWAhXBOSYKHYuhBSAQMwiNAigDMAM&iact=mrc&uact=8"

I could urlDecode(URL) this before or after parsing as shown above. "imgurl=" to first "&" character is the URL needed.
Easy with IE_Inject as shown below. Just get me the "href" I think, as this data:image method may use different formats.
Then I can parse it as needed based on LocationURL I guess. Google's format is by far the only one to worry about.

I or you could parse it as I have shown in my IE_Inject function shown here.
myL = var mySS = "%myL%"; mySS = mySS.split('imgurl=')[1].split('&')[0];
fURL := IE_InjectJS(WinExist("ahk_class IEFrame"), myL, "mySS")

This would be consistent whether the StatusBar for StatusBarGetText is showing or not. We would not even
look at the StatusBar. Our fURL data would come from the href of the <a .. element. Maybe that would just
be the parentNode of the img element?

If you do this yourself, just search for 'background-butterflies" in your text editor"
I get the active outerHTML with:
+F1::
wb := WBGet("ahk_class IEFrame")
myL := wb.document.all.item[0].outerHTML
;then put this var into Edit1 of notepad.

This is the actual innerHTML in the pages outerHTML:
<a class="rg_l" style="left: 0px; width: 263px; height: 161px;"
href="/imgres?imgurl=https%3A%2F%2Fstatic.pexels.com%2Fphotos%2F87452%2Fflowers-background-butterflies-beautiful-87452.jpeg&imgrefurl=https%3A%2F%2Fwww.pexels.com%2Fsearch%2Fflowers%2F&docid=nVrbZ6x84_QItM&tbnid=ok3Ujapxrx5yrM%3A&vet=10ahUKEwialcGnp4XWAhXBOSYKHYuhBSAQMwiNAigDMAM..i&w=2144&h=1424&bih=658&biw=1280&q=flowers&ved=0ahUKEwialcGnp4XWAhXBOSYKHYuhBSAQMwiNAigDMAM&iact=mrc&uact=8"
rel="noopener" jsaction="fire.ivg_o;mouseover:str.hmov;mouseout:str.hmou" jsname="hSRGPd">
<img name="ok3Ujapxrx5yrM:" class="rg_ic rg_i" style="width: 263px; height: 174px; margin-top: 0px; margin-right: 0px; margin-left: 0px;" onload="typeof google==='object'&&google.aft&&google.aft(this)" alt="Image result for flowers"
src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxITEhUSEhIVFRUXFxxYVF...miles long here...jsaction="load:str.tbn" data-sz="f">

This is the URL that would be (ahk's) urlDecode(URL) to yield what I need:
https%3A%2F%2Fstatic.pexels.com%2Fphotos%2F87452%2Fflowers-background-butterflies-beautiful-87452.jpeg
to produce this
https://static.pexels.com/photos/87452/ ... 87452.jpeg
which is the URL I need.

Messing with the hex code would not do us any good anyway. The URL of the photo is what I need.

Hope this helps.

Thanks
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Get img src onmouseover. Also read Properties popup window.

01 Sep 2017, 23:14

Try this:

Code: Select all

q::
WinGet, hWnd, ID, A
oWB := WBGet("ahk_id " hWnd)
JEE_IntExpGetEltUnderCursor(oWB, oElt)
;JEE_IntExpEltGetPos(hWnd, oWB, oElt, vEltX, vEltY, vEltW, vEltH)
;JEE_Borders(vEltX, vEltY, vEltW, vEltH)
vHref := oElt.parentNode.href
MsgBox, % vHref
if !(vPos1 := InStr(vHref, "?imgurl="))
|| !(vPos2 := InStr(vHref, "&imgrefurl=", 0, vPos1+8))
	return
MsgBox, % SubStr(vHref, vPos1+8, vPos2-vPos1-8)
oWB := oElt := ""
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Visioneer
Posts: 140
Joined: 07 Oct 2013, 18:51

Re: Get img src onmouseover. Also read Properties popup window.

02 Sep 2017, 00:28

This is what I came up with.
The ByRef param is cool. The whole function is cool
it gives me a reference to the "element" under the cursor,
not just an img. The parentNode gets me both one or the other

if InStr(oElt.src, "data:image")
fURL := oElt.parentNode.href
else
fURL := oElt.src

Afterwards from there I can see if fURL contains imgurl=
and urlDecode/parse fURL accordingly.

What is the COM way to do something like this?
fURL := urlDecode(fURL)
myL = var mySS = "%fURL%"; mySS = mySS.split('imgurl=')[1].split('&')[0];
fURL := IE_InjectJS(WinExist("ahk_class IEFrame"), myL, "mySS")
this?

BTW: I like your:
wb.ExecWB(63, 2, 130, 0)
better than
send, ^0
That good for all IE versions?
Visioneer
Posts: 140
Joined: 07 Oct 2013, 18:51

Re: Get img src onmouseover. Also read Properties popup window.

02 Sep 2017, 12:10

Hi jeeswg,

What is the COM way to do something like this?
fURL := urlDecode(fURL)
myL = var mySS = "%fURL%"; mySS = mySS.split('imgurl=')[1].split('&')[0];
fURL := IE_InjectJS(WinExist("ahk_class IEFrame"), myL, "mySS")
this?

BTW: I like your:
wb.ExecWB(63, 2, 130, 0)
better than
send, ^0
That good for all IE versions?

Thanks
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Get img src onmouseover. Also read Properties popup window.

02 Sep 2017, 12:24

Using the script from earlier, take vHref and apply this, although this is a string manipulation issue rather than a JavaScript issue, although interestingly it appears that you had previously got JavaScript to do this for you:

Code: Select all

oArray := StrSplit(vHref, ["imgurl=","&"])
MsgBox, % oArray.2
I don't really know re. ExecWB and version numbers. I believe ExecWB goes a fair way back, but I've only tested it on Internet Explorer 11, I believe it worked on Internet Explorer_Server controls created via AutoHotkey, which I believe use the equivalent of an earlier version of Internet Explorer.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Visioneer
Posts: 140
Joined: 07 Oct 2013, 18:51

Re: Get img src onmouseover. Also read Properties popup window.

02 Sep 2017, 18:05

Yes jeeswg,

Unless the splitting is in a function, you wind up with:
"If you do not need the substrings to be permanently stored in memory, consider using a parsing loop -- especially if InputVar is very large, in which case a large amount of memory would be saved"
vars you don't need. I could use 2 parsing loops, but that is a lot longer than my simple JavaScript method.

I was hoping the question would result in a simple way to inject JavaScript or even just run JavaScript, and maybe even get a value(s)
back, like IE_Inject does.

I know that I used to use ^0 to set zoom to 100% way back in XP. I'll look at WBExec more closely. Anyway, please add that to the
COM terms & tech manual. The links may also be to Microsoft I suppose.

Do you think my jump to text within a page function can be incorporated into an online or chm help file/program?
https://autohotkey.com/boards/viewtopic ... 19#p168519

Thanks
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Get img src onmouseover. Also read Properties popup window.

02 Sep 2017, 18:57

I don't really know about incorporating that function. If it was your own website, a good approach would be to add more fragment identifiers to pages. Perhaps you can include that in the html inside a webpage or chm file, but I'm not too familiar with scripts within html.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 117 guests