Chase offers

Automatically add chase offers

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Chase offers
// @namespace    http://tampermonkey.net/
// @version      2024-11-24
// @description  Automatically add chase offers
// @author       You
// @match        https://secure.chase.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=chase.com
// @grant        none
// ==/UserScript==

// copied with minor adaptation from https://www.reddit.com/r/ChaseSapphire/comments/18pb8w5/auto_add_all_offers_to_chase_card/

(function() {
    'use strict';

    const urlPattern = /https:\/\/secure\.chase\.com\/web\/auth\/dashboard#\/dashboard\/merchantOffers\/offer-hub\?accountId=.*/;
    const btnSelection = '[role="button"][tabindex="0"] > :nth-child(2)';
    //'.r9jbij9' manual button selection

    const backFunction = () => {
        // shadow root back button click
        document.querySelectorAll(`[variant="back"]`)[0].shadowRoot.querySelectorAll(`#back-button`)[0].click()
.click();
        // old back method
        // window.history.back();
    };
    const aa = () => {
        backFunction();
        setTimeout(checkUrlAndRun, Math.random() * 1000 + 300);
    };

    let count = 1;
    const c = () => {
        try {
            const btns = [...document.querySelectorAll(btnSelection)]
                .filter(b => b.childNodes[1].childNodes[0].type !== 'ico_checkmark_filled');
            const b = btns.pop();
            if (!b) {
                console.log('added all!');
                return;
            }
            b.childNodes[0].click();
            updateProgress(count, btns.length);
            setTimeout(aa, Math.random() * 1000 + 300);

            document.querySelector(btnSelection).click();
        } catch (e) {
            checkUrlAndRun();
        }
    };
    const updateProgress = (current, total) => {
      console.log(`Remaining: ${total}`);
      count++;
    };

    const waitForElements = () => {
        const observer = new MutationObserver((mutations, observer) => {
            if (document.querySelectorAll(btnSelection).length > 0) {
                observer.disconnect();
                c();
            }
        });

        observer.observe(document.body, { childList: true, subtree: true });
    };

    const checkUrlAndRun = () => {
        if (urlPattern.test(window.location.href)) {
            waitForElements();
        }
    };

    // Initial check
    checkUrlAndRun();

    // Monitor URL changes
    let oldHref = document.location.href;
    const body = document.querySelector("body");
    const observer = new MutationObserver(mutations => {
        if (oldHref !== document.location.href) {
            oldHref = document.location.href;
            checkUrlAndRun();
        }
    });
    observer.observe(body, { childList: true, subtree: true });

})();