Skip to content

Instantly share code, notes, and snippets.

@nakami
Created January 28, 2022 16:27
Show Gist options
  • Select an option

  • Save nakami/2f8e60f09a6686a27e435c336f585fce to your computer and use it in GitHub Desktop.

Select an option

Save nakami/2f8e60f09a6686a27e435c336f585fce to your computer and use it in GitHub Desktop.
Adds a button to the Payback website to activate all coupons
// ==UserScript==
// @name Activate All Payback Coupons
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Activating all Coupons on Payback.de with one click
// @author nakami
// @copyright 2022 nakami
// @license GNU General Public License v2.0
// @include http*://www.payback.de/coupons*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js
// @require http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js
// @grant none
// ==/UserScript==
(function() {
'use strict';
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
let mainSR = undefined;
let coupons = undefined;
sleep(2000).then(() => {
var span = document.createElement("span");
span.innerHTML = '<input type="button" href="javascript:void(0);" title="Activate all Coupons" value="Activate all Coupons">';
span.addEventListener("click", function(){
alert('Starting the Work');
mainSR = document.querySelector("#coupon-center").shadowRoot;
coupons = mainSR.querySelectorAll("pbc-coupon");
coupons.forEach((coupon) =>
{
try {
coupon.shadowRoot.querySelector("pbc-coupon-call-to-action").shadowRoot.querySelector('button.not-activated').click();
} catch (error) {
console.error(error);
}
})
}, false);
document.querySelector('#coupon-center').shadowRoot.querySelector("div.coupon-center__filter").append(span);
});
})();
@sippsolutions
Copy link

(function() {
    'use strict';

    function addActivateButton() {
        if (document.getElementById('pbc-activate-all-btn')) return;

        const btn = document.createElement("button");
        btn.id = 'pbc-activate-all-btn';
        btn.innerHTML = 'Activate all Coupons';
        
        Object.assign(btn.style, {
            position: 'fixed',
            top: '80px',
            left: '20px',
            zIndex: '9999',
            padding: '10px 20px',
            backgroundColor: '#003EB0',
            color: 'white',
            border: 'none',
            borderRadius: '4px',
            cursor: 'pointer',
            fontWeight: 'bold',
            boxShadow: '0 2px 5px rgba(0,0,0,0.3)'
        });

        btn.addEventListener("click", async function() {
            const coupons = document.querySelectorAll('button[data-testid*="-not_activated"]');
            if (coupons.length === 0) {
                return;
            }

            btn.innerHTML = `Activating ${coupons.length} Coupons...`;
            btn.disabled = true;

            for (let i = 0; i < coupons.length; i++) {
                try {
                    coupons[i].scrollIntoView({ behavior: 'smooth', block: 'center' });
                    coupons[i].click();
                    await new Promise(r => setTimeout(r, 300));
                } catch (e) {
                    console.error("Error activating coupons:", e);
                }
            }

            btn.innerHTML = 'All activated!';
            btn.style.backgroundColor = '#28a745';
            
            setTimeout(() => {
                btn.innerHTML = 'Activate all Coupons';
                btn.style.backgroundColor = '#003EB0';
                btn.disabled = false;
            }, 3000);
        });

        document.body.appendChild(btn);
    }

    setInterval(() => {
        if (window.location.href.includes('/coupons')) {
            addActivateButton();
        }
    }, 2000);
})();

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