Skip to content

Instantly share code, notes, and snippets.

@yungd1plomat
Last active February 18, 2024 20:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save yungd1plomat/c7c294f5806623a7569495d2a4e3c195 to your computer and use it in GitHub Desktop.
Save yungd1plomat/c7c294f5806623a7569495d2a4e3c195 to your computer and use it in GitHub Desktop.
Megamarket custom bonus activator
// ==UserScript==
// @name Megamarket custom bonus
// @namespace http://tampermonkey.net/
// @version 0.2
// @description Allows you to enter your own amount of bonuses for an order
// @author yungd1plomat
// @grant none
// @match https://megamarket.ru/multicart/checkout/*
// ==/UserScript==
var bonusAmount = null;
document.addEventListener("change", (e) => {
if (e.target.value == 'true') {
bonusAmount = prompt('Введите количество бонусов', 0);
return;
}
bonusAmount = null;
});
const {
fetch: originalFetch
} = window;
window.fetch = async (...args) => {
let [resource, config] = args;
if (resource.includes('checkoutService/checkout/calculate') && bonusAmount) {
let body = config.body;
let json = JSON.parse(body);
if (json.discounts[0].amount) {
json.discounts[0].amount = bonusAmount;
}
else {
json.discounts[1].amount = bonusAmount;
}
config.body = JSON.stringify(json);
console.log(`hooked calculate with ${bonusAmount} bonuses`);
}
const response = await originalFetch(resource, config);
return response;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment