Greasy Fork is available in English.

Just For U Coupon Clipper

Clips all the coupons (09/2023) Safeway Just For U

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name     Just For U Coupon Clipper
// @version  1
// @grant    none
// @include https://www.safeway.com/foru/coupons-deals.html*
// @description Clips all the coupons (09/2023) Safeway Just For U
// @namespace https://greasyfork.org/users/803889
// @license MIT
// ==/UserScript==
  
/// While the load more button exists, load more
function loadUntilDone() {
  let buttons = document.getElementsByClassName('load-more')
  
  if (buttons.length > 0) {
    // Still a load more button. Click until it goes away
    
    console.log("Loading more coupons...")
    
    try {
      buttons[0].click()
    } catch (e) {
      console.error(e)
    }
  
  // Give it some time to load.
      setTimeout(loadUntilDone, 1000)
  } else {
    // Now find and click all the coupons
    console.log("Clicking all coupons...")
    clickAllUnclicked(document.querySelectorAll('.grid-coupon-btn'))
    
  }
}
  
/// Resolve after the given delay
async function sleep(delay) {
  return new Promise((resolve, reject) => {
    setTimeout(resolve, delay)
  })
}
  
/// Click on every element in the given collection, at a sensible pace, unless alredy clicked
async function clickAllUnclicked(elems) {
  let i = elems.length
  for (i > 0; i--;) {
    let elem = elems[i];
    if (!elem.classList.contains('.grid-coupon-btn')) {
      console.log("Click coupon " + i + ": " + elem)
      elem.click()
      await sleep(100)
    }
  }
  console.log("All coupons clicked!")
}
  
// Wait for the page to load and then start collecting coupons
console.log("Waiting to load coupons")
setTimeout(loadUntilDone, 4000)