Automates wishlist monitoring, product availability tracking, and quick actions on usmint.gov
Size
7.2 KB
Version
1.1.2
Created
Oct 18, 2025
Updated
5 days ago
1// ==UserScript==
2// @name US Mint Automation Assistant
3// @description Automates wishlist monitoring, product availability tracking, and quick actions on usmint.gov
4// @version 1.1.2
5// @match https://*.usmint.gov/*
6// @icon https://www.usmint.gov/on/demandware.static/Sites-USM-Site/-/default/dwc3e65435/images/favicons/favicon-32x32.png
7// ==/UserScript==
8(function() {
9 'use strict';
10
11 console.log('US Mint Automation Assistant loaded');
12
13 // Function to enable and click the 25NPM Add to Bag button
14 function enableAndClickAddToBag() {
15 console.log('Looking for 25NPM Add to Bag button...');
16
17 const addToCartBtn = document.querySelector('button.add-to-cart[data-pid="25NPM"]');
18
19 if (addToCartBtn) {
20 console.log('Found 25NPM button, checking if disabled...');
21
22 if (addToCartBtn.disabled || addToCartBtn.hasAttribute('disabled')) {
23 console.log('Button is disabled, enabling it...');
24 addToCartBtn.disabled = false;
25 addToCartBtn.removeAttribute('disabled');
26 }
27
28 console.log('Clicking Add to Bag button...');
29 addToCartBtn.click();
30 console.log('✅ 25NPM Add to Bag button clicked successfully!');
31
32 // After clicking, wait a moment then open cart
33 setTimeout(() => {
34 console.log('Opening cart page...');
35 window.location.href = 'https://www.usmint.gov/cart';
36 }, 2000);
37
38 return true;
39 } else {
40 console.log('25NPM button not found on this page');
41 return false;
42 }
43 }
44
45 // Function to extract UUID and PID from cart page
46 function extractCartInfo() {
47 console.log('Extracting cart information...');
48
49 // Try to find UUID in the page HTML
50 const html = document.documentElement.outerHTML;
51 const uuidMatch = html.match(/uuid[=:"'\s]+([a-f0-9]{20,})/i);
52
53 let uuid = null;
54 if (uuidMatch && uuidMatch[1]) {
55 uuid = uuidMatch[1];
56 console.log('Found UUID:', uuid);
57 }
58
59 // Try to find PID (product ID)
60 const pidMatch = html.match(/pid[=:"'\s]+(25[A-Z]{2,3})/i);
61 let pid = '25APM'; // Default
62 if (pidMatch && pidMatch[1]) {
63 pid = pidMatch[1];
64 console.log('Found PID:', pid);
65 }
66
67 return { uuid, pid };
68 }
69
70 // Function to repeatedly attempt quantity update
71 async function attemptQuantityUpdate(pid, uuid, quantity = 99) {
72 const updateUrl = `https://www.usmint.gov/on/demandware.store/Sites-USM-Site/default/Cart-UpdateQuantity?pid=${pid}&quantity=${quantity}&uuid=${uuid}&giftUUIDs=`;
73
74 console.log('🔄 Attempting to update quantity to', quantity);
75 console.log('URL:', updateUrl);
76
77 try {
78 const response = await GM.xmlhttpRequest({
79 method: 'GET',
80 url: updateUrl,
81 anonymous: false
82 });
83
84 console.log('Response status:', response.status);
85 console.log('Response text:', response.responseText);
86
87 // Check if successful
88 if (response.status === 200) {
89 try {
90 const data = JSON.parse(response.responseText);
91 if (data.success || !data.error) {
92 console.log('✅ SUCCESS! Quantity updated to', quantity);
93 return true;
94 } else {
95 console.log('❌ Update failed:', data.error || 'Unknown error');
96 return false;
97 }
98 } catch (e) {
99 // If not JSON, assume success if status is 200
100 console.log('✅ SUCCESS! (Non-JSON response, status 200)');
101 return true;
102 }
103 } else {
104 console.log('❌ Update failed with status:', response.status);
105 return false;
106 }
107 } catch (error) {
108 console.error('❌ Error during update:', error);
109 return false;
110 }
111 }
112
113 // Function to place order
114 async function placeOrder() {
115 console.log('🚀 PLACING ORDER NOW!');
116 const orderUrl = 'https://www.usmint.gov/on/demandware.store/Sites-USM-Site/default/CheckoutServices-PlaceOrder';
117
118 // Open in new tab
119 window.open(orderUrl, '_blank');
120 console.log('✅ Order placement URL opened in new tab');
121 }
122
123 // Main cart automation function
124 async function automateCart() {
125 console.log('🎯 Starting cart automation...');
126
127 // Extract cart info
128 const { uuid, pid } = extractCartInfo();
129
130 if (!uuid) {
131 console.error('❌ Could not find UUID in cart. Make sure item is in cart.');
132 return;
133 }
134
135 console.log(`📦 Cart Info - PID: ${pid}, UUID: ${uuid}`);
136 console.log('🔄 Starting rapid quantity update attempts...');
137
138 let attemptCount = 0;
139 const maxAttempts = 1000;
140
141 // Rapid fire attempts
142 const attemptUpdate = async () => {
143 attemptCount++;
144 console.log(`\n--- Attempt ${attemptCount}/${maxAttempts} ---`);
145
146 const success = await attemptQuantityUpdate(pid, uuid, 99);
147
148 if (success) {
149 console.log('🎉 QUANTITY UPDATE SUCCESSFUL!');
150 console.log('🚀 Proceeding to place order...');
151
152 // Wait a moment then place order
153 setTimeout(() => {
154 placeOrder();
155 }, 500);
156 } else {
157 // Try again immediately if not successful
158 if (attemptCount < maxAttempts) {
159 setTimeout(attemptUpdate, 100); // 100ms delay between attempts
160 } else {
161 console.error('❌ Max attempts reached. Stopping.');
162 }
163 }
164 };
165
166 // Start the attempts
167 attemptUpdate();
168 }
169
170 // Initialize the assistant
171 async function init() {
172 console.log('Initializing US Mint Automation Assistant...');
173
174 // Wait for page to be ready
175 if (document.readyState === 'loading') {
176 document.addEventListener('DOMContentLoaded', init);
177 return;
178 }
179
180 // Wait a bit for the page to fully load
181 setTimeout(() => {
182 // Check if we're on the wishlist page
183 if (window.location.href.includes('/wishlist')) {
184 console.log('📋 On wishlist page, attempting to add 25NPM to bag...');
185 enableAndClickAddToBag();
186 }
187 // Check if we're on the cart page
188 else if (window.location.href.includes('/cart')) {
189 console.log('🛒 On cart page, starting automation...');
190 automateCart();
191 }
192 }, 1000);
193
194 console.log('US Mint Automation Assistant initialized successfully');
195 }
196
197 // Start the extension
198 init();
199})();