tangled
alpha
login
or
join now
claycow.com
/
claycow
0
fork
atom
A Astro blog hosted on Vercel
0
fork
atom
overview
issues
pulls
pipelines
pat cheese confetti
Clayton Cook
4 months ago
b75dbe55
78a5bb56
1/1
deploy.yaml
success
45s
+61
-13
1 changed file
expand all
collapse all
unified
split
src
pages
pat.astro
+61
-13
src/pages/pat.astro
reviewed
···
6
6
<!doctype html>
7
7
<html lang="en">
8
8
<head>
9
9
-
<Head title={'🐀'} description={'Pat the rat'} />
9
9
+
<Head title={'🐀'} description={'pat the rat'} />
10
10
+
<script
11
11
+
defer
12
12
+
src="https://cdn.jsdelivr.net/npm/canvas-confetti@1.9.4/dist/confetti.browser.min.js"
13
13
+
>
14
14
+
</script>
10
15
<style>
11
16
@keyframes squish {
12
17
0% {
···
24
29
display: flex;
25
30
justify-content: center;
26
31
align-items: center;
32
32
+
gap: 8rem;
33
33
+
}
34
34
+
35
35
+
body > main > p#cheeses {
36
36
+
display: flex;
37
37
+
flex-direction: row;
38
38
+
gap: 1rem;
39
39
+
font-size: 2rem;
40
40
+
}
41
41
+
42
42
+
body > main > p#cheeses[data-cheeses='0'] {
43
43
+
visibility: hidden;
44
44
+
}
45
45
+
46
46
+
body > main > p#cheeses::after {
47
47
+
content: attr(data-cheeses);
27
48
}
28
49
29
50
body > main > img {
···
45
66
<source src="/rat-squeak.mp3" type="audio/mp3" />
46
67
</audio>
47
68
<main>
69
69
+
<p id="cheeses" data-cheeses="0">🧀</p>
48
70
<Image
49
71
id={'pat'}
50
50
-
alt="Pat the rat"
72
72
+
alt="pat the rat"
51
73
src={'/pat.webp'}
52
74
width={128}
53
75
height={128}
54
76
/>
55
77
</main>
56
78
<script>
57
57
-
const pat = document.querySelector<HTMLImageElement>('img#pat');
79
79
+
let cheeses = 0;
80
80
+
const $PAT = document.querySelector<HTMLImageElement>('img#pat');
81
81
+
const $CHEESES =
82
82
+
document.querySelector<HTMLParagraphElement>('p#cheeses');
83
83
+
const cheese = confetti.shapeFromText({ text: '🧀', scalar: 5 });
58
84
59
59
-
pat?.addEventListener('click', () => {
60
60
-
if (!pat) return;
85
85
+
window.addEventListener('load', () => {
86
86
+
window.cookieStore.get('cheeses').then((item) => {
87
87
+
if (!$CHEESES) return;
88
88
+
cheeses = parseInt(item?.value ?? '0');
89
89
+
$CHEESES.setAttribute('data-cheeses', cheeses.toString());
90
90
+
});
91
91
+
});
92
92
+
93
93
+
$PAT?.addEventListener('click', () => {
94
94
+
if (!$PAT) return;
95
95
+
if (!$CHEESES) return;
61
96
const squeakAudio = new Audio('rat-squeak.mp3');
62
97
63
63
-
pat.style.animationName = 'none';
64
64
-
pat.offsetHeight;
98
98
+
$PAT.style.animationName = 'none';
99
99
+
$PAT.offsetHeight;
65
100
66
66
-
pat.style.animationName = 'squish';
67
67
-
pat.style.animationPlayState = 'running';
101
101
+
$PAT.style.animationName = 'squish';
102
102
+
$PAT.style.animationPlayState = 'running';
68
103
squeakAudio.currentTime = 0;
69
104
squeakAudio.play();
105
105
+
106
106
+
cheeses += 1;
107
107
+
$CHEESES.setAttribute('data-cheeses', cheeses.toString());
108
108
+
window.cookieStore.set('cheeses', cheeses.toString());
109
109
+
110
110
+
if (cheeses % 100 === 0) {
111
111
+
confetti({
112
112
+
particleCount: cheeses,
113
113
+
spread: 360,
114
114
+
shapes: [cheese],
115
115
+
scalar: 5,
116
116
+
});
117
117
+
}
70
118
});
71
119
72
72
-
pat?.addEventListener('animationend', () => {
73
73
-
if (!pat) return;
120
120
+
$PAT?.addEventListener('animationend', () => {
121
121
+
if (!$PAT) return;
74
122
75
75
-
pat.style.animationName = 'none';
76
76
-
pat.style.animationPlayState = 'paused';
123
123
+
$PAT.style.animationName = 'none';
124
124
+
$PAT.style.animationPlayState = 'paused';
77
125
});
78
126
</script>
79
127
</body>