makefuture / games / accept-the-cookie / game / scenes / RevealScene.js
228 words
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { buildProfile } from '../systems/profile.js?v=20260427c';
import { createShareCard } from '../systems/shareCard.js?v=20260427c';

export class RevealScene extends Phaser.Scene {
    constructor() {
        super('RevealScene');
    }

    init(data) {
        this.session = data.session;
    }

    create() {
        this.session.endedAt = Date.now();
        const profile = buildProfile(this.session);
        this.cameras.main.setBackgroundColor(0xf7f7f2);
        this.renderReceipt(profile);
    }

    renderReceipt(profile) {
        const overlay = document.createElement('div');
        overlay.className = 'receipt-backdrop';
        overlay.innerHTML = `
            <article class="receipt">
                <h1>DATA RECEIPT</h1>
                <div class="receipt-line"><span>Session ID</span><strong>${escapeHtml(profile.header.sessionId)}</strong></div>
                <div class="receipt-line"><span>Duration</span><strong>${escapeHtml(profile.header.duration)}</strong></div>
                <div class="receipt-line"><span>Date</span><strong>${escapeHtml(profile.header.date)}</strong></div>
                <div class="receipt-grid">
                    ${sectionTemplate('DEVICE PROFILE', profile.device)}
                    ${sectionTemplate('BEHAVIORAL PROFILE', profile.behavioral)}
                    ${sectionTemplate('ESTIMATED AD PROFILE', profile.advertising)}
                </div>
                <section class="receipt-section">
                    <h2>CONTEXT</h2>
                    ${profile.context.copy.map((line) => `<p class="receipt-callout">${escapeHtml(line)}</p>`).join('')}
                </section>
                <section class="receipt-section">
                    <h2>WHAT WE NOTICED</h2>
                    ${profile.callouts.map((line) => `<p class="receipt-callout">${escapeHtml(line)}</p>`).join('')}
                    <p class="receipt-callout">This game collected your data for a few minutes to show you what it feels like. The rest of the internet does it 24/7 and rarely shows you this screen.</p>
                </section>
                <div class="receipt-actions">
                    <button type="button" data-share>Share your receipt</button>
                    <a class="secondary" href="./?privacy=1">Play again (with privacy)</a>
                    <a class="secondary" href="/privacy.html">Learn more</a>
                    <a class="secondary" href="https://www.eff.org/issues/privacy" rel="noopener noreferrer">EFF privacy resources</a>
                    <a class="secondary" href="https://privacybadger.org/" rel="noopener noreferrer">Privacy Badger</a>
                    <a class="secondary" href="https://www.mozilla.org/privacy/" rel="noopener noreferrer">Mozilla privacy</a>
                </div>
            </article>
        `;
        document.body.appendChild(overlay);
        overlay.querySelector('[data-share]').addEventListener('click', async () => {
            const url = createShareCard(profile, this.session);
            const link = document.createElement('a');
            link.download = 'accept-the-cookie-data-receipt.png';
            link.href = url;
            link.click();
        });
        this.events.once('shutdown', () => overlay.remove());
    }
}

function sectionTemplate(title, lines) {
    return `
        <section class="receipt-section">
            <h2>${escapeHtml(title)}</h2>
            ${Object.entries(lines).map(([key, value]) => `
                <div class="receipt-line"><span>${escapeHtml(key)}</span><strong>${escapeHtml(String(value))}</strong></div>
            `).join('')}
        </section>
    `;
}

function escapeHtml(value) {
    return value
        .replaceAll('&', '&amp;')
        .replaceAll('<', '&lt;')
        .replaceAll('>', '&gt;')
        .replaceAll('"', '&quot;')
        .replaceAll("'", '&#039;');
}

static mirror of HEAD · about · clone: git clone https://git.makefuture.ro/makefuture.git