Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
108 lines (94 loc) · 3.4 KB
/
Copy pathscript.js
File metadata and controls
108 lines (94 loc) · 3.4 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
// Get all "Get Early Access" buttons
const ctaButtons = document.querySelectorAll('button');
const modalOverlay = document.getElementById('waitlistModal');
const closeButton = document.getElementById('closeModal');
const waitlistForm = document.getElementById('waitlistForm');
// Filter buttons that contain "Get Early Access" text
const earlyAccessButtons = Array.from(ctaButtons).filter(button =>
button.textContent.includes('Get Early Access')
);
// Add click event listeners to all "Get Early Access" buttons
earlyAccessButtons.forEach(button => {
button.addEventListener('click', (e) => {
e.preventDefault();
modalOverlay.classList.add('is-open');
});
});
// Close modal when close button is clicked
closeButton.addEventListener('click', () => {
modalOverlay.classList.remove('is-open');
});
// Close modal when overlay background is clicked
modalOverlay.addEventListener('click', (e) => {
if (e.target === modalOverlay) {
modalOverlay.classList.remove('is-open');
}
});
// Handle email validation
function isValidEmail(email) {
// Simple RFC 5322 compliant regex for most emails
const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return re.test(email);
}
/*
// Handle email spam
function isSpamSubmission(form) {
// Honeypot: hidden field should be empty if human
const honeypot = form.querySelector('.honeypot');
if (honeypot && honeypot.value) return true;
// Simple rate limiting: allow only 1 submit per 30 seconds per session
const lastSubmit = sessionStorage.getItem('waitlist_last_submit');
const now = Date.now();
if (lastSubmit && now - lastSubmit < 30000) return true;
sessionStorage.setItem('waitlist_last_submit', now);
return false;
}
*/
// Handle form submission
waitlistForm.addEventListener('submit', (e) => {
e.preventDefault();
const emailInput = waitlistForm.querySelector('.email-input');
const submitButton = waitlistForm.querySelector('.submit-button');
const email = emailInput.value;
// Validation
if (!isValidEmail(email)) {
alert('Please enter a valid email address.');
return;
}
/*
// Spam Protection
if (isSpamSubmission(waitlistForm)) {
alert('Submission blocked as spam or too frequent. Please try again later.');
return;
}
*/
// Optimistic UI: Immediately perform success actions
modalOverlay.classList.remove('is-open');
alert('Thank you! You\'ve been added to the waitlist.');
emailInput.value = '';
submitButton.disabled = false;
submitButton.textContent = 'Submit';
submitButton.classList.remove('is-submitting');
// Send data to Google Sheet in the background
const scriptURL = 'https://script.google.com/macros/s/AKfycbzXRh4_cwawakpF1doqL8ot19m99-CTGWlaVA9PX_vYuijjdsbSy4qOSBXNLNMzzQ9PRQ/exec';
fetch(scriptURL, {
method: 'POST',
mode: 'no-cors',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: new URLSearchParams({ email })
})
.then(() => {
console.log('Success: Email sent to Google Sheet');
})
.catch((error) => {
console.error('Background error sending email to sheet:', error.message);
});
});
// Close modal with Escape key
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape' && modalOverlay.classList.contains('is-open')) {
modalOverlay.classList.remove('is-open');
}
});