Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## Summary

<!-- What does this PR change, and why? -->

## Changes

-

## Testing

<!-- How was this verified? e.g. installed in Tampermonkey, ran on payback.de/coupons with N open coupons. -->

## Checklist

- [ ] PR title follows Conventional Commits (`type(scope): subject`)
- [ ] `@version` bumped if the script's behavior changed
- [ ] Tested manually on https://www.payback.de/coupons
- [ ] README updated if usage or behavior changed
44 changes: 44 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: CI

on:
pull_request:
types: [opened, edited, synchronize, reopened]
push:
branches: [main]

permissions:
contents: read

jobs:
lint:
name: Lint userscript
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Check JavaScript syntax
run: node --check payback-helper.user.js

- name: Check metadata block
run: |
f=payback-helper.user.js
head -n 1 "$f" | grep -qx '// ==UserScript==' || { echo "::error::Metadata block must start on line 1"; exit 1; }
for key in name namespace version description author license match updateURL downloadURL; do
grep -Eq "^// @${key}[[:space:]]" "$f" || { echo "::error::Missing @${key} in metadata block"; exit 1; }
done
grep -Eq '^// @version[[:space:]]+[0-9]+\.[0-9]+\.[0-9]+$' "$f" || { echo "::error::@version must be SemVer (x.y.z)"; exit 1; }

pr-title:
name: PR title
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Check Conventional Commits format
env:
TITLE: ${{ github.event.pull_request.title }}
run: |
re='^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\([a-z0-9-]+\))?!?: [^ ].{0,71}$'
if [[ ! "$TITLE" =~ $re ]]; then
echo "::error::PR title must follow Conventional Commits, e.g. 'fix(activation): handle disabled buttons'. Got: $TITLE"
exit 1
fi
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# OS
.DS_Store
Thumbs.db
desktop.ini
Zone.Identifier
*:Zone.Identifier

# Editors / IDEs
.vscode/
.idea/
*.swp
*.swo
*~

# Node tooling (in case linters/formatters are added later)
node_modules/
npm-debug.log*
yarn-error.log*
.npm/
.eslintcache

# Environment / secrets
.env
.env.*

# Logs and scratch files
*.log
tmp/
*.bak
83 changes: 83 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Contributing

Thanks for your interest in improving Payback Helper Script! This document describes how changes get into `main`.

## Workflow

1. Create a branch from `main` named `<type>/<short-kebab-description>`, e.g. `fix/stuck-loading-state` or `feat/progress-bar`.
2. Make your changes and commit them following the [commit conventions](#commit-messages).
3. Open a pull request against `main` and fill in the PR template.
4. CI must pass and all review conversations must be resolved before merging.
5. PRs are merged with **squash merge** only. The PR title becomes the commit subject on `main`.

`main` is protected: direct pushes, force pushes and branch deletion are disabled for everyone, including admins.

## Commit messages

This project follows [Conventional Commits 1.0.0](https://www.conventionalcommits.org/en/v1.0.0/).

```
<type>(<optional scope>): <subject>

<optional body>

<optional footer(s)>
```

**Types**

| Type | Use for |
| ---------- | ---------------------------------------------------------- |
| `feat` | A new user-facing feature |
| `fix` | A bug fix |
| `docs` | Documentation only (README, CONTRIBUTING, comments) |
| `style` | Formatting, whitespace; no behavior change |
| `refactor` | Code change that neither fixes a bug nor adds a feature |
| `perf` | Performance improvement |
| `test` | Adding or fixing tests |
| `build` | Build tooling, dependencies |
| `ci` | CI configuration (`.github/workflows`) |
| `chore` | Repository maintenance that does not fit any type above |
| `revert` | Reverting a previous commit |

**Scopes** (optional): `activation`, `ui`, `metadata`, `repo`.

**Rules**

- Write in English, in the imperative mood: "add", not "added" or "adds".
- Subject line: at most 72 characters, lowercase first letter, no trailing period.
- Separate the body from the subject with a blank line; explain *what* and *why*, not *how*.
- Mark breaking changes with `!` after the type/scope and a `BREAKING CHANGE:` footer.
- Reference issues in the footer: `Closes #12`.

**Examples**

```
feat(ui): show remaining coupon count on the floating button
fix(activation): wait for MUI loading state to clear before next click
docs: add installation instructions for Violentmonkey
chore(metadata)!: rename script file to payback-helper.user.js
```

## Pull requests

- **Title**: must follow the same Conventional Commits format (checked by CI).
- **Scope**: one logical change per PR; keep unrelated refactors separate.
- **Description**: fill in the template: summary, changes, how you tested it.
- **Testing**: there is no automated browser test, so describe your manual test on `https://www.payback.de/coupons`.

## Versioning

The script uses [Semantic Versioning](https://semver.org/) through the `@version` metadata key. Tampermonkey only offers an update when `@version` increases, so any PR that changes the script's behavior **must** bump it:

- **MAJOR**: breaking change in behavior or a changed `@match` scope
- **MINOR**: new feature
- **PATCH**: bug fix or metadata-only change

Do not change `@name` or `@namespace`: userscript managers use them to identify the script, and changing them makes existing installs appear as a separate script.

## Local checks

```sh
node --check payback-helper.user.js
```
72 changes: 72 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Payback Helper Script

A userscript for [Tampermonkey](https://www.tampermonkey.net/) that activates all of your not-yet-activated eCoupons in the [PAYBACK](https://www.payback.de/) coupon center with a single click.

Instead of clicking "Jetzt aktivieren" on dozens of coupons one by one, you get a floating button that works through all of them for you.

## Features

- **One-click activation**: a floating button in the bottom-right corner activates every open coupon on the page.
- **Live counter**: the button shows how many coupons are still waiting to be activated and updates as the page re-renders.
- **Progress display**: shows `n/total` while it runs.
- **Stop anytime**: click the button again to stop after the current coupon.
- **Gentle on the site**: activates coupons one at a time and waits for each response, with a short pause in between.
- **No permissions**: runs with `@grant none` and only on `https://www.payback.de/coupons*`.

## Installation

1. Install a userscript manager:
- [Tampermonkey](https://www.tampermonkey.net/) (Chrome, Edge, Firefox, Safari, Opera)
- [Violentmonkey](https://violentmonkey.github.io/) also works
2. Click the link below. Your userscript manager will open an install dialog:

**[Install payback-helper.user.js](https://raw.githubusercontent.com/hannesgao/Payback-Helper-Script/main/payback-helper.user.js)**

3. Confirm the installation.

The script includes `@updateURL` and `@downloadURL`, so your userscript manager picks up new versions from this repository automatically.

> **Chrome / Edge users:** recent versions require you to enable **Developer mode** on `chrome://extensions` (or **Allow User Scripts** in the Tampermonkey extension details) before userscripts can run.

## Usage

1. Log in to your PAYBACK account and open the [coupon center](https://www.payback.de/coupons).
2. A blue button labeled **"Alle N Coupons aktivieren"** appears in the bottom-right corner.
3. Click it. The script scrolls to and activates each open coupon in turn, showing its progress on the button.
4. Click the button again at any time to stop.

When it finishes, the button shows how many coupons were activated and returns to its normal state after a few seconds.

## How it works

PAYBACK renders each coupon with a button whose `data-testid` follows the pattern `coupon-button-<id>-not_activated` until it is activated. The script:

1. Finds the next such button it has not tried yet.
2. Clicks it and waits until the button disappears, changes state, or leaves its loading state (up to 6 seconds).
3. Repeats until no open coupons remain or you stop it.

A `MutationObserver` keeps the counter in sync because the coupon list is rendered dynamically by React.

You can adjust the timing constants at the top of the script:

| Constant | Default | Meaning |
| -------------- | ------- | ----------------------------------------------- |
| `MIN_DELAY_MS` | `250` | Minimum pause between two activations (ms) |
| `TIMEOUT_MS` | `6000` | Maximum wait for a single activation (ms) |

## Limitations

- Only supports the German PAYBACK site (`www.payback.de`).
- Relies on PAYBACK's current page markup. If PAYBACK changes its coupon center, the script may stop finding coupons until it is updated. Please [open an issue](https://github.com/hannesgao/Payback-Helper-Script/issues) if that happens.

## Disclaimer

This project is not affiliated with, endorsed by, or connected to PAYBACK GmbH. It only automates clicks you could make yourself in your own logged-in browser session. Use it at your own risk.

## Contributing

Contributions are welcome. Please read [CONTRIBUTING.md](CONTRIBUTING.md) for the branch, commit and pull request conventions.

## License

[MIT](LICENSE) © Hannes Gao
122 changes: 122 additions & 0 deletions payback-helper.user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// ==UserScript==
// @name PAYBACK – Alle Coupons aktivieren
// @name:en PAYBACK – Activate All Coupons
// @namespace https://belvast.de/
// @version 0.2.1
// @description Aktiviert alle noch nicht aktivierten eCoupons im PAYBACK Coupon-Center mit einem Klick
// @description:en Activates all not-yet-activated eCoupons in the PAYBACK coupon center with one click
// @author Hannes Gao
// @license MIT
// @homepageURL https://github.com/hannesgao/Payback-Helper-Script
// @supportURL https://github.com/hannesgao/Payback-Helper-Script/issues
// @updateURL https://raw.githubusercontent.com/hannesgao/Payback-Helper-Script/main/payback-helper.user.js
// @downloadURL https://raw.githubusercontent.com/hannesgao/Payback-Helper-Script/main/payback-helper.user.js
// @match https://www.payback.de/coupons*
// @icon https://www.google.com/s2/favicons?sz=64&domain=payback.de
// @run-at document-idle
// @grant none
// ==/UserScript==

(function () {
'use strict';

// Jeder nicht aktivierte Coupon hat genau einen Button
// data-testid="coupon-button-<id>-not_activated"
// ("Jetzt aktivieren", vereinzelt "JETZT TEILNEHMEN" – gleicher Aktivierungs-Flow).
const SELECTOR = 'button[data-testid^="coupon-button-"][data-testid$="-not_activated"]';
const MIN_DELAY_MS = 250; // Mindestpause zwischen zwei Aktivierungen
const TIMEOUT_MS = 6000; // max. Wartezeit auf die Antwort einer Aktivierung

const attempted = new Set();
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
const couponId = (b) => b.dataset.testid.replace(/^coupon-button-|-not_activated$/g, '');

const nextButton = () =>
[...document.querySelectorAll(SELECTOR)].find(
(b) => !attempted.has(couponId(b)) && !b.disabled && !b.classList.contains('Mui-disabled')
);

const pendingCount = () =>
[...document.querySelectorAll(SELECTOR)].filter((b) => !attempted.has(couponId(b))).length;

// Nach dem Klick zeigt MUI einen Ladezustand; danach verschwindet der Button
// bzw. wird durch "Vor Ort / Online einlösen" ersetzt.
async function waitForActivation(btn) {
const start = Date.now();
await sleep(MIN_DELAY_MS);
while (Date.now() - start < TIMEOUT_MS) {
const done =
!btn.isConnected ||
!btn.matches(SELECTOR) ||
(!btn.classList.contains('MuiButton-loading') && !btn.disabled && Date.now() - start > 800);
if (done) return;
await sleep(150);
}
}

let running = false;

async function activateAll(ui) {
if (running) {
running = false; // zweiter Klick = abbrechen
return;
}
running = true;
const total = pendingCount();
let done = 0;

let btn;
while (running && (btn = nextButton())) {
attempted.add(couponId(btn));
btn.scrollIntoView({ block: 'center', behavior: 'instant' });
btn.click();
await waitForActivation(btn);
done++;
ui.textContent = `Aktiviere… ${done}/${total} (Klick = Stopp)`;
}

const stopped = !running;
running = false;
ui.textContent = stopped ? `Gestoppt nach ${done}` : done ? `✓ ${done} Coupons aktiviert` : 'Keine offenen Coupons';
setTimeout(updateLabel, 5000);
}

let ui;
function updateLabel() {
if (!ui || running) return;
const n = document.querySelectorAll(SELECTOR).length;
ui.textContent = n ? `Alle ${n} Coupons aktivieren` : 'Alle Coupons aktivieren';
}

function addButton() {
if (document.getElementById('pb-activate-all')) return;
ui = document.createElement('button');
ui.id = 'pb-activate-all';
Object.assign(ui.style, {
position: 'fixed',
right: '20px',
bottom: '20px',
zIndex: 2147483647,
padding: '12px 18px',
background: '#0046aa',
color: '#fff',
border: 'none',
borderRadius: '24px',
font: '600 15px/1.2 system-ui, sans-serif',
boxShadow: '0 4px 12px rgba(0,0,0,.25)',
cursor: 'pointer',
});
ui.addEventListener('click', () => activateAll(ui));
document.body.appendChild(ui);
updateLabel();
// Liste wird per React nachgerendert – Zähler aktuell halten
let scheduled = false;
new MutationObserver(() => {
if (scheduled) return;
scheduled = true;
setTimeout(() => { scheduled = false; updateLabel(); }, 500);
}).observe(document.body, { childList: true, subtree: true });
}

addButton();
})();
Loading