Last active
February 18, 2024 20:16
-
-
Save yungd1plomat/c7c294f5806623a7569495d2a4e3c195 to your computer and use it in GitHub Desktop.
Megamarket custom bonus activator
This file contains 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
// ==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