This is a tiny, playful userscript that turns clearing your Gmail inbox into a race against the clock. Instead of confronting an intimidating mountain of emails, you’re given one simple challenge: deal with the next email in 30 seconds. Archive it. Delete it. Move it. Turn it into a task. Just make a decision before the timer runs out. Then do it again.
How it works
A barely visible, 1-pixel countdown bar sits at the top of Gmail. You’ve got 30 seconds to act.
- 🟢 30–10 seconds: Plenty of time. Make your decision.
- 🟡 10–5 seconds: Getting close!
- 🔴 Final 5 seconds: Hurry up!
- 🔵 Success! You’ve dealt with an email. Points awarded.
After a brief 1.5-second breather, the next round begins automatically. The game recognises common Gmail actions, including archiving, deleting, moving and turning emails into tasks. You can pause whenever you need to.
The fun bit
Inbox Game borrows a handful of mechanics from arcade games:
- Beat the clock: Every email becomes a miniature timed challenge.
- Build a streak: Keep making decisions without running out of time.
- Earn points: The faster you act, the more you score. Consecutive successes unlock a multiplier of up to 2×.
- Find your momentum: Compare your last five decisions with the previous five. Are you speeding up, slowing down or holding steady?
- Chase your average: Watch how quickly you’re getting through your inbox.
- Keep your flow: No menus, levels or complicated controls. Just emails and decisions.
A tiny scoreboard quietly tracks your progress, while your browser tab displays your countdown, clears and streak.
A toy, not a productivity philosophy
The game doesn’t write replies, prioritise your messages or magically achieve Inbox Zero. It doesn’t even care how many emails I have. It simply makes the act of processing your inbox a little less awful. Some emails deserve careful thought, and the pause shortcut is there for precisely that reason. The aim isn’t to make every decision hurried; it’s to stop trivial decisions expanding to fill the afternoon.
Anyway, this is just a way to help me find this again :)
// ==UserScript==
// @name Inbox Game
// @description Timed rounds for clearing Gmail. Average, streak, momentum and points.
// @match https://mail.google.com/*
// @run-at document-idle
// @grant none
// ==/UserScript==
(() => {
'use strict';
`if (window.__inboxGame) {`
`window.__inboxGame.stop();`
`}`
`const LIMIT_MS = 30000;`
`const WARN_MS = 10000;`
`const DANGER_MS = 5000;`
`const NEXT_ROUND_DELAY_MS = 1500;`
`const WINDOW = 5;`
`const COLOURS = { ok: '#2e7d32', warn: '#f9a825', danger: '#c62828', done: '#1565c0' };`
`// Words Gmail shows in its confirmation toast (English interface).`
`const TOAST_RULES = [`
`{ kind: 'archive', test: /archived/i },`
`{ kind: 'todo', test: /task/i },`
`{ kind: 'move', test: /moved|label/i },`
`{ kind: 'delete', test: /deleted|trash|bin\b/i },`
`];`
`const reducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)');`
`const isRtl = getComputedStyle(document.documentElement).direction === 'rtl';`
`// The 1px countdown bar.`
`const bar = document.createElement('div');`
`bar.setAttribute('aria-hidden', 'true');`
`Object.assign(bar.style, {`
`position: 'fixed',`
`insetBlockStart: '0',`
`insetInlineStart: '0',`
`inlineSize: '100%',`
`blockSize: '1px',`
`zIndex: '2147483647',`
`pointerEvents: 'none',`
`transformOrigin: isRtl ? 'right center' : 'left center',`
`transform: 'scaleX(0)',`
`background: COLOURS.ok,`
`});`
`// Small score panel. The status region below gives the same facts as text.`
`const hud = document.createElement('p');`
`hud.setAttribute('aria-hidden', 'true');`
`Object.assign(hud.style, {`
`position: 'fixed',`
`insetBlockEnd: '8px',`
`insetInlineEnd: '8px',`
`zIndex: '2147483647',`
`margin: '0',`
`paddingBlock: '4px',`
`paddingInline: '8px',`
`borderRadius: '4px',`
`background: '#202124',`
`color: '#ffffff',`
`font: '12px/1.4 system-ui, sans-serif',`
`pointerEvents: 'none',`
`});`
`const status = document.createElement('p');`
`status.setAttribute('role', 'status');`
`Object.assign(status.style, {`
`position: 'absolute',`
`inlineSize: '1px',`
`blockSize: '1px',`
`overflow: 'hidden',`
`clipPath: 'inset(50%)',`
`whiteSpace: 'nowrap',`
`});`
`document.body.append(bar, hud, status);`
`const stats = {`
`times: [],`
`missed: 0,`
`streak: 0,`
`bestStreak: 0,`
`points: 0,`
`};`
`let startedAt = 0;`
`let running = false;`
`let paused = false;`
`let frame = 0;`
`let nextTimer = 0;`
`let lastSecond = -1;`
`let lastToast = '';`
`let toastTimer = 0;`
`let freshToast = false;`
`function mean(list) {`
`return list.length ? list.reduce((sum, value) => sum + value, 0) / list.length : 0;`
`}`
`function seconds(ms) {`
`return (ms / 1000).toFixed(1);`
`}`
`// Momentum: last WINDOW times against the WINDOW before them. Faster is up.`
`function momentum() {`
`const { times } = stats;`
`if (times.length < WINDOW * 2) {`
`return { symbol: '–', word: 'building' };`
`}`
`const recent = mean(times.slice(-WINDOW));`
`const before = mean(times.slice(-WINDOW * 2, -WINDOW));`
`const change = (before - recent) / before;`
`if (change > 0.1) {`
`return { symbol: '▲', word: 'speeding up' };`
`}`
`if (change < -0.1) {`
`return { symbol: '▼', word: 'slowing down' };`
`}`
`return { symbol: '▬', word: 'steady' };`
`}`
`function pace() {`
`const total = stats.times.reduce((sum, value) => sum + value, 0);`
`return total ? (stats.times.length / (total / 60000)) : 0;`
`}`
`function summary() {`
`const { times, missed, streak, points } = stats;`
`const move = momentum();`
`return [`
``${times.length} cleared`,`
``${missed} missed`,`
``avg ${seconds(mean(times))}s`,`
``last ${WINDOW} ${seconds(mean(times.slice(-WINDOW)))}s`,`
``streak ${streak}`,`
``momentum ${move.symbol} ${move.word}`,`
``${pace().toFixed(1)}/min`,`
``${points} points`,`
`].join(' · ');`
`}`
`function setTitle(text) {`
`const clean = document.title.replace(/^\[[^\]]*\] /, '');`
`document.title = text ? `[${text}] ${clean}` : clean;`
`}`
`function shortScore() {`
`return `✓${stats.times.length} ✗${stats.missed} 🔥${stats.streak} ${momentum().symbol}`;`
`}`
`function render() {`
`hud.textContent = summary();`
`}`
`function announce(message) {`
`status.textContent = `${message}. ${summary()}`;`
`render();`
`}`
`function paint(remaining) {`
`const left = Math.ceil(remaining / 1000);`
`const share = reducedMotion.matches`
`? left / (LIMIT_MS / 1000)`
`: Math.max(0, remaining / LIMIT_MS);`
`bar.style.transform = `scaleX(${share})`;`
`bar.style.background = remaining <= DANGER_MS`
`? COLOURS.danger`
`: remaining <= WARN_MS ? COLOURS.warn : COLOURS.ok;`
`if (left !== lastSecond) {`
`lastSecond = left;`
`setTitle(`${left}s ${shortScore()}`);`
`if (left === 10 || left === 5) {`
`announce(`${left} seconds left`);`
`}`
`}`
`}`
`function scheduleNext() {`
`clearTimeout(nextTimer);`
`if (!paused) {`
`nextTimer = setTimeout(start, NEXT_ROUND_DELAY_MS);`
`}`
`}`
`function tick() {`
`if (!running) {`
`return;`
`}`
`const remaining = LIMIT_MS - (performance.now() - startedAt);`
`if (remaining <= 0) {`
`running = false;`
`stats.missed += 1;`
`stats.streak = 0;`
`bar.style.transform = 'scaleX(1)';`
`bar.style.background = COLOURS.danger;`
`setTitle(`Time up ${shortScore()}`);`
`announce('Time is up. Streak lost');`
`scheduleNext();`
`return;`
`}`
`paint(remaining);`
`frame = requestAnimationFrame(tick);`
`}`
`function start() {`
`clearTimeout(nextTimer);`
`cancelAnimationFrame(frame);`
`startedAt = performance.now();`
`running = true;`
`lastSecond = -1;`
`tick();`
`}`
`function resolve(kind) {`
`if (!running) {`
`return;`
`}`
`const elapsed = performance.now() - startedAt;`
`running = false;`
`cancelAnimationFrame(frame);`
`stats.times.push(elapsed);`
`stats.streak += 1;`
`stats.bestStreak = Math.max(stats.bestStreak, stats.streak);`
`// Points: seconds left, times a streak bonus of 10% per clear (up to 2x).`
`const bonus = 1 + Math.min(stats.streak - 1, 10) * 0.1;`
`const earned = Math.round(((LIMIT_MS - elapsed) / 1000) * bonus);`
`stats.points += earned;`
`bar.style.transform = 'scaleX(1)';`
`bar.style.background = COLOURS.done;`
`setTitle(`${kind} ${seconds(elapsed)}s +${earned} ${shortScore()}`);`
`announce(`${kind} in ${seconds(elapsed)} seconds, plus ${earned} points`);`
`scheduleNext();`
`}`
`function togglePause() {`
`paused = !paused;`
`if (paused) {`
`running = false;`
`cancelAnimationFrame(frame);`
`clearTimeout(nextTimer);`
`bar.style.transform = 'scaleX(0)';`
`setTitle(`paused ${shortScore()}`);`
`announce('Paused');`
`} else {`
`announce('Resumed');`
`start();`
`}`
`}`
`// Action detection 1: the confirmation toast that Gmail shows.`
`function checkToast() {`
`const text = Array.from(document.querySelectorAll('[role="alert"]'))`
`.map((node) => node.textContent.trim())`
`.join(' ');`
`const fresh = freshToast;`
`freshToast = false;`
`if (!text) {`
`lastToast = '';`
`return;`
`}`
`if (text === lastToast && !fresh) {`
`return;`
`}`
`lastToast = text;`
`const rule = TOAST_RULES.find((item) => item.test.test(text));`
`if (rule) {`
`resolve(rule.kind);`
`}`
`}`
`function isAlert(node) {`
`return node.nodeType === Node.ELEMENT_NODE`
`&& (node.getAttribute('role') === 'alert' || node.querySelector('[role="alert"]'));`
`}`
`const observer = new MutationObserver((mutations) => {`
`// A new alert element means a new toast, even when the words repeat.`
`if (mutations.some((item) => Array.from(item.addedNodes).some(isAlert))) {`
`freshToast = true;`
`}`
`clearTimeout(toastTimer);`
`toastTimer = setTimeout(checkToast, 100);`
`});`
`observer.observe(document.body, { childList: true, subtree: true, characterData: true });`
`// Action detection 2: Shift+T (add to Tasks) has no toast. Alt+P pauses.`
`function onKey(event) {`
`const typing = event.target.closest('input, textarea, [contenteditable="true"]');`
`if (event.altKey && event.code === 'KeyP') {`
`togglePause();`
`} else if (!typing && event.shiftKey && event.key === 'T') {`
`resolve('todo');`
`}`
`}`
`document.addEventListener('keydown', onKey, true);`
`window.__inboxGame = {`
`stats,`
`stop() {`
`cancelAnimationFrame(frame);`
`clearTimeout(nextTimer);`
`clearTimeout(toastTimer);`
`observer.disconnect();`
`document.removeEventListener('keydown', onKey, true);`
`bar.remove();`
`hud.remove();`
`status.remove();`
`setTitle('');`
`delete window.__inboxGame;`
`},`
`};`
`render();`
`start();`
})();