Skip to content

Instantly share code, notes, and snippets.

@J-Swift
Last active November 15, 2021 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save J-Swift/c1458d8e505a60d4b46161509c7a8f63 to your computer and use it in GitHub Desktop.
Save J-Swift/c1458d8e505a60d4b46161509c7a8f63 to your computer and use it in GitHub Desktop.
Programmatically add all available chase credit card rewards
await (async function wrapper() {
const accountDropdownSelector = 'mds-select mds-select-option';
const addDealSelector = '.sixersoffers__container .iconAddToCard';
const closeFlyoutSelector = 'flyoutClose';
const offerInfoTitleSelector = '.offerdetails__offer-info .offerdetails__info-one';
const offerInfoAmountSelector = '.offerdetails__offer-info .offered-amount-info';
const defaultDelayMs = 1000;
const defaultMaxWaitMs = 1000;
const pause = async (delayMs = defaultDelayMs) => {
return new Promise(resolve => {
setTimeout(resolve, delayMs);
});
};
const clickAndPause = async (el, delayMs = defaultDelayMs) => {
el.click();
await pause(delayMs);
};
const waitFor = async (predicate, maxWaitMs = defaultMaxWaitMs) => {
let result = predicate();
let totalWaitMs = 0;
while(result == null && totalWaitMs < maxWaitMs) {
await pause(100);
totalWaitMs += 100;
result = predicate();
}
if (result == null) {
// console.log('TIMED OUT WHILE WAITING FOR ELEMENT');
}
return result;
}
const getCurrentDealDescription = async () => {
const name = await waitFor(() => document.querySelector(offerInfoTitleSelector));
const amount = await waitFor(() => document.querySelector(offerInfoAmountSelector));
return `${name.textContent} ${amount.textContent}`;
};
const doNext = async () => {
const el = await waitFor(() => document.querySelector(addDealSelector));
if (el != null) {
el.click();
const closeBtn = await waitFor(() => document.getElementById(closeFlyoutSelector));
const description = await getCurrentDealDescription();
console.log(` REDEEMING: ${description}`);
closeBtn.click();
} else {
console.log(' LINKS DONE!');
return;
}
await doNext();
};
let currentIdx = 0;
let keepGoing = true;
while (keepGoing) {
const els = document.querySelectorAll(accountDropdownSelector);
if (els.length > currentIdx) {
console.log('STARTING ACCOUNT!');
await clickAndPause(els[currentIdx]);
currentIdx += 1;
await doNext();
} else {
console.log('ACCOUNTS DONE!');
keepGoing = false;
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment