Created
March 25, 2021 13:51
-
-
Save MikeeI/0636dd2d368dc3f2089f2afcf01dfea9 to your computer and use it in GitHub Desktop.
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
const ids = { | |
'www.mediamarkt.de': [ | |
2661939, | |
2661938 | |
], | |
'www.mediamarkt.at': [ | |
1716302, | |
1797340, | |
1797339, | |
1821625, | |
1821626, | |
1821627, | |
1823467, | |
1823468, | |
1821624, | |
1823756, | |
1823757, | |
1823758, | |
1823759, | |
], | |
'www.saturn.de': [ | |
2661939, | |
2661938, | |
2715827, | |
2715826, | |
2715828 | |
] | |
}; | |
const host = location.host; | |
const salesLine = host === 'www.saturn.de' ? 'Saturn' : 'Media'; | |
const country = host === 'www.mediamarkt.at' ? 'AT' : 'DE'; | |
const f = (id) => { | |
return fetch("https://" + host + "/api/v1/graphql", { | |
"headers": { | |
"accept": "*/*", | |
"accept-language": "de-AT,de-DE;q=0.9,de;q=0.8,en-US;q=0.7,en;q=0.6", | |
"apollographql-client-name": "pwa-client", | |
"apollographql-client-version": "6.119.0", | |
"cache-control": "no-cache", | |
"content-type": "application/json", | |
"pragma": "no-cache", | |
"sec-fetch-dest": "empty", | |
"sec-fetch-mode": "cors", | |
"sec-fetch-site": "same-origin", | |
"x-cacheable": "false", | |
"x-flow-id": "374cc1ee-7ece-4877-a3c3-8e39ab4c209c", | |
"x-mms-country": "AT", | |
"x-mms-language": "de", | |
"x-mms-salesline": "Media", | |
"x-operation": "AddProduct" | |
}, | |
"body": `{\"operationName\":\"AddProduct\",\"variables\":{\"items\":[{\"productId\":\"${id}\",\"outletId\":null,\"quantity\":1,\"serviceId\":null,\"warrantyId\":null}]},\"extensions\":{\"pwa\":{\"salesLine\":\"${salesLine}\",\"country\":\"${country}\",\"language\":\"de\"},\"persistedQuery\":{\"version\":1,\"sha256Hash\":\"404e7401c3363865cc3d92d5c5454ef7d382128c014c75f5fc39ed7ce549e2b9\"}}}`, | |
"method": "POST", | |
"mode": "cors", | |
"credentials": "include" | |
}); | |
}; | |
ids[host].forEach((id, index) => { | |
setTimeout(() => { | |
f(id) | |
.then(res => { | |
console.log(`Added ${id}`); | |
}) | |
.catch(err => console.error(err)); | |
}, 1000 * index); | |
}); | |
setTimeout(() => console.log("Done."), 1000 * ids[host].length); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment