Skip to content

Instantly share code, notes, and snippets.

@Thestias
Last active January 7, 2026 18:10
Show Gist options
  • Select an option

  • Save Thestias/96881df2546616483d09b8f7e6a261d0 to your computer and use it in GitHub Desktop.

Select an option

Save Thestias/96881df2546616483d09b8f7e6a261d0 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 2025-12-05
// @description try to take over the world!
// @author You
// @match https://app.warera.io/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=warera.io
// @grant unsafeWindow
// @grant GM_xmlhttpRequest
// @connect api2.warera.io
// @connect *
// ==/UserScript==
(function () {
"use strict";
function getCookie(name) {
return document.cookie
.split("; ")
.find((row) => row.startsWith(name + "="))
?.split("=")[1];
}
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
function openCase() {
return new Promise((resolve) => {
const token = getCookie("token");
// TRPC batch-like envelope (minimal)
const data = JSON.stringify({
0: { caseCode: "case1" },
});
GM_xmlhttpRequest({
method: "POST",
url: "https://api2.warera.io/trpc/inventory.openCase?batch=1",
headers: {
"content-type": "application/json",
authorization: token,
},
data: data,
onload: function (res) {
console.log("Status:", res.status);
console.log("Body:", res.responseText);
resolve(res.status); // return status to control batching & stop on non-200
},
onerror: function (err) {
console.error("ERR:", err);
resolve(0); // treat error as failure
},
});
});
}
async function startLoop() {
console.log("Starting batched loop…");
const BATCH_SIZE = 2; // how many to send per batch
const BATCH_DELAY = 1000; // ms between batches (2 seconds)
while (true) {
console.log(`🔷 Starting batch of ${BATCH_SIZE}…`);
// Run X requests in parallel
const results = await Promise.all(
Array.from({ length: BATCH_SIZE }, () => openCase())
);
if (results.includes(403)) {
console.log("⏳ Received 403 — waiting then continuing…");
await sleep(BATCH_DELAY);
continue;
}
// Check if ANY request failed
const bad = results.find((s) => s !== 200);
if (bad !== undefined) {
console.log("❌ Non-200 detected in batch. Stopping.", bad);
break;
}
console.log(`🔹 Batch OK. Waiting ${BATCH_DELAY}ms…`);
await sleep(BATCH_DELAY);
}
}
// 🔄 WAIT FOR FULL LOAD + 30 SECONDS
window.addEventListener("load", async () => {
console.log("Page loaded. Waiting 30 seconds…");
await sleep(30000);
console.log("30 seconds passed — starting.");
startLoop();
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment