Skip to content

Commit

Permalink
Improved URL detection
Browse files Browse the repository at this point in the history
- Fix for #30
- All IE versions
- New Chrome versions
- Non language-specific approach
  • Loading branch information
anonymous1184 committed May 12, 2022
1 parent 4359820 commit e9a58ee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
8 changes: 4 additions & 4 deletions Lib/Match.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Match(Mode)
WinGet exe, ProcessName

; Get Url and it parts if browser
url := Match_ParseUrl(hWnd, exe)
url := Match_ParseUrl(hWnd, exe, activeClass)

matches := []
; Loop through the JSON
Expand Down Expand Up @@ -102,11 +102,11 @@ Match_ByUrl(Url, Entry)
}
}

Match_ParseUrl(hWnd, Exe)
Match_ParseUrl(hWnd, Exe, WinClass)
{
if !(Exe ~= "i)(chrome|msedge|firefox|iexplore|opera|min)\.")
if !(Exe ~= "i)^(chrome|msedge|firefox|iexplore|opera|min)\.exe")
return
Url := Url_Get(hWnd, InStr(Exe, "ie"))
Url := Url_Get(hWnd, WinClass)
if (url)
{
Url_Split(url, host, domain)
Expand Down
27 changes: 13 additions & 14 deletions Lib/Url.ahk
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@

Url_Get(hWnd, isIE := false)
Url_Get(hWnd, WinClass)
{
static cache := []
if (!cache.HasKey(hWnd) || isIE)

if (!cache.HasKey(hWnd))
{
oAcc := Acc_ObjectFromWindow(hWnd)
if (WinClass = "Chrome_WidgetWin_1") {
PostMessage 0x003D, 0, 1, Chrome_RenderWidgetHostHWND1
oAcc.accName(0)
}
cache[hWnd] := Url_GetAddressBar(oAcc)
}
try
Expand All @@ -13,23 +18,17 @@ Url_Get(hWnd, isIE := false)
{
cache.Delete(hWnd)
if InStr(e.Message, "800401FD")
return Url_Get(hWnd)
return Url_Get(hWnd, WinClass)
}
}

Url_GetAddressBar(oAcc)
{
; Firefox + Chromium-based + IE || Min Browser
if (oAcc.accValue(0))
{
if (oAcc.accRole(0) = 42 && InStr(oAcc.accName(0), "Address"))
|| (oAcc.accRole(0) = 15 && oAcc.accName(0) != "Min")
{
return oAcc
}
}
for _,accChild in Acc_Children(oAcc)
{
if (ComObjType(oAcc, "Name") != "IAccessible")
return
if (oAcc.accValue(0) ~= "^(?!file:.+\/Min\/App\/)\w+:")
return oAcc
for _,accChild in Acc_Children(oAcc) {
oAcc := Url_GetAddressBar(accChild)
if IsObject(oAcc)
return oAcc
Expand Down

0 comments on commit e9a58ee

Please sign in to comment.