Last active
March 7, 2025 02:39
-
-
Save GarrettBlackmon/3c3df6f635b10b96f212854e739af5fc to your computer and use it in GitHub Desktop.
get-gpu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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