Skip to content

DavidZirinsky/Coupon-Clipper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

✂️ Coupon Clipper

🎫 Clip Up To The 250 Digital Coupon Limit at King Soopers

Coupon Clipper logo In-store view
Pictured Above: The Coupon Clipper Extension, and in-store view of potential savings

Never miss a coupon again! Clip all available digital coupons before heading to the store.

🚀 Get the Extension

Available in Chrome Web Store   Get it on Firefox

🎬 Demo Video

output_1440.mp4

📱It works on Firefox for Android as well!

android_fs10M.mp4

📋 About

We've all been there: you see an item at the grocery store is on sale, if and only if you clipped the digital coupon. Having other things to do you didn't do that, and good luck trying to clip the coupon in store. With the store acting a giant faraday cage, non-working wifi, and a slow mobile site you're going to be stuck paying more.

Instead, just clip all the coupons you can before going to the store with this extension.

💻 I Don't Want to Install Your Extension

There's nothing to stop you from pasting this into your browser's developer console. To access your browser's console please follow this guide, then paste this into the console:

(async function () {
  function sleep(ms) {
    return new Promise((res) => setTimeout(res, ms));
  }
  // Returns a delay near `base`, plus‐minus up to `variance` ms.
  function jitter(base, variance) {
    return base + (Math.random() * 2 - 1) * variance;
  }

  const SCROLL_STEP = 400; // pixels per scroll
  const SCROLL_BASE_INTERVAL = 300; // nominal ms between scrolls
  const SCROLL_VARIANCE = 100; // ±100 ms jitter
  const MAX_COUPONS = 250; // ±100 ms jitter

  function getTotalHeight() {
    return Math.max(
      document.body.scrollHeight,
      document.documentElement.scrollHeight
    );
  }
  function getViewportBottom() {
    return window.scrollY + window.innerHeight;
  }

  // Gentle scrolling to the bottom of the page to load all coupons
  console.log("⤵️  Scrolling to bottom of page…");
  while (getViewportBottom() < getTotalHeight()) {
    window.scrollBy(0, SCROLL_STEP);
    await sleep(jitter(SCROLL_BASE_INTERVAL, SCROLL_VARIANCE));
  }
  // final "snap" to absolute bottom (for lazy‐load)
  window.scrollTo(0, getTotalHeight());
  console.log("✅  Reached bottom of page.");

  // Wait a moment for anything new to render
  await sleep(1000);

  // Jump back up to the top
  window.scrollTo(0, 0);
  console.log("⤴️  Jumped back to the top.");
  await sleep(300);

  // Read the "Coupons Clipped"
  function getClippedCount() {
    const titles = document.querySelectorAll("div.DashboardTile--title");
    for (let t of titles) {
      if (t.textContent.trim() === "Coupons Clipped") {
        const numDiv = t.nextElementSibling;
        if (numDiv) {
          const val = parseInt(numDiv.textContent.trim(), 10);
          return isNaN(val) ? 0 : val;
        }
      }
    }
    return 0;
  }

  let clippedSoFar = getClippedCount();
  console.log(`🔢  Currently clipped: ${clippedSoFar}`);

  // Clip as many coupons as the website allows
  const allClipButtons = Array.from(document.querySelectorAll("button")).filter(
    (btn) => btn.textContent.trim() === "Clip"
  );

  console.log(`🔍  Found ${allClipButtons.length} "Clip" button(s) on page.`);

  for (let i = 0; i < allClipButtons.length; i++) {
    clippedSoFar = getClippedCount();
    if (clippedSoFar >= MAX_COUPONS) {
      console.warn(
        `⚠️  Reached 250 coupons clipped. Stopping at button #${i}.`
      );
      break;
    }

    allClipButtons[i].click();
    console.log(
      `✔️  Clicked "Clip" button #${i + 1}. (Clipped now: ${
        clippedSoFar + 1 || "?"
      })`
    );

    // Wait ~1200 ms ±200 ms before the next click
    await sleep(jitter(1200, 200));
  }

  console.log("🎉  Script finished.");
})();

🛠 How To Run This For Development

Firefox: Follow this guide and select the firefox directory in this repo.

Chrome: Follow this guide and select the firefox directory in this repo.

About

Source code for the Coupon Clipper Chrome and Firefox extensions

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published