webpages: get icon urls

Get help with using AutoHotkey and its commands and hotkeys
User avatar
jeeswg
Posts: 5555
Joined: 19 Dec 2016, 01:58
Location: UK

webpages: get icon urls

26 Oct 2017, 00:43

I wrote a script that tries to list a webpage's icon urls. I'm posting here in case anyone has any suggestions to improve it e.g. if some icon urls are being missed by the script.

Code: Select all

;WBGet function - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=6&t=39869

q:: ;internet explorer - get icon urls
WinGet, hWnd, ID, A
oWB := WBGet("ahk_id " hWnd)
oArray := []
vListEltTag := "link,meta"
Loop, Parse, vListEltTag, % ","
{
	vEltTag := A_LoopField
	oElts := oWB.document.getElementsByTagName(vEltTag)
	Loop, % oElts.length
	{
		oElt := oElts[A_Index-1]
		vTypeHref := (vEltTag = "meta") ? "content" : "href"
		try vUrl := oElt[vTypeHref]
		catch
			continue
		;e.g. rel: icon,mask-icon,shortcut icon,apple-touch-icon,apple-touch-icon-precomposed
		;e.g. name: msapplication-square150x150logo,msapplication-square310x310logo,msapplication-square70x70logo,msapplication-TileImage,msapplication-wide310x150logo
		vTypeRel := (vEltTag = "meta") ? "name" : "rel"
		vRel := ""
		try vRel := oElt[vTypeRel]
		if (vUrl ~= "favicon|\.ico") || (vRel ~= "icon|logo|square|tile")
			oArray.Push(vUrl)
	}
}

vUrl := oWB.document.url
oWB := oElts := oElt := ""
SplitPath, vUrl, vName, vDir, vExt, vNameNoExt, vDrive
vUrl1 := vDrive "/favicon.ico"
if (SubStr(vUrl1, 1, 7) = "http://")
	vUrl2 := "https://" SubStr(vUrl1, 8)
else if (SubStr(vUrl1, 1, 8) = "https://")
	vUrl2 := "http://" SubStr(vUrl1, 9)
else
	vUrl2 := ""
vOutput := "list:`r`n"
for vKey, vValue in oArray
	vOutput .= vKey " " vValue "`r`n"
vOutput .= "`r`n" "other possibilities:`r`n" vUrl1 "`r`n" vUrl2
oArray := ""
MsgBox, % vOutput
return

Return to “Ask For Help”

Who is online

Users browsing this forum: AHKStudent, Bing [Bot], Haasjes, jony26, SOTE and 61 guests