Skip to content

Instantly share code, notes, and snippets.

@tmplinshi
Created September 6, 2019 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmplinshi/ae149234ed79b8fc68040c8ce78cd949 to your computer and use it in GitHub Desktop.
Save tmplinshi/ae149234ed79b8fc68040c8ce78cd949 to your computer and use it in GitHub Desktop.
; js := "void(document.getElementById('keywords').value='Hello world 1')"
; ChromeRunJs(js)
ChromeRunJs(ByRef js) {
static addrBar
if !addrBar || !WinExist("ahk_id " addrBar.hWnd) {
if !addrBar := FindAddressBar() {
throw "FindAddressBar failed."
}
}
addrBar.accObj.accValue(0) := "javascript" . Chr(58) . js
addrBar.accObj.accSelect(0x1, 0)
ControlSend,, {Enter}
}
FindAddressBar(WinTitle := "ahk_exe chrome.exe", oAcc := "", accPath := "") {
if !oAcc {
if hWnd := WinExist(WinTitle) {
oAcc := Acc_ObjectFromWindow(hWnd)
while oAcc.accRole(0) != 9 { ; ROLE_SYSTEM_WINDOW := 9
oAcc := Acc_Parent(oAcc)
}
} else {
throw WinTitle " not found."
}
}
for i, child in Acc_Children(oAcc) {
nRole := child.accRole(0)
if (nRole = 42) { ; ROLE_SYSTEM_TEXT := 42
if (child.accName(0) ~= "i)address|地址") {
accPath := LTrim(accPath "." i, ".")
return {accObj: child, accPath: accPath, hWnd: hWnd}
}
}
/*
ROLE_SYSTEM_APPLICATION := 14
ROLE_SYSTEM_PANE := 16
ROLE_SYSTEM_GROUPING := 20
ROLE_SYSTEM_TOOLBAR := 22
ROLE_SYSTEM_COMBOBOX := 46
*/
static oGroup := {14:1, 16:1, 20:1, 22:1, 46:1}
if oGroup.HasKey(nRole) {
if result := FindAddressBar(, child, accPath "." i) {
return result
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment