Advertisement
anonymous1184

https://redd.it/vyifcn

Jul 14th, 2022
1,555
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #If WinActive("ahk_exe firefox.exe") && DomainSearch("google.com")
  3.     F1::MsgBox You are on Google!
  4. #If
  5.  
  6. DomainSearch(SearchDomain) {
  7.     url := GetUrl()
  8.     RegExMatch(url, "\/\/\K[^\/]+", urlDomain)
  9.     return !!InStr(urlDomain, SearchDomain)
  10. }
  11.  
  12. ; Version: 2022.07.06.1
  13. ; https://gist.github.com/7cce378c9dfdaf733cb3ca6df345b140
  14.  
  15. GetUrl()
  16. {
  17.     static conditions := []
  18.     hWnd := WinExist("A")
  19.     WinGetClass wClass
  20.     ; CLSID_CUIAutomation, IID_IUIAutomation
  21.     IUIAutomation := ComObjCreate("{ff48dba4-60ef-4201-aa87-54103eef594e}", "{30cbe57d-d9d0-452a-ab13-7ac5ac4825ee}")
  22.     ; IUIAutomation::ElementFromHandle
  23.     DllCall(NumGet(NumGet(IUIAutomation+0)+6*A_PtrSize), "Ptr",IUIAutomation, "Ptr",hWnd, "Ptr*",eRoot:=0)
  24.     ctrlTypeId := wClass ~= "Chrome" ? 50030 : 50004
  25.     if (conditions.HasKey(ctrlTypeId)) {
  26.         condition := conditions[ctrlTypeId]
  27.     } else {
  28.         VarSetCapacity(value, 8 + 2 * A_PtrSize), NumPut(3, value, 0, "UShort"), NumPut(ctrlTypeId, value, 8, "Ptr")
  29.         (A_PtrSize = 8)
  30.             ; IUIAutomation::CreatePropertyCondition
  31.             ? DllCall(NumGet(NumGet(IUIAutomation+0)+23*A_PtrSize), "Ptr",IUIAutomation, "UInt",30003, "Ptr",&value, "Ptr*",condition:=0)
  32.             : DllCall(NumGet(NumGet(IUIAutomation+0)+23*A_PtrSize), "Ptr",IUIAutomation, "UInt",30003, "UInt64",NumGet(value, 0, "UInt64"), "UInt64",NumGet(value, 8, "UInt64"), "Ptr*",condition:=0)
  33.     }
  34.     ; IUIAutomationElement::FindFirst
  35.     DllCall(NumGet(NumGet(eRoot+0)+5*A_PtrSize), "Ptr",eRoot, "UInt",0x4, "Ptr",condition, "Ptr*",eFirst:=0)
  36.     if (!eFirst)
  37.         return
  38.     VarSetCapacity(propertyValue, 8 + 2 * A_PtrSize), NumPut(0, propertyValue, 0, "UShort"), NumPut(0, propertyValue, 8, "Ptr")
  39.     ; IUIAutomationElement::GetCurrentPropertyValue
  40.     DllCall(NumGet(NumGet(eFirst+0)+10*A_PtrSize), "Ptr",eFirst, "UInt",30045, "Ptr",&propertyValue)
  41.     ObjRelease(eFirst), ObjRelease(eRoot), ObjRelease(IUIAutomation), eFirst := eRoot := IUIAutomation := ""
  42.     return StrGet(NumGet(propertyValue, 8, "Ptr"), "UTF-16")
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement