Skip to content

Instantly share code, notes, and snippets.

@tmplinshi
Last active March 12, 2019 01:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tmplinshi/8267668 to your computer and use it in GitHub Desktop.
Save tmplinshi/8267668 to your computer and use it in GitHub Desktop.
; DOM_Sample.ahk
; DOM Documentation:
; http://www.w3schools.com/jsref/dom_obj_all.asp
#NoEnv
#SingleInstance Force
SetBatchLines -1
ListLines Off
ComObjError(False)
; =================================
; GUI
; =================================
Gui, Margin, 0, 0
Gui Add, ActiveX, w800 h500 vWB, Shell.Explorer
Gui, Show
; =================================
; Open url, and wait for finish loading
; =================================
OpenLoginPage:
WB.Navigate("http://ahkscript.org/boards/ucp.php?mode=login")
While WB.readystate != 4 or WB.busy
Sleep 10
; Logout if already loged in
if !InStr(WB.LocationUrl, "login")
{
Gui, +OwnDialogs
MsgBox, 36, Logout Confirmation, Do you allow me to logout? (Because this script is for the login page.)
IfMsgBox, No
{
MsgBox, OK. Please logout manually, then run this script again. Bye.
ExitApp
}
; Logout
WB.document.getElementById("menubar").all.tags("a")[0].Click()
While WB.readystate != 4 or WB.busy
Sleep 10
Goto, OpenLoginPage
}
; =================================
; Modify web page
; =================================
doc := WB.doc
doc.getElementById("username").Disabled := True
doc.getElementById("password").Disabled := True
doc.getElementById("username").style.backgroundColor := "A0FABF"
doc.getElementById("password").style.backgroundColor := "FDCAAE"
doc.getElementById("login").value := "Click me to login :)"
doc.getElementById("login").style.Color := "Red"
doc.getElementById("login").style.backgroundColor := "FFFF00"
doc.images[0].src := "http://i1064.photobucket.com/albums/u361/tmplinshi/ahk_logo2_zps3dad3db9.png"
; =================================
; Monitor events
; =================================
; events for doc
ComObjConnect(doc, doc_events)
; events for the form of login button
form := doc.forms[0]
ComObjConnect(form, "LoginForm_")
; events for login button
LogInBtn := doc.getElementById("login")
ComObjConnect(LogInBtn, "LogInBtn_")
; events for the login button's parent <td>
LogInBtnPTD := LogInBtn.parentNode
ComObjConnect(LogInBtnPTD, "LogInBtnPTD_")
; =================================
; Timer settings for moving login button
; =================================
LogInBtn.style.position := "relative"
MoveStep := -50
BtnW := LogInBtn.offsetWidth
BtnPW := LogInBtn.parentNode.offsetWidth
SetTimer, Move_LogInBtn, 200
Return
; =================================
; move login button
; =================================
Move_LogInBtn:
x += MoveStep
LogInBtn.style.left := x
BtnX := LogInBtn.offsetLeft
MoveStep := ( BtnX < Abs(MoveStep) || (BtnX + BtnW >= BtnPW) ) ? -MoveStep : MoveStep
Return
; =================================
; Exit
; =================================
GuiClose:
ExitApp
; ================================================== Functions ==================================================
; =================================
; events for doc
; =================================
Class doc_events
{
oncontextmenu(doc) {
doc.parentWindow.event.returnvalue := False ; Cancel the event's action.
MsgBox, Right click disabled.
}
OnClick(doc) {
if doc.parentWindow.event.srcElement.name in username,password
doc.parentWindow.event.srcElement.value := doc.parentWindow.event.srcElement.name
}
ondblclick(doc) {
MsgBox, Double click detected.
}
}
; =================================
; ; events for the form of login button
; =================================
LoginForm_onsubmit(form) {
form.document.parentWindow.event.returnvalue := False ; Cancel the event's action.
form.document.getElementById("login").value := "Click me to login :)"
MsgBox, Login action canceled.
}
; =================================
; ; events for the login button's parent <td>
; =================================
LogInBtnPTD_onmouseover(LogInBtn) {
SetTimer, Move_LogInBtn, Off ; Stop moving login button
}
LogInBtnPTD_onmouseout(LogInBtn) {
SetTimer, Move_LogInBtn, 200 ; Resume moving login button
}
; =================================
; events for login button
; =================================
LogInBtn_onmouseover(LogInBtn) {
LogInBtn.style.backgroundColor := "FDD0FD"
}
LogInBtn_onmouseout(LogInBtn) {
LogInBtn.style.backgroundColor := "FFFF00"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment