Skip to content

Instantly share code, notes, and snippets.

@ctsstc
Last active November 3, 2022 07:56
Show Gist options
  • Save ctsstc/73a74ae0f0c315262bf07cea9fdc7aa2 to your computer and use it in GitHub Desktop.
Save ctsstc/73a74ae0f0c315262bf07cea9fdc7aa2 to your computer and use it in GitHub Desktop.
Safeway Just for U Auto Clicker. Add all the discounts at once.
// Allow redefinition for copy/paste
let Clicker = class {
#document;
#selector;
constructor(document, selector) {
this.#document = document;
this.#selector = selector;
}
hasMore() {
return this.#findAll().length > 0;
}
clickAll() {
this.#findAll().forEach((el, index) => setTimeout(() => el.click(), index*200));
}
#findAll() {
return this.#document.querySelectorAll(this.#selector);
}
}
let coupons = new Clicker(window.document, '.grid-coupon-btn');
let loadButton = new Clicker(window.document, '.btn.load-more');
// Anonymous singleton
let SafewayClicker = new class {
#coupons;
#loadButton;
#pollLength;
constructor(coupons, loadButton, pollLength = 2000) {
this.#coupons = coupons;
this.#loadButton = loadButton;
this.#pollLength = pollLength;
this.run();
}
run() {
// State 1
// Has coupon buttons -> Click all buttons
if (this.#coupons.hasMore()) {
// Note: console.log has been removed
console.warn("GOTTA CLICK'EM ALL!!!");
this.#coupons.clickAll();
this.#runAgain();
}
// State 2
// Has load more -> Click load more
else if(this.#loadButton.hasMore()) {
console.warn('LOAD MOARRR!!!');
this.#loadButton.clickAll();
this.#runAgain();
}
// State 3
// Has neither -> Finish
else {
console.warn("LE FINI! 🚀");
}
}
#runAgain() {
setTimeout(this.run.bind(this), this.#pollLength);
}
}(coupons, loadButton);
@ctsstc
Copy link
Author

ctsstc commented Feb 12, 2021

Would be nice to auto scroll the page, and I should have a queue to process these rather than clicking all of them instantly; maybe some randomness to the time between clicks too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment