Skip to content

Instantly share code, notes, and snippets.

@davydmaker
Created December 4, 2025 14:36
Show Gist options
  • Select an option

  • Save davydmaker/ba35ae94bb336fef66f7e16944750a05 to your computer and use it in GitHub Desktop.

Select an option

Save davydmaker/ba35ae94bb336fef66f7e16944750a05 to your computer and use it in GitHub Desktop.
Browser console script to automatically remove items from Liga Magic cart by exact price match. Auto-confirms native browser prompts.
/**
* Browser console script for Liga Magic website.
* Removes items from the cart by exact price match and auto-confirms native browser prompts.
*
* USAGE:
* 1. Open Liga Magic website in your browser
* 2. Open browser console (F12 or Cmd+Option+I)
* 3. Copy and paste this entire script
* 4. Call: ligaMagicRemoveFromCartByPrice({ targetPrice: 'R$ 10,00' })
*
* OPTIONS:
* - targetPrice: exact price string to match (required, e.g., 'R$ 10,00')
* - maxRemove: maximum number of items to remove (default: Infinity)
* - delay: milliseconds delay between removals (default: 0)
*
* EXAMPLE:
* // Actually remove items with 500ms delay between each
* ligaMagicRemoveFromCartByPrice({
* targetPrice: 'R$ 5,00',
* delay: 500
* });
*/
function ligaMagicRemoveFromCartByPrice(opts = {}) {
const {
targetPrice,
maxRemove = Infinity,
delay = 0,
} = opts;
if (!targetPrice) {
console.error(
'Error: targetPrice is required (exact price string, e.g., "R$ 10,00")'
);
return;
}
const container = document.querySelector(".itens");
if (!container) {
console.error("Error: Container not found with selector \".itens\"");
return;
}
const items = Array.from(container.querySelectorAll(".row"));
const matches = [];
for (let i = 0; i < items.length && matches.length < maxRemove; i++) {
const item = items[i];
const priceEl = item.querySelector(".preco-total.item-total");
if (!priceEl) continue;
const priceText = priceEl.textContent.trim();
if (priceText === targetPrice) {
matches.push({ item, index: i, priceText });
}
}
const originalConfirm = window.confirm;
const originalAlert = window.alert;
const originalPrompt = window.prompt;
try {
window.confirm = () => true;
window.alert = () => {
/* silent */
};
window.prompt = () => null;
} catch (error) {
console.warn(
"Warning: Could not override global functions (context restriction):",
error
);
}
function extractMpDelId(element) {
const onclick = element.getAttribute("onclick") || "";
const match = onclick.match(/mpDel\((\d+)\)/);
return match ? match[1] : null;
}
function findRemovalButton(item) {
let button = item.querySelector(
'.item-delete, .remove, .btn-circle.remove, [title*="Remover"]'
);
if (!button) {
const candidate = Array.from(item.querySelectorAll("[onclick]")).find(
(el) => el.getAttribute("onclick")?.includes("mpDel(")
);
if (candidate) button = candidate;
}
let mpId = null;
if (button) {
mpId = extractMpDelId(button);
} else {
const anyOnclickElement = Array.from(
item.querySelectorAll("[onclick]")
).find((el) =>
/mpDel\(\s*\d+\s*\)/.test(el.getAttribute("onclick") || "")
);
if (anyOnclickElement) {
button = anyOnclickElement;
mpId = extractMpDelId(anyOnclickElement);
}
}
return { button, mpId };
}
matches.forEach((match, index) => {
const executeRemoval = () => {
const { item, index: itemIndex } = match;
const { button, mpId } = findRemovalButton(item);
if (mpId && typeof window.mpDel === "function") {
try {
window.mpDel(Number(mpId));
console.log(`[REMOVE] Called mpDel(${mpId}) for item #${itemIndex}`);
} catch (error) {
console.warn(
`Warning: mpDel failed for item #${itemIndex}, trying direct click. Error:`,
error
);
if (button) button.click();
}
} else if (button) {
button.click();
console.log(`[CLICK] Clicked removal button for item #${itemIndex}`);
} else {
console.warn(
`[FAILED] Could not find removal button for item #${itemIndex}`
);
}
};
if (delay > 0) {
setTimeout(executeRemoval, index * delay);
} else {
executeRemoval();
}
});
const totalDelayMs =
(matches.length > 0 ? (matches.length - 1) * delay : 0) + 2000;
setTimeout(() => {
try {
window.confirm = originalConfirm;
window.alert = originalAlert;
window.prompt = originalPrompt;
console.log("Restored window.confirm/alert/prompt to original functions");
} catch (error) {
console.warn("Warning: Error restoring original functions:", error);
}
}, totalDelayMs);
return {
found: matches.length,
executed: true,
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment