Last active
February 6, 2024 19:05
-
-
Save 1natsu172/cab0b3a982f41ac033ed88d60e5d9dc5 to your computer and use it in GitHub Desktop.
Heirroom謎スクリプト
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
// --- fetch | |
const count = await fetch("https://heirroom.coffee/api/coffee/count", { | |
headers: { | |
accept: "*/*", | |
"accept-language": "ja,en;q=0.9,en-US;q=0.8,pt;q=0.7,el;q=0.6", | |
"content-type": "text/plain;charset=UTF-8", | |
"sec-ch-ua": | |
'"Not A(Brand";v="99", "Google Chrome";v="121", "Chromium";v="121"', | |
"sec-ch-ua-mobile": "?0", | |
"sec-ch-ua-platform": '"macOS"', | |
"sec-fetch-dest": "empty", | |
"sec-fetch-mode": "cors", | |
"sec-fetch-site": "same-origin", | |
}, | |
referrer: "https://heirroom.coffee/coffee", | |
referrerPolicy: "strict-origin-when-cross-origin", | |
body: '{"body":{}}', | |
method: "POST", | |
mode: "cors", | |
credentials: "include", | |
}) | |
.then((res) => res.json()) | |
.then((res) => res.count); | |
console.log("count is", count); | |
const coffees = await fetch("https://heirroom.coffee/api/coffee", { | |
headers: { | |
accept: "*/*", | |
"accept-language": "ja,en;q=0.9,en-US;q=0.8,pt;q=0.7,el;q=0.6", | |
"content-type": "text/plain;charset=UTF-8", | |
"sec-ch-ua": | |
'"Not A(Brand";v="99", "Google Chrome";v="121", "Chromium";v="121"', | |
"sec-ch-ua-mobile": "?0", | |
"sec-ch-ua-platform": '"macOS"', | |
"sec-fetch-dest": "empty", | |
"sec-fetch-mode": "cors", | |
"sec-fetch-site": "same-origin", | |
}, | |
referrer: "https://heirroom.coffee/coffee", | |
referrerPolicy: "strict-origin-when-cross-origin", | |
body: `{\"body\":{\"limit\":${count}}}`, | |
method: "POST", | |
mode: "cors", | |
credentials: "include", | |
}) | |
.then((res) => res.json()) | |
.then((res) => res.collection.coffees) | |
.then((coffees) => | |
coffees.map((coffee) => ({ | |
...coffee, | |
// memo: add url to item of coffees. | |
url: `https://heirroom.coffee/coffee/${coffee.id}`, | |
})) | |
); | |
console.log("coffees is", coffees); | |
// --- filtered | |
const trialCoffees = coffees.filter((item) => | |
item.variations.some((variation) => variation.price === "9999.0") | |
); | |
console.log("trialCoffees is", trialCoffees); | |
const trialAvailableCoffees = trialCoffees | |
.filter((item) => | |
item.variations.some( | |
(variation) => | |
variation.price === "9999.0" && variation.availableForSale === true | |
) | |
) | |
.map(({ id, title, variations, url }) => ({ | |
id, | |
title, | |
url, | |
variations, | |
})); | |
console.log("trialAvailableCoffees is", trialAvailableCoffees); | |
// --- open | |
if (trialAvailableCoffees.length >= 3) { | |
trialAvailableCoffees.forEach((item) => { | |
const { title, url } = item; | |
console.group(title, url); | |
open(url); | |
console.groupEnd(); | |
}); | |
} else { | |
console.error( | |
`Do not have enough trial samples in stock! Stock is ${trialAvailableCoffees.length} :(` | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run on the browser console that logged-in heirroom tab.
Need allow the browser popup blocker.