-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathview-script
170 lines (150 loc) · 6.52 KB
/
view-script
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
set madeBy to "
Made by Araav Patel | UC Berkeley | Computer Science
"
set instructionMessage to "
Instructions
1. Download instacart-deliveryslot-finder.script
2. Open Safari on your Mac
3. Open Safari Preferences (command + comma key)
4. Click Advanced
5. Checkmark the “Show develop menu in menu bar” option
6. Go back to Safari window
7. Click Develop on the Menu Bar
8. Enable “Allow JavaScript from Apple Events”
9. Open Instacart and fill up your cart
10. Go to Checkout after you have placed everything you wanted in your cart
11. Choose your delivery address
12. Your screen should show an Image with 'No Delivery times available'
13. Open up the downloaded script in Script Editor and click the Run Button (3rd Button on the top)
14. Make sure your volume is on because the script will give a sound notification once a delivery slot becomes available
"
set howitWorks to "
How the Script Works
1. Opens a new window with Instacart and refreshes it around every 30 seconds
2. Checks to see if a delivery slot is available
3. If it is available, it will send a desktop notification with sound and/or an email if you had selected the option
"
set variableNotDefined to "
If you receive the error 'input not defined' after the script opens a new tab with the Instacart website:
then,
1. cntrl-f
2. search for 'error fixing statement'
3. for the line right underneath, which should say 'delay 15', you want to change the number 15 (in seconds) to the number of seconds it takes for the Instacart website to load
"
-- Declare variables
set welcomeMessage to "Welcome to Instacart Delivery Slot Search Tool!"
set instaURL to "https://www.instacart.com/store/checkout_v3"
set no_delivery to "No delivery times available"
set no_delivery2 to "Sorry, we're fresh out of same-day delivery options at this store"
set minimize_window to true
set delivery_openslot to false
set first_time to true
set mail_notif to false
set user_mail_address to ""
set input to "Not Found"
-- Declare functions
-- Welcome Message
display dialog welcomeMessage with title "Welcome" with icon stop buttons {"Cancel", "Continue"} default button "Continue"
-- Whether user wants mail notifications in addition to desktop notification
set user_mail_notif to display dialog "Do you want to receive a mail notification when there is a delivery slot available? Only do this if your Mail Application is synced to your email or else it may cause issues" buttons {"No", "Yes"} with icon note with title "Mail Notifications"
-- The mail will be sent from the default email on the Mail App
if button returned of user_mail_notif = "Yes" then
set user_mail_input to display dialog "What is your email address" default answer ""
set user_mail_address to text returned of user_mail_input
set mail_notif to true
else if button returned of user_mail_notif = "No" then
set mail_notif to false
end if
-- Opens new window
tell application "Safari"
make new document
delay 15
set instaURL_id to id of front window
end tell
-- Repeats until the script finds a delivery slot available
repeat while delivery_openslot is false
-- Opens Instacart tab
tell application "Safari"
tell window id instaURL_id
make new tab with properties {URL:instaURL}
set current tab to last tab
end tell
-- Minimizes the window and runs in background
if first_time is true then
set miniaturized of window id instaURL_id to true
set first_time to false
end if
-- error fixing statement
delay 15
repeat until (do JavaScript "document.readyState" in tab -1 of window id instaURL_id) is "complete"
if (do JavaScript "document.readyState" in tab -1 of window id instaURL_id) is "complete" then
exit repeat
log "exited repeat"
end if
end repeat
delay 15
end tell
-- Reads HTML text on page and looks for whether delivery slot is open or not
tell application "Safari"
set input to do JavaScript "document.getElementsByClassName('" & "rmq-28f9c13a rmq-8e4e203" & "')[" & 0 & "].innerHTML;" in tab -1 of window id instaURL_id
end tell
-- Refreshes by closing previous page and opening a new one
if input contains no_delivery or input contains no_delivery2 then
tell application "Safari"
-- close (last tab of window id instaURL_id)
repeat with i from (count of windows) to 1 by -1
repeat with j from (count of tabs of window i) to 1 by -1
set index_tab to tab j of window i
set name_of_tab to name of index_tab
if name_of_tab contains "Instacart -" then close index_tab
end repeat
end repeat
end tell
log "no slots found"
delay 10
else if input is "Not Found" then
log "error caused"
else if input contains "CHOOSE" and input contains "$" and (input contains "Today" or input contains "SUN" or input contains "MON" or input contains "TUE" or input contains "WED" or input contains "THU" or input contains "FRI" or input contains "SAT") then
if input contains "all shoppers are busy" then
tell application "Safari"
close (last tab of window id instaURL_id)
end tell
log "no slots found"
delay 10
else
-- Sends notifications through desktop notification or mail (if user allowed)
display notification "Found an available delivery slot!" with title "Instacart" sound name "Sosumi"
say "Delivery slot appeared. Try to checkout."
if mail_notif is true then
tell application "Mail"
set theMessage to make new outgoing message with properties {subject:"Instacart Delivery Slot Found!", content:"Check the Instacart Website! There is a delivery slot available! Try to checkout!", visible:true}
tell theMessage
make new to recipient with properties {address:user_mail_address}
send
end tell
end tell
end if
set delivery_openslot to true
log "Script found 'CHOOSE' slot"
end if
(*else
-- Sends notifications through desktop notification or mail (if user allowed)
display notification "Found an available delivery slot!" with title "Instacart" sound name "Sosumi"
say "Delivery slot appeared. Try to checkout."
if mail_notif is true then
tell application "Mail"
set theMessage to make new outgoing message with properties {subject:"Instacart Delivery Slot Found!", content:"Check the Instacart Website! There is a delivery slot available! Try to checkout!", visible:true}
tell theMessage
make new to recipient with properties {address:user_mail_address}
send
end tell
end tell
end if
set delivery_openslot to true
log "Script did not find 'CHOOSE' nor no delivery slot messages"*)
end if
end repeat
set madeBy to "
Made by Araav Patel | UC Berkeley | Computer Science
Inspiration: Adrian Hertel
"