Skip to content

Instantly share code, notes, and snippets.

@GarrettBlackmon
Last active March 7, 2025 02:39
Show Gist options
  • Select an option

  • Save GarrettBlackmon/3c3df6f635b10b96f212854e739af5fc to your computer and use it in GitHub Desktop.

Select an option

Save GarrettBlackmon/3c3df6f635b10b96f212854e739af5fc to your computer and use it in GitHub Desktop.
get-gpu
javascript:(function(){
if (!window.autoCartState) window.autoCartState={running:false, count:0};
if (window.autoCartState.running) {window.autoCartState.running=false; console.log("%cπŸ›‘ Auto Add-to-Cart Stopped!", "color:red;font-weight:bold;"); return;}
window.autoCartState.running=true;
window.autoCartState.count=0; // Reset count on start
console.log("%cπŸš€ Auto Add-to-Cart Script Loaded!", "color:yellow;font-weight:bold;");
console.log("%cπŸ’‘ A popup will appear. Paste your copied fetch() request inside and click OK.", "color:lightblue;");
console.log("%cπŸ›‘ Click the bookmark again to stop the script.", "color:orange;font-weight:bold;");
let userFetchInput=prompt("Paste your fetch() request here (exactly as copied from DevTools):");
try {
if (!userFetchInput.startsWith("fetch(")) throw new Error("Invalid fetch() request. Make sure you copied the full request.");
let requestUrl=userFetchInput.match(/fetch\("([^"]+)"/)[1],
requestHeaders=userFetchInput.match(/"headers": ({[\s\S]+?})/),
requestBody=userFetchInput.match(/"body": "([^"]+)"/),
requestMethod=userFetchInput.match(/"method": "([^"]+)"/)[1];
if (!requestUrl || !requestMethod) throw new Error("Could not extract request details.");
let headers=requestHeaders ? JSON.parse(requestHeaders[1]) : {},
body=requestBody ? requestBody[1] : null,
lastResponse=null;
// Remove any headers that start with "sec-"
Object.keys(headers).forEach(key => { if (key.toLowerCase().startsWith("sec-")) delete headers[key]; });
function addToCartLoop() {
if (!window.autoCartState.running) {console.log("%cπŸ›‘ Auto Add-to-Cart Stopped!", "color:red;font-weight:bold;"); return;}
console.clear(); // Clears console before each new request
window.autoCartState.count++; // Increment request count
let timestamp=new Date().toLocaleTimeString(),
requestStartTime=performance.now();
console.log(`%c[${timestamp}] πŸ›’ Attempt #${window.autoCartState.count}: Sending Add-to-Cart Request via XHR...`, "color:cyan;font-weight:bold;");
let xhr=new XMLHttpRequest();
xhr.open(requestMethod, requestUrl, true);
for (let key in headers) {
try {xhr.setRequestHeader(key, headers[key]);}
catch (err) {console.warn(`⚠️ Could not set header: ${key}`);}
}
xhr.onreadystatechange=function(){
if (xhr.readyState===4) {
let requestDuration=(performance.now()-requestStartTime).toFixed(2);
console.log(`%c[${timestamp}] βœ… Request #${window.autoCartState.count} Sent (Response Time: ${requestDuration} ms)`, "color:green;font-weight:bold;");
let responseData=xhr.responseText;
console.log(`%cπŸ“¦ Server responded!`, "color:green;font-weight:bold;");
logFormattedResponse(responseData);
let dataString=JSON.stringify(responseData);
if (lastResponse!==null && lastResponse!==dataString) {
console.log("%c🚨 RESPONSE CHANGED! POSSIBLE STOCK UPDATE! πŸ”” SOUNDING THE ALARM!", "color:red;font-weight:bold;background:yellow;");
playAlert();
}
lastResponse=dataString;
setTimeout(addToCartLoop, 2000);
}
};
xhr.send(body);
}
function playAlert() {new Audio("https://www.myinstants.com/media/sounds/bell.mp3").play();}
function logFormattedResponse(data) {console.log("%cπŸ” FULL RESPONSE DETAILS:", "color:orange;font-weight:bold;"); console.table(JSON.parse(data));}
addToCartLoop();
console.log("%cπŸš€ Auto Add-to-Cart Running! Click the bookmark again to stop.", "color:yellow;font-weight:bold;");
} catch (error) {
console.error("%c❌ ERROR: Invalid fetch() request pasted! Please try again.","color:red;font-weight:bold;");
window.autoCartState.running=false;
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment