-
Notifications
You must be signed in to change notification settings - Fork 28
/
Do-Javascript-Handler.applescript
50 lines (46 loc) · 1.54 KB
/
Do-Javascript-Handler.applescript
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
-- @Description
-- Performs basic JavaScript actions in Safari
-- @param - theAction: get, set, click, submit
-- @param - theType: id, class, etc
-- @param - id: the string associated with the object
-- @param - num: the index of the object
-- @param - theValue: value an object is to be set to (set to missing value by default)
-- @param - theTab: the tab the action is to be performed in
--
on doJava:theAction onType:theType withIdentifier:theID withElementNum:num withSetValue:theValue inTab:thetab
if theType = "id" then
set getBy to "getElementById"
set theJavaEnd to ""
else
if theType = "class" then
set theType to "ClassName"
else if theType = "name" then
set theType to "Name"
else if theType = "tag" then
set theType to "TagName"
end if
set getBy to "getElementsBy" & theType
set theJavaEnd to "[" & num & "]"
end if
if theAction = "click" then
set theJavaEnd to theJavaEnd & ".click();"
else if theAction = "get" then
set theJavaEnd to theJavaEnd & ".innerHTML;"
else if theAction = "set" then
set theJavaEnd to theJavaEnd & ".value ='" & theValue & "';"
else if theAction = "submit" then
else if theAction = "force" then
end if
set theJava to "document." & getBy & "('" & theID & "')" & theJavaEnd
tell application "Safari"
if thetab is missing value then set thetab to front document
tell thetab
if theAction = "get" then
set input to do JavaScript theJava
return input
else
do JavaScript theJava
end if
end tell
end tell
end doJava:onType:withIdentifier:withElementNum:withSetValue:inTab: