Last active
March 27, 2024 13:59
-
-
Save raxityo/c82abe49b77d5feaeb5cf6b69f0e0d9d to your computer and use it in GitHub Desktop.
Clip all available BJ's coupons
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 BJ's Coupon Clipper | |
// @namespace Violentmonkey Scripts | |
// @match https://www.bjs.com/ | |
// @grant none | |
// @version 1.0 | |
// @author @raxityo | |
// @description 3/24/2024, 11:01:30 PM | |
// ==/UserScript== | |
/** | |
* Clip all available BJ's coupons | |
* - Login to BJ's website | |
* - Open dev console and paste this function | |
* - Run it! Example `await clipAllOffers()` | |
* @return {Promise<T>} | |
*/ | |
(async function clipAllOffers() { | |
const membershipNumber = localStorage.getItem("x_MembershipNumber"); | |
const zipcode = JSON.parse( | |
localStorage.getItem("clubDetailsForClubId") | |
).postalCode; | |
await fetch( | |
"https://api.bjs.com/digital/live/api/v1.0/member/available/offers", | |
{ | |
method: "post", | |
credentials: "include", | |
body: JSON.stringify({ | |
membershipNumber, | |
zipcode, | |
category: "", | |
isPrev: false, | |
isNext: true, | |
pagesize: 500, | |
searchString: "", | |
indexForPagination: 0, | |
brand: "" | |
}) | |
} | |
) | |
.then((r) => r.json()) | |
.then(([{ availableOffers }]) => { | |
// Intentionally doing sequential requests to avoid hammering the backend | |
availableOffers.forEach(async ({ offerId, storeId }) => { | |
await fetch( | |
`https://api.bjs.com/digital/live/api/v1.0/store/${storeId}/coupons/activate?zip=07302&offerId=${offerId}`, | |
{ | |
credentials: "include" | |
} | |
); | |
}); | |
}); | |
})().then(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@TheMarf I have just converted this to a UserScript, so you can use it in FireFox or other browsers using plugins such as Tampermonkey or ViolentMonkey and installing the script as a UeserScript. Doing so would automatically run the script whenever you visit bjs.com.