, here is my attempt, please kindly see if there is any way to improve. thank you.
Code: Select all
F1::GetAllYtvLinks("A")
GetAllYtvLinks(wTitle*) { ;based on the script by Descolada (https://www.autohotkey.com/boards/viewtopic.php?p=459451#p459451)
ErrorLevel := 0
if !(wId := WinExist(wTitle*)) {
ErrorLevel := 1
return
}
IUIAutomation := ComObjCreate(CLSID_CUIAutomation := "{ff48dba4-60ef-4201-aa87-54103eef594e}", IID_IUIAutomation := "{30cbe57d-d9d0-452a-ab13-7ac5ac4825ee}")
DllCall(NumGet(NumGet(IUIAutomation+0)+21*A_PtrSize), "ptr", IUIAutomation, "ptr*", TrueCondition) ; IUIAutomation::CreateTrueCondition
DllCall(NumGet(NumGet(IUIAutomation+0)+6*A_PtrSize), "ptr", IUIAutomation, "ptr", wId, "ptr*", elementMain) ; IUIAutomation::ElementFromHandle
DllCall(NumGet(NumGet(elementMain+0)+6*A_PtrSize), "ptr", elementMain, "int", TreeScope_Descendants := 0x4, "ptr", TrueCondition, "ptr*", elementArray) ; IUIAutomationElement::FindAll
DllCall(NumGet(NumGet(elementArray+0)+3*A_PtrSize), "ptr", elementArray, "ptr*", aLen) ; IUIAutomationElementArray::get_Length
Loop, %aLen%
DllCall(NumGet(NumGet(elementArray+0)+4*A_PtrSize), "ptr", elementArray, "int", A_Index-1, "ptr*", currentElement) ; IUIAutomationElementArray::GetElement
,DllCall(NumGet(NumGet(currentElement+0)+10*A_PtrSize),"ptr",currentElement,"uint",30045,"ptr",(VarSetCapacity(currentValue,8+2*A_PtrSize)+NumPut(0,currentValue,0,"short")+NumPut(0,currentValue,8,"ptr"))*0+¤tValue) ;IUIAutomationElement::GetCurrentPropertyValue
,log.=InStr(v:=StrGet(NumGet(currentValue,8,"ptr"),"utf-16"),".youtube.com/watch?v=") ? v "`n" : ""
ObjRelease(currentElement)
ObjRelease(elementArray)
ObjRelease(elementMain)
ObjRelease(IUIAutomation)
If RegExMatch(log, "i)\.youtube\.com/watch\?v=.+?&index=")
Clipboard := RegExReplace(RegExReplace(log, "im`a)^(?!.+?\.youtube\.com/watch\?v=.+?&index=).+?(\R|$)"), "im`a)&(list|pageId)=.+?(?=\R|$)")
Else Clipboard := log
If StrLen(Clipboard)
MsgBox,, YouTube Video Links, Retrieved, 1
Else MsgBox, Not Any YouTube Video Link Is Found
return Clipboard
}