-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
340 lines (306 loc) · 24.5 KB
/
index.html
File metadata and controls
340 lines (306 loc) · 24.5 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-M8VGTNS7');</script>
<!-- End Google Tag Manager -->
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- SEO Meta Tags -->
<title>Free Cookie Exporter | Download Website Cookies as CSV</title>
<meta name="description" content="A free online tool to easily extract and download all browser cookies from any website as a .csv file. Perfect for developers, QA testers, and SEO analysts.">
<meta name="keywords" content="cookie exporter, download cookies, cookie scraper, export cookies csv, selenium, web scraping tool, developer tools">
<!-- NEW: Favicon -->
<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path stroke-linecap='round' stroke-linejoin='round' stroke-width='2' stroke='%234F46E5' d='M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4' /></svg>">
<link rel="canonical" href="https://melogabriel.github.io/cookie-scrapper/">
<!-- Open Graph / Facebook -->
<meta property="og:type" content="website">
<meta property="og:url" content="https://melogabriel.github.io/cookie-scrapper/">
<meta property="og:title" content="Free Cookie Exporter | Download Website Cookies as CSV">
<meta property="og:description" content="A free online tool to easily extract and download all browser cookies from any website as a .csv file.">
<meta property="og:image" content="https://melogabriel.github.io/cookie-scrapper/social-preview.png">
<!-- Twitter -->
<meta property="twitter:card" content="summary_large_image">
<meta property="twitter:url" content="https://melogabriel.github.io/cookie-scrapper/">
<meta property="twitter:title" content="Free Cookie Exporter | Download Website Cookies as CSV">
<meta property="twitter:description" content="A free online tool to easily extract and download all browser cookies from any website as a .csv file.">
<meta property="twitter:image" content="https://melogabriel.github.io/cookie-scrapper/social-preview.png">
<!-- Tailwind CSS & Google Fonts -->
<script src="https://cdn.tailwindcss.com"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<style>
body { font-family: 'Inter', sans-serif; }
.spinner {
border: 2px solid rgba(255, 255, 255, 0.3);
border-top-color: #fff;
border-radius: 50%;
width: 1rem;
height: 1rem;
animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#shareModal.hidden { display: none; }
</style>
<!-- AEO: JSON-LD Structured Data -->
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "SoftwareApplication",
"name": "Cookie Exporter",
"applicationCategory": "DeveloperApplication",
"operatingSystem": "Web",
"browserRequirements": "Requires a modern web browser.",
"description": "A free web-based tool that allows users to extract and download cookies from any URL as a CSV file.",
"url": "https://melogabriel.github.io/cookie-scrapper/",
"author": {
"@type": "Person",
"name": "Gabriel Melo",
"url": "https://github.com/melogabriel"
},
"offers": {
"@type": "Offer",
"price": "0"
}
}
</script>
</head>
<body class="bg-slate-50 flex items-center justify-center min-h-screen py-12 px-4">
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-M8VGTNS7"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
<div class="w-full max-w-2xl mx-auto">
<main class="bg-white p-8 sm:p-10 rounded-2xl shadow-xl border border-slate-200">
<!-- Header Section -->
<header class="text-center mb-8 relative">
<div class="flex items-center justify-center gap-3 mb-4">
<svg role="img" aria-label="Code Icon" xmlns="http://www.w3.org/2000/svg" class="h-8 w-8 text-indigo-600" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4" />
</svg>
<h1 class="text-3xl sm:text-4xl font-bold text-slate-800">Cookie Exporter</h1>
</div>
<p class="text-slate-500">Enter a URL to download its cookies as a .csv file.</p>
</header>
<!-- Form Section -->
<form id="cookie-form">
<div class="mb-5">
<label for="url-input" class="block text-slate-700 text-sm font-semibold mb-2">Target URL</label>
<div class="flex items-center bg-slate-50 border-2 border-slate-200 rounded-xl focus-within:ring-2 focus-within:ring-indigo-500 focus-within:border-indigo-500 transition-all duration-300 p-1">
<svg role="img" aria-label="Link Icon" xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mx-3 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1" />
</svg>
<input type="text" id="url-input" placeholder="example.com" required
class="w-full px-2 py-2 text-slate-700 bg-transparent border-none focus:outline-none focus:ring-0">
</div>
</div>
<button type="submit" id="submitButton"
class="w-full bg-indigo-600 text-white font-semibold py-3 px-4 rounded-xl hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 transition-transform transform hover:scale-[1.02] disabled:bg-indigo-400 disabled:cursor-not-allowed flex items-center justify-center">
<span id="buttonText">Download Cookies</span>
<div id="buttonSpinner" class="spinner hidden"></div>
</button>
</form>
<!-- Message/Feedback Area -->
<div id="messageDiv" class="mt-6 text-center text-sm text-slate-600 min-h-[48px] flex items-center justify-center p-2 border border-transparent rounded-lg"></div>
</main>
<!-- On-Page Content Section -->
<section class="mt-10 text-slate-700 text-sm leading-relaxed">
<h2 class="text-lg font-semibold text-slate-800 text-center mb-4">How It Works</h2>
<p class="text-center">This tool uses a server-side automated browser to visit the URL you provide. It captures all accessible cookies (primarily first-party cookies due to modern browser privacy standards) and formats them into a downloadable CSV file. The process is ideal for developers needing to inspect session data or analysts reviewing a site's cookie implementation.</p>
</section>
<!-- Footer -->
<footer class="text-center mt-8 space-y-2">
<p class="text-slate-500 text-sm">
Developed by <a href="https://github.com/melogabriel" target="_blank" rel="noopener noreferrer" class="font-medium text-indigo-600 hover:underline">Gabriel Melo</a>
</p>
<div class="text-slate-500 text-sm flex items-center justify-center gap-x-4">
<a href="https://github.com/melogabriel/cookie-scraper/issues/new" target="_blank" rel="noopener noreferrer" class="font-medium text-indigo-600 hover:underline">Report an Issue</a>
<span class="text-slate-300">|</span>
<a href="https://github.com/melogabriel/cookie-scraper/compare" target="_blank" rel="noopener noreferrer" class="font-medium text-indigo-600 hover:underline">Contribute</a>
</div>
</footer>
</div>
<!-- Share Modal -->
<div id="shareModal" class="fixed inset-0 bg-slate-900 bg-opacity-50 flex items-center justify-center p-4 transition-opacity duration-300 hidden opacity-0">
<div class="bg-white w-full max-w-lg p-6 rounded-2xl shadow-xl border border-slate-200 transform transition-all duration-300 scale-95" id="shareModalContent">
<div class="flex justify-between items-center mb-4">
<h3 class="text-xl font-bold text-slate-800">Share this Tool</h3>
<button id="closeShareModalBtn" class="p-2 text-slate-400 hover:text-slate-600 rounded-full">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
</div>
<p class="text-slate-500 mb-6">Help others discover this free cookie exporter.</p>
<!-- Social Links Grid -->
<div class="grid grid-cols-2 sm:grid-cols-3 gap-4 mb-6">
<!-- Twitter -->
<a href="#" id="shareTwitter" target="_blank" class="flex items-center justify-center gap-3 p-3 bg-gray-900 text-white font-semibold rounded-lg shadow-md hover:shadow-lg transform hover:-translate-y-1 transition-all">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" viewBox="0 0 16 16"><path d="M12.6.75h2.454l-5.36 6.142L16 15.25h-4.937l-3.867-5.07-4.425 5.07H.316l5.733-6.57L0 .75h5.063l3.495 4.633L12.6.75zm-.86 13.028h1.36L4.323 2.145H2.865l8.875 11.633z"/></svg>
<span>Twitter</span>
</a>
<!-- Facebook -->
<a href="#" id="shareFacebook" target="_blank" class="flex items-center justify-center gap-3 p-3 bg-[#1877F2] text-white font-semibold rounded-lg shadow-md hover:shadow-lg transform hover:-translate-y-1 transition-all">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" viewBox="0 0 16 16"><path d="M16 8.049c0-4.446-3.582-8.05-8-8.05C3.58 0-.002 3.603-.002 8.05c0 4.017 2.926 7.347 6.75 7.951v-5.625h-2.03V8.05H6.75V6.275c0-2.017 1.195-3.131 3.022-3.131.876 0 1.791.157 1.791.157v2.278h-1.31c-.979 0-1.168.465-1.168 1.14v1.499h2.531l-.42 2.375h-2.11V16c3.824-.604 6.75-3.934 6.75-7.951z"/></svg>
<span>Facebook</span>
</a>
<!-- LinkedIn -->
<a href="#" id="shareLinkedIn" target="_blank" class="flex items-center justify-center gap-3 p-3 bg-[#0A66C2] text-white font-semibold rounded-lg shadow-md hover:shadow-lg transform hover:-translate-y-1 transition-all">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" viewBox="0 0 16 16"><path d="M0 1.146C0 .513.526 0 1.175 0h13.65C15.474 0 16 .513 16 1.146v13.708c0 .633-.526 1.146-1.175 1.146H1.175C.526 16 0 15.487 0 14.854V1.146zm4.943 12.248V6.169H2.542v7.225h2.401zm-1.2-8.212c.837 0 1.358-.554 1.358-1.248-.015-.709-.52-1.248-1.342-1.248-.822 0-1.359.54-1.359 1.248 0 .694.521 1.248 1.327 1.248h.016zm4.908 8.212V9.359c0-.216.016-.432.08-.586.173-.431.568-.878 1.232-.878.869 0 1.216.662 1.216 1.634v3.865h2.401V9.25c0-2.22-1.184-3.252-2.764-3.252-1.274 0-1.845.7-2.165 1.193v.025h-.016a5.54 5.54 0 0 1 .016-.025V6.169h-2.4c.03.678 0 7.225 0 7.225h2.4z"/></svg>
<span>LinkedIn</span>
</a>
<!-- WhatsApp -->
<a href="#" id="shareWhatsApp" target="_blank" class="flex items-center justify-center gap-3 p-3 bg-[#25D366] text-white font-semibold rounded-lg shadow-md hover:shadow-lg transform hover:-translate-y-1 transition-all">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" viewBox="0 0 16 16"><path d="M13.601 2.326A7.854 7.854 0 0 0 7.994 0C3.627 0 .068 3.558.064 7.926c0 1.399.366 2.76 1.057 3.965L0 16l4.204-1.102a7.933 7.933 0 0 0 3.79.965h.004c4.368 0 7.926-3.558 7.93-7.93A7.898 7.898 0 0 0 13.6 2.326zM7.994 14.521a6.573 6.573 0 0 1-3.356-.92l-.24-.144-2.494.654.666-2.433-.156-.251a6.56 6.56 0 0 1-1.007-3.505c0-3.626 2.957-6.584 6.591-6.584a6.56 6.56 0 0 1 4.66 1.931 6.557 6.557 0 0 1 1.928 4.66c-.004 3.639-2.961 6.592-6.592 6.592zm3.615-4.934c-.197-.099-1.17-.578-1.353-.646-.182-.065-.315-.099-.445.099-.133.197-.513.646-.627.775-.114.133-.232.148-.43.05-.197-.1-.836-.308-1.592-.985-.59-.525-.985-1.175-1.103-1.372-.114-.198-.011-.304.088-.403.087-.088.197-.232.296-.346.1-.114.133-.198.198-.33.065-.134.034-.248-.015-.347-.05-.099-.445-1.076-.612-1.47-.16-.389-.323-.335-.445-.34-.114-.007-.247-.007-.38-.007a.729.729 0 0 0-.529.247c-.182.198-.691.677-.691 1.654 0 .977.71 1.916.81 2.049.098.133 1.394 2.132 3.383 2.992.47.205.84.326 1.129.418.475.152.904.129 1.246.08.38-.058 1.171-.48 1.338-.943.164-.464.164-.86.114-.943-.049-.084-.182-.133-.38-.232z"/></svg>
<span>WhatsApp</span>
</a>
<!-- Telegram -->
<a href="#" id="shareTelegram" target="_blank" class="flex items-center justify-center gap-3 p-3 bg-[#26A5E4] text-white font-semibold rounded-lg shadow-md hover:shadow-lg transform hover:-translate-y-1 transition-all">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" viewBox="0 0 16 16"><path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM8.287 5.906c-.778.324-2.334.994-4.666 2.01-.378.15-.577.298-.595.442-.03.243.275.339.69.47l.175.055c.408.133.958.288 1.243.294.26.006.549-.1.868-.32 2.179-1.471 3.304-2.214 3.374-2.23.05-.012.12-.026.166.016.047.041.042.12.037.141-.03.129-1.227 1.241-1.846 1.817-.193.18-.33.307-.358.336a8.154 8.154 0 0 1-.188.186c-.38.366-.664.64.015 1.088.327.216.589.393.85.571.284.194.568.387.936.629.093.06.183.125.27.187.331.236.63.448.997.414.214-.02.435-.22.547-.82.265-1.417.786-4.486.906-5.751a1.426 1.426 0 0 0-.013-.315.337.337 0 0 0-.114-.217.526.526 0 0 0-.31-.093c-.396.008-.748.172-1.023.322z"/></svg>
<span>Telegram</span>
</a>
<!-- Email -->
<a href="#" id="shareMail" class="flex items-center justify-center gap-3 p-3 bg-slate-500 text-white font-semibold rounded-lg shadow-md hover:shadow-lg transform hover:-translate-y-1 transition-all">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" viewBox="0 0 16 16"><path d="M.05 3.555A2 2 0 0 1 2 2h12a2 2 0 0 1 1.95 1.555L8 8.414.05 3.555zM0 4.697v7.104l5.803-3.558L0 4.697zM6.761 8.83l-6.57 4.027A2 2 0 0 0 2 14h12a2 2 0 0 0 1.808-1.144l-6.57-4.027L8 9.586l-1.239-.757zm3.436-.586L16 11.801V4.697l-5.803 3.558z"/></svg>
<span>Email</span>
</a>
</div>
<!-- Copy Link Section -->
<div class="flex items-center gap-2">
<input id="shareUrlInput" type="text" readonly value="https://melogabriel.github.io/cookie-scrapper/" class="w-full px-3 py-2 text-sm text-slate-500 bg-slate-100 border border-slate-200 rounded-lg focus:outline-none">
<button id="copyLinkBtn" class="flex-shrink-0 flex items-center justify-center gap-2 p-3 bg-slate-600 text-white font-semibold rounded-lg hover:bg-slate-700 transition-colors">
<span id="copyIcon">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M4.715 6.542 3.343 7.914a3 3 0 1 0 4.243 4.243l1.828-1.829A3 3 0 0 0 8.586 5.5L8 6.086a1.002 1.002 0 0 0-.154.199 2 2 0 0 1 .861 3.337L6.88 11.45a2 2 0 1 1-2.83-2.83l.793-.792a4.018 4.018 0 0 1-.128-1.287z"/><path d="M6.586 4.672A3 3 0 0 0 7.414 9.5l.775-.776a2 2 0 0 1-.896-3.346L9.12 3.55a2 2 0 1 1 2.83 2.83l-.793.792c.112.42.155.855.128 1.287l1.372-1.372a3 3 0 1 0-4.243-4.243L6.586 4.672z"/></svg>
</span>
<span id="checkIcon" class="hidden">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0z"/></svg>
</span>
<span id="copyLinkText">Copy</span>
</button>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
// --- Elements ---
const cookieForm = document.getElementById('cookie-form');
const urlInput = document.getElementById('url-input');
const submitButton = document.getElementById('submitButton');
const buttonText = document.getElementById('buttonText');
const buttonSpinner = document.getElementById('buttonSpinner');
const messageDiv = document.getElementById('messageDiv');
const shareModal = document.getElementById('shareModal');
const closeShareModalBtn = document.getElementById('closeShareModalBtn');
const shareModalContent = document.getElementById('shareModalContent');
const copyLinkBtn = document.getElementById('copyLinkBtn');
const copyLinkText = document.getElementById('copyLinkText');
const copyIcon = document.getElementById('copyIcon');
const checkIcon = document.getElementById('checkIcon');
// --- Share Configuration ---
const shareUrl = 'https://melogabriel.github.io/cookie-scrapper/';
const shareText = encodeURIComponent('Check out this free tool to download website cookies as a CSV!');
const shareTitle = encodeURIComponent('Web Cookie Exporter');
document.getElementById('shareTwitter').href = `https://twitter.com/intent/tweet?url=${shareUrl}&text=${shareText}`;
document.getElementById('shareFacebook').href = `https://www.facebook.com/sharer/sharer.php?u=${shareUrl}`;
document.getElementById('shareLinkedIn').href = `https://www.linkedin.com/shareArticle?mini=true&url=${shareUrl}&title=${shareTitle}&summary=${shareText}`;
document.getElementById('shareWhatsApp').href = `https://api.whatsapp.com/send?text=${shareText}%20${shareUrl}`;
document.getElementById('shareTelegram').href = `https://t.me/share/url?url=${shareUrl}&text=${shareText}`;
document.getElementById('shareMail').href = `mailto:?subject=${shareTitle}&body=${shareText}%20${shareUrl}`;
// --- Modal Functions ---
function openModal() {
shareModal.classList.remove('hidden', 'opacity-0');
shareModalContent.classList.remove('scale-95');
}
function closeModal() {
shareModal.classList.add('opacity-0');
shareModalContent.classList.add('scale-95');
setTimeout(() => {
shareModal.classList.add('hidden');
}, 300);
}
// --- Event Listeners ---
closeShareModalBtn.addEventListener('click', closeModal);
shareModal.addEventListener('click', (event) => {
if (event.target === shareModal) { closeModal(); }
});
copyLinkBtn.addEventListener('click', () => {
const urlToCopy = document.getElementById('shareUrlInput').value;
navigator.clipboard.writeText(urlToCopy).then(() => {
copyLinkText.textContent = 'Copied!';
copyIcon.classList.add('hidden');
checkIcon.classList.remove('hidden');
setTimeout(() => {
copyLinkText.textContent = 'Copy';
copyIcon.classList.remove('hidden');
checkIcon.classList.add('hidden');
}, 2000);
}).catch(err => console.error('Failed to copy text: ', err));
});
// --- Main Form Logic ---
cookieForm.addEventListener('submit', async function(event) {
event.preventDefault();
let url = urlInput.value.trim();
if (url && !url.startsWith('http://') && !url.startsWith('https://')) {
url = 'https://' + url;
urlInput.value = url;
}
submitButton.disabled = true;
buttonText.classList.add('hidden');
buttonSpinner.classList.remove('hidden');
messageDiv.className = 'mt-6 text-center text-sm flex items-center justify-center p-2 border rounded-lg border-blue-200 bg-blue-50 text-blue-800';
messageDiv.innerHTML = '<div class="flex flex-col items-center"><span>Connecting to the server...</span><small class="font-medium">This may take a minute if the server is waking up.</small></div>';
try {
const apiUrl = 'https://cookie-scrapper.onrender.com/scrape';
const response = await fetch(apiUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ url: url })
});
if (response.ok) {
const contentType = response.headers.get("content-type");
if (contentType && contentType.includes("text/csv")) {
messageDiv.className = 'mt-6 text-center text-sm flex items-center justify-center p-2 border rounded-lg border-green-200 bg-green-50 text-green-800';
messageDiv.textContent = 'Success! Your download is starting.';
const blob = await response.blob();
const downloadUrl = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = downloadUrl;
a.download = 'cookies.csv';
document.body.appendChild(a);
a.click();
a.remove();
setTimeout(openModal, 1000);
// Push a custom event to the dataLayer for GTM to capture
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
event: 'file_download'
});
} else {
const result = await response.json();
messageDiv.className = 'mt-6 text-center text-sm flex items-center justify-center p-2 border rounded-lg border-slate-200 bg-slate-50 text-slate-700';
messageDiv.textContent = result.message || 'Received a success response but no file.';
}
} else {
const errorData = await response.json();
messageDiv.className = 'mt-6 text-center text-sm flex items-center justify-center p-2 border rounded-lg border-red-200 bg-red-50 text-red-800';
messageDiv.innerHTML = `<div class="flex flex-col"><strong>Error:</strong> ${errorData.error}</div>`;
}
} catch (error) {
console.error('Fetch error:', error);
messageDiv.className = 'mt-6 text-center text-sm flex items-center justify-center p-2 border rounded-lg border-red-200 bg-red-50 text-red-800';
messageDiv.innerHTML = '<strong>Network Error:</strong> Could not connect. Please try again in a minute.';
} finally {
submitButton.disabled = false;
buttonText.classList.remove('hidden');
buttonSpinner.classList.add('hidden');
}
});
});
</script>
</body>
</html>