-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.user.js
324 lines (269 loc) · 16.7 KB
/
main.user.js
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
// ==UserScript==
// @name Rosie Addons Suite
// @namespace http://ryah.org/
// @match https://retailers.rosieapp.com/*
// @version 1.61
// @description Addons for Rosie Retailers because the site needs improvement
// @author Ryan Adame
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @require https://raw.githubusercontent.com/Ryah/Rosie-Addon-Suite/main/js/waitForKeyElements_offline.js
// @resource payCalcHTML https://raw.githubusercontent.com/Ryah/Rosie-Addon-Suite/main/html/paymentCalculator.html
// @resource customCSS https://raw.githubusercontent.com/Ryah/Rosie-Addon-Suite/main/css/styles.css
// @resource orderHistBut https://raw.githubusercontent.com/Ryah/Rosie-Addon-Suite/main/html/orderHist.html
// @grant GM_addStyle
// @grant GM_getResourceText
// ==/UserScript==
/* --------------------------------------------------------------------------*/
/* Setup */
/* --------------------------------------------------------------------------*/
//Calls tag section to add tag to footer once visible
jQuery(document).ready(checkContainer);
ouMsg = false;
//Checks and store if you're on Dashboard or Order Page and stores in a boolean named "dash" every second
//(yeah it's unoptimized but it's the best I got so deal with it)
//UPDATE: It's no longer the best I got but I'm too lazy to change it
setInterval(() => {
if (window.location.href.indexOf("dashboard") > -1) {
dash = true;
changed = false;
if (ouMsg == true) {
ouMsg = false;
}
loadOrderTime = document.getElementById("orderTime");
if (typeof loadOrderTime != "undefined" && loadTime === null) {
nextTimeSlot();
}
} else if (window.location.href.indexOf("orders") > -1) {
dash = false;
loadTime = document.getElementById("nextTimeLoad");
//console.log("dash = " + dash);
} else {
//alert("Something went wrong finding what page you're on. Error Code 8262.");
console.log("Something went wrong finding what page you're on. Error Code 8262.");
}
}, 1000);
/* --------------------------------------------------------------------------- */
/* 24 hour to 12 hour conversion button */
/* --------------------------------------------------------------------------- */
waitForKeyElements("#main-content-region > div > div > div.working-orders-container > div > div.orders-tabbed-panel-container > div > div.panel-content > div > div > div > div.batch-sections-container > div > div:nth-child(1) > div.table-row > div > span", timeConvert);
//changed = false; //Set variable to mark replacement since I can't think of another way to detect if the time has changed or not :)
function timeConvert() {
//if (changed === false) {
if (document.querySelectorAll(".convertedTime").length <= 0) {
//If on Dashboard, counts the header-content classes for amount of orders.
//If not on Dashboard, then sets default order count to 1.
if (dash === true) {
var orders = document.querySelectorAll("#main-content-region .header-content").length;
} else if (dash === false) {
var orders = 1;
} else {
console.log("Something went wrong grabbing orders. Error code 3625 in Time Conversion Script.");
}
//for loop wouldn't work ¯\_(ツ)_/¯
//jk now it does pog
msg = false;
for (i = 0; i < orders; i++) {
//Grabs and trims time using grabTime function. Also formats it with AM/PM at the end.
var timeString = grabTime(i);
var hourEnd = timeString.indexOf(":");
var H = +timeString.substr(0, hourEnd);
var h = H % 12 || 12;
var ampm = H < 12 || H === 24 ? " AM" : " PM";
timeString = h + timeString.substr(hourEnd, 3) + ampm;
//Checks if on Dashboard or on Order Page
//If on Dashboard, add the times to the header-content class.
//If on Order Page, create an alert showing the time.
//Else, show error with error code.
if (dash === true) {
if (msg === false) {
console.log("On Dashboard, adding times to Dashboard.");
msg = true;
}
$(document.querySelectorAll(".header-content")[i])
.contents()
.filter(function () {
return this.nodeType == 3;
})
.first()
.replaceWith("<b>" + timeString + " " + "|" + " " + "</b>");
//.prepend("<b class='convertedTime'>" + timeString + " " + "|"+ "</b>");
changed = true; //Mark the time as converted to prevent the script converting a random string. It's a duct tape fix but it works 99% of the time so I'm not going to touch it.
} else {
console.log("Something went wrong replacing the time. Error Code 2124 in 24/12 Button Script.");
}
}
msg = false;
}
}
function grabTime(j) {
if (dash === true) {
var timeString2 = document.querySelectorAll(".header-content")[j].innerHTML;
var timeStart = timeString2.indexOf("|") + 12;
var timeEnd = timeString2.indexOf(":") + 2;
var T = timeString2.substr(timeStart, timeEnd);
return T;
} else if (dash === false) {
//Add time to order page if on order page
var timeString2 = document.querySelectorAll("div:nth-child(4) > div:nth-child(3)")[2].innerHTML;
var timeStart = timeString2.indexOf(",") + 1;
var timeEnd = timeString2.indexOf(":") + 2;
var T = timeString2.substr(timeStart, timeEnd);
return T;
} else {
// alert("Something went wrong grabbing the time. Error Code 1735 in 24/12 Button Script.");
console.log("Something went wrong grabbing the time. Error Code 1735 in 24/12 Button Script.");
}
}
/* -------------------------------------------------------------------------- */
/* Order Page Improvements */
/* -------------------------------------------------------------------------- */
//Waits for loyality number to load before passing it to the orderImprove function.
waitForKeyElements("#main-content-region > div > div.order-details-container > div.order-details-card.card > div.order-details > div:nth-child(4) > div.loyalty-info > div:nth-child(2) > div", orderImprove);
function orderImprove() {
//Add line breaks for better kerning.
$(document.querySelector("#main-content-region > div > div.order-details-container > div > div.order-details > div:nth-child(4) > div.loyalty-info")).append(`<br>`);
// Format Loyality Number
/*Uses regex to format the number and store it in propNum.
This took way too long to figure out. Why hasn't anyone made a simpler version of regex yet? I wrote the thing yet if you ask me how it works I will be just as confused as you are.
It shouldn't be the norm to have multiple generators out there for something that people use very often and have pretty much no viable substitute for.
Sure it's EXTREMELY versatile but the learning curve is like running into a brick wall. I've never heard someone go "Oh thank God I can use RegEx! I've been waiting for this moment! I'm so happy!"
Everyone hates it but for some reason as far as I know no one has sucessfully attempted to make an alternative for it. It makes me so sad.
Anyways that's my rant. */
num = document.querySelector("#main-content-region > div > div.order-details-container > div > div.order-details > div:nth-child(4) > div.loyalty-info > div:nth-child(2) > div").innerHTML;
propNum = num.replace(/(\d{3})(\d{3})(\d{4})/, "($1) $2-$3");
// Replace phone number with propNum.
$(document.querySelector("#main-content-region > div > div.order-details-container > div > div.order-details > div:nth-child(4) > div.loyalty-info > div:nth-child(2) > div")).contents().filter(function () {
return this.nodeType == 3;
}).last().replaceWith(propNum);
// Rename "Loyalty Number" to "Celebrate Number" for consistancy.
$(document.querySelector("#main-content-region > div > div.order-details-container > div > div.order-details > div:nth-child(4) > div.loyalty-info > div:nth-child(1) > div")).contents().filter(function () {
return this.nodeType == 3;
}).last().replaceWith("Celebrate Number");
// Remove "Cutoff Time" as it just causes confusion with pickup time.
$(document.querySelector("#main-content-region > div > div.order-details-container > div > div.order-details > div:nth-child(4) > div:nth-child(5) > div")).remove();
$(document.querySelector("#main-content-region > div > div.order-details-container > div > div.order-details > div:nth-child(4) > div:nth-child(6) > div")).remove();
// If Alternate Phone Number isn't present, remove it.
if (document.querySelector("#main-content-region > div > div.order-details-container > div > div.order-details > div:nth-child(3) > div:nth-child(5) > div").innerHTML.length === 7) {
document.querySelector("#main-content-region > div > div.order-details-container > div > div.order-details > div:nth-child(3) > div:nth-child(4) > div").remove();
document.querySelector("#main-content-region > div > div.order-details-container > div > div.order-details > div:nth-child(3) > div:nth-child(5) > div").remove();
};
}
/* -------------------------------------------------------------------------- */
/* Customer Order History */
/* -------------------------------------------------------------------------- */
waitForKeyElements("#main-content-region > div > div.order-details-container > div.order-details-card.card > div.order-details > div:nth-child(2) > div:nth-child(5) > div", orderHistory);
orderHist = GM_getResourceText("orderHistBut");
// addItem = GM_getResourceText("addItemBut");
function orderHistory() {
$(document.querySelector("#page-cap-region > div > div > div.buttons-container > div")).append(orderHist);
// $(document.querySelector("#main-content-region > div > div.pick-list-container > div > div.pick-list-title > div.buttons-section")).append(addItem);
}
/* -------------------------------------------------------------------------- */
/* Payment Calculator */
/* -------------------------------------------------------------------------- */
//Most of the js is in the HTML file.
var pcHTML = GM_getResourceText("payCalcHTML");
setInterval(() => {
if (window.location.href.indexOf("dashboard") > -1) {
//do nothing i guess?
} else {
load = document.getElementById("payCalc");
}
}, 500);
loadPayCalc = document.getElementById("payCalc");
waitForKeyElements("#main-content-region > div > div.order-details-container > div > div.order-details > div.details-column.money > div:nth-child(4) > div.content", paymentCalc);
function paymentCalc() {
if (window.location.href.indexOf("orders") > -1) {
if (typeof loadPayCalc != "undefined" && loadPayCalc === null) {
$(document.querySelector("#main-content-region > div > div.order-details-container")).append(pcHTML);
loadPayCalc = true;
}
}
}
/* -------------------------------------------------------------------------- */
/* Show Next Available Timeslot */
/* -------------------------------------------------------------------------- */
waitForKeyElements("#page-cap-region > div > div > div.buttons-container > div > div.loading-button.button.secondary > div > div", nextTimeSlot);
loadTime = document.getElementById("orderTime");
function nextTimeSlot() {
if (window.location.href.indexOf("dashboard") > -1) {
if (typeof loadTime != "undefined" && loadTime != null) {
document.getElementById("orderTime").remove();
}
var today = new Date();
var pickupTimeStart = today.getHours() + 5;
var pickupTimeEnd = today.getHours() + 6;
var pickupTimeConvertStart = pickupTimeStart % 12 || 12;
var pickupTimeConvertEnd = pickupTimeEnd % 12 || 12;
if (pickupTimeStart > 19 || pickupTimeStart < 9) {
var pickupTimeConvertStart = 9;
}
if (pickupTimeStart > 12) {
var pickupTimeConvertStart = pickupTimeConvertStart + ":00 PM";
} else {
var pickupTimeConvertStart = pickupTimeConvertStart + ":00 AM";
}
if (pickupTimeEnd > 12) {
var pickupTimeConvertEnd = pickupTimeConvertEnd + ":00 PM";
} else {
var pickupTimeConvertEnd = pickupTimeConvertEnd + ":00 AM";
}
$(document.querySelector("#main-content-region > div > div > div.new-orders-container")).prepend('<div id="orderTime" class="dashboard card"><b class="nextTimeLoad">Next Pickup Slot: <b style="color: rgb(0, 149, 169);">' + pickupTimeConvertStart + '</b></b></div>');
loadTime = true;
}
}
/* -------------------------------------------------------------------------- */
/* Reload Dashboard upon Order Ready */
/* -------------------------------------------------------------------------- */
//This is to fix a bug in Rosie where when you mark an order as ready, it will stay in working.
//Current solution is to force reload the page when the banner saying it's complete pops up.
//Will work on a more complete solution at a later date.
waitForKeyElements("#main-toaster-region > div > div > div > div > span", forceReload);
function forceReload() {
if (document.querySelector("#main-toaster-region > div > div > div > div > span").innerText.indexOf("successfully marked as ready") > -1) {
location.reload();
}
}
function checkContainer() {
if ($(".footer-content").is(":visible")) {
console.log("Loading Rosie Addons");
$(document.querySelectorAll(".copyright"))
.contents()
.filter(function () {
return this.nodeType == 3;
})
.last()
.replaceWith(
"© 2012-2020 Rosie Applications Inc. | <a href='https://www.ryah.org/'>Rosie Addons</a> | <a style='text-decoration:none' href='https://github.com/Ryah/Rosie-Addon-Suite'><img height='20' width='20' src='https://cdn.jsdelivr.net/npm/[email protected]/icons/github.svg' /></a>"
);
} else {
setTimeout(checkContainer, 50);
}
}
//Enter Key Submit on Substitution Modal
// waitForKeyElements(".search-result-description-section", addEnterFunc);
// function addEnterFunc() {
// function clickTargetButton(jNode) {
// var clickEvent = document.createEvent("MouseEvents");
// clickEvent.initEvent("click", true, true);
// jNode[0].dispatchEvent(clickEvent);
// }
// console.log("Adding enter");
// var quantSubBox = document.querySelector('#modal-manager-region > div > div.modal.modal-visible > div.modal-content-container > div > div.modal-cards.paper > div:nth-child(2) > div.search-results-card-container > div > div.search-item-stickers-container > div > div > div.fill-section > div.fill-input-container > div > input[type=text]');
// quantSubBox.classList.add('quantSubBox');
// $('.quantSubBox').focus(function () {
// document.addEventListener("keyup", function (event) {
// if (event.keyCode === 13) {
// console.log("enter was pressed");
// clickTargetButton($('#modal-manager-region > div > div.modal.modal-visible > div.modal-content-container > div > div.modal-cards.paper > div:nth-child(2) > div.search-results-card-container > div > div.search-item-stickers-container > div > div > div.fill-section > div.action-button-container > div > span'));
// }
// });
// });
// };
//Extra Functions
/* -------------------------------------------------------------------------- */
/* Custom CSS */
/* -------------------------------------------------------------------------- */
//Went for a Material Design look with Pure CSS since injecting ANY form of stylesheet breaks the site's fonts.
var customCSS = GM_getResourceText("customCSS");
GM_addStyle(customCSS);