-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patheiea.vbs
241 lines (213 loc) · 5.43 KB
/
eiea.vbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
Class EasyIEAutomate
'''
' OBJECTS
'
Private classIE
Private classWSS
Private classSHELL
'''
' EVENTS
'
Private Sub Class_Initialize
Set classIE = Nothing
Set classWSS = CreateObject("WScript.Shell")
Set classSHELL = CreateObject("Shell.Application")
End Sub
Private Sub Class_Terminate
Set classIE = Nothing
Set classWSS = Nothing
Set classSHELL = Nothing
End Sub
'''
' CONSTRUCTOR
'
Public Default Function Init(obj)
If IsObject(obj) Then
If obj Is Nothing Then
Set classIE = Nothing
ElseIf IsIE(obj) Then
Set classIE = obj
End If
ElseIf IsNumeric(obj) Then
If obj = vbUseDefault Then
Set classIE = CreateObject("InternetExplorer.Application")
End If
End If
Set Init = Me
End Function
'''
' PROPERTIES
'
Public Property Get Avail
Dim process, list : list = Array()
For Each process In classSHELL.Windows
If IsIE(process) Then
ReDim Preserve list(UBound(list) + 1)
Set list(UBound(list)) = process
End If
Next
Avail = list
End Property
Public Property Get Base
If classIE Is Nothing Then
Call noInitMsg()
End If
Set Base = classIE
End Property
Public Property Get Url
If classIE Is Nothing Then
Call noInitMsg()
Url = ""
Else
Url = classIE.LocationURL
End If
End Property
Public Property Get Title
If classIE Is Nothing Then
Call noInitMsg()
Title = ""
Else
Title = classIE.LocationName
End If
End Property
'''
' METHODS
'
Public Sub Close()
If classIE Is Nothing Then
Call noInitMsg()
Else
classIE.Quit
End If
End Sub
Public Sub CloseAll()
Dim window
For Each window In classSHELL.Windows
If IsIE(window) Then : window.Quit : End If
Next
End Sub
Public Sub Show()
Call autoInit()
classIE.Visible = True
End Sub
Public Sub Hide()
Call autoInit()
classIE.Visible = False
End Sub
Public Sub Center()
Call WaitForLoad()
On Error Resume Next
With classIE.Document.ParentWindow.screen
classIE.Left = (.width - classIE.Width) / 2
classIE.Top = (.height - classIE.Height) / 2
End With
If Err.Number = 505 Then
Navigate "about:blank"
Center()
End If
End Sub
Public Sub Navigate(url)
Call autoInit()
classIE.Navigate2 url
End Sub
Public Sub NavigateTab(url)
Call autoInit()
classIE.Navigate2 url, 2048
End Sub
Public Sub NavigateBgTab(url)
Call autoInit()
classIE.Navigate2 url, 4096
End Sub
Public Sub WaitForLoad()
If classIE Is Nothing Then
Call noInitMsg()
Else
While (classIE.Busy) And Not (classIE.ReadyState = 4) : WScript.Sleep(400) : Wend
End If
End Sub
Public Sub DeepWaitForLoad(elem)
While Not (elem.ReadyState = "complete") : WScript.Sleep(400) : Wend
End Sub
Public Sub ReBase(ie)
Init(ie)
End Sub
Public Sub RePoint(url)
Dim window
For Each window in classSHELL.Windows
If IsIE(window) And (LCase(window.LocationURL) = LCase(url)) Then
Set classIE = window
Exit Sub
End If
Next
Call ErrorOut(strURL, "Internet Explorer")
End Sub
Public Sub Latest()
Dim window
For Each window In classSHELL.Windows
If IsIE(window) Then
Set classIE = window
Exit Sub
End If
Next
Call autoInit()
End Sub
Private Function IsIE(obj)
IsIE = CBool(Right(LCase(obj.FullName), 12) = "iexplore.exe")
End Function
Public Function Query(squery)
Call WaitForLoad()
On Error Resume Next
Dim element
Set element = classIE.Document.querySelector(squery)
If Err.Number = 0 Then
Set Query = element
Else
Call ErrorOut(squery, classIE.LocationURL)
End If
End Function
Public Function QueryAll(squery)
Call WaitForLoad()
On Error Resume Next
Dim elements
Set elements = classIE.Document.querySelectorAll(squery)
If Err.Number = 0 Then
Set QueryAll = elements
Else
Call ErrorOut(squery, classIE.LocationURL)
End If
End Function
Public Function Deeper(squery)
Call WaitForLoad()
On Error Resume Next
Dim element
Set element = classIE.Document.querySelector(squery)
If Err.Number = 0 Then
Call DeepWaitForLoad(element)
Set Deeper = element.contentDocument
If Err.Number = -2147024891 Then
MsgBox "ERROR: Deeper(""" & squery & """)" & vbLf & vbLf & "Same Origin Policy Violated.", vbCritical, "EasyIEAutomate: " & Err.Description
WScript.Quit
End If
Else
Call ErrorOut(squery, classIE.LocationURL)
End If
End Function
'''
' ERROR HANDLING
'
Private Sub ErrorOut(item, at)
MsgBox _
"CANNOT FIND [ " & item & " ]" & vbLf & _
"AT [ " & at & " ]", vbCritical
WScript.quit
End Sub
Private Sub autoInit()
If classIE Is Nothing Then
classWSS.PopUp "Auto initialized a new IE object.", 1, "EasyIEAutomate"
Set classIE = CreateObject("InternetExplorer.Application")
End If
End Sub
Private Sub noInitMsg()
classWSS.PopUp "Not yet initialized.", 1, "EasyIEAutomate"
End Sub
End Class