#Warn
#NoEnv
#SingleInstance Force
SetBatchLines -1
arr := []
WinGet, id, list,,, Program Manager
Loop, %id%
{
this_id := id%A_Index%
WinGetClass, this_class, ahk_id %this_id%
If (this_class = "IEFrame") {
WinGetTitle, this_title, ahk_id %this_id%
arr.push(["IE",this_title])
}
Else If (this_class = "HTML Application Host Window Class") {
WinGetTitle, this_title, ahk_id %this_id%
arr.push(["HTA",this_title])
}
}
acount := arr.MaxIndex()
If (!acount) {
MsgBox 0x30, , Not HTA or Internet Explorer window found!
ExitApp
}
Else If (acount = 1){
COM_Connect(arr[1][2])
ExitApp
}
Else {
Loop % acount {
Menu, MyMenu, Add, % arr[A_Index][1] "`t" arr[A_Index][2], MenuHandler
}
Menu, MyMenu, Show
return
}
MenuHandler:
COM_Connect(RegExReplace(A_ThisMenuItem, "^\S*?\t", ""))
ExitApp
COM_Connect(win_title){
pwin := WBGet(win_title)
If (pwin){
doc := pwin.document
; Извлекаем со страницы выделенный текст (если ничего не выделено, то весь)
html := doc.selection.createRange().htmlText
If (!html)
html := doc.documentElement.outerHTML
; Записываем полученный текст во временный файл
EnvGet, TEMP, TEMP
EnvGet, WINDIR, WINDIR
tmp := % TEMP "\$tmp.html"
FileDelete, % tmp
FileAppend, % html, % tmp
; Находим редактор, заданный для редактирования HTML
RegRead, editor, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Internet Explorer\View Source Editor\Editor Name
If (!editor)
editor := % WINDIR "\notepad.exe"
Run % editor " " tmp
} else {
MsgBox 0x30, , Could not connect to DOM!
}
}
; https://autohotkey.com/board/topic/47052-basic-webpage-controls-with-javascript-com-tutorial/
WBGet(WinTitle="ahk_class IEFrame", Svr#=1) { ; based on ComObjQuery docs
static msg := DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT")
, IID := "{332C4427-26CB-11D0-B483-00C04FD90119}" ; IID_IHTMLWindow2 (работает с IE и с HTA)
; , IID := "{0002DF05-0000-0000-C000-000000000046}" ; IID_IWebBrowserApp (работает только с IE)
SendMessage msg, 0, 0, Internet Explorer_Server%Svr#%, %WinTitle%
if (ErrorLevel != "FAIL") {
lResult:=ErrorLevel, VarSetCapacity(GUID,16,0), pdoc:=""
if DllCall("ole32\CLSIDFromString", "wstr","{332C4425-26CB-11D0-B483-00C04FD90119}", "ptr",&GUID) >= 0 {
DllCall("oleacc\ObjectFromLresult", "ptr",lResult, "ptr",&GUID, "ptr",0, "ptr*",pdoc)
return ComObj(9,ComObjQuery(pdoc,IID,IID),1), ObjRelease(pdoc)
}
}
}