@@ -95,85 +95,85 @@ document.addEventListener('DOMContentLoaded', () => {
9595} ) ;
9696
9797// submission box
98- document . addEventListener ( 'DOMContentLoaded' , function ( ) {
99- const submitButton = document . getElementById ( 'submitButton' ) ;
100- if ( submitButton ) {
101- submitButton . addEventListener ( 'click' , submitEmail ) ;
102- emailInput . addEventListener ( 'keydown' , function ( event ) {
103- if ( event . key === 'Enter' ) {
104- event . preventDefault ( ) ;
105- submitButton . click ( ) ;
106- }
107- } ) ;
108- } ;
109- } ) ;
110-
111- function validateEmail ( email ) {
112- const re = / ^ .+ @ .+ \. .+ $ / ;
113- return re . test ( email . toLowerCase ( ) ) ;
114- }
115-
116- function showMessage ( text , isError = false ) {
117- const messageDiv = document . getElementById ( 'message' ) ;
118- messageDiv . textContent = text ;
119- messageDiv . style . display = 'block' ;
120- messageDiv . className = `message ${ isError ? 'error' : 'success' } ` ;
121- }
122-
123- function submitEmail ( ) {
124- const emailInput = document . getElementById ( 'emailInput' ) ;
125- const submitButton = document . getElementById ( 'submitButton' ) ;
126- const email = emailInput . value . trim ( ) ;
127-
128- if ( ! validateEmail ( email ) ) {
129- showMessage ( 'Please enter a valid email address' , true ) ;
130- return ;
131- }
132-
133- submitButton . disabled = true ;
98+ // document.addEventListener('DOMContentLoaded', function() {
99+ // const submitButton = document.getElementById('submitButton');
100+ // if (submitButton) {
101+ // submitButton.addEventListener('click', submitEmail);
102+ // emailInput.addEventListener('keydown', function (event) {
103+ // if (event.key === 'Enter') {
104+ // event.preventDefault();
105+ // submitButton.click();
106+ // }
107+ // });
108+ // };
109+ // });
110+
111+ // function validateEmail(email) {
112+ // const re = /^.+@.+\..+$/;
113+ // return re.test(email.toLowerCase());
114+ // }
115+
116+ // function showMessage(text, isError = false) {
117+ // const messageDiv = document.getElementById('message');
118+ // messageDiv.textContent = text;
119+ // messageDiv.style.display = 'block';
120+ // messageDiv.className = `message ${isError ? 'error' : 'success'}`;
121+ // }
122+
123+ // function submitEmail() {
124+ // const emailInput = document.getElementById('emailInput');
125+ // const submitButton = document.getElementById('submitButton');
126+ // const email = emailInput.value.trim();
127+
128+ // if (!validateEmail(email)) {
129+ // showMessage('Please enter a valid email address', true);
130+ // return;
131+ // }
132+
133+ // submitButton.disabled = true;
134134
135- // Replace this URL with your Google Apps Script web app URL
136- const googleAppScriptUrl = 'https://script.google.com/macros/s/AKfycbwiGxv02KdERUK68Gaf80V0BUlMGNyyrhVJPHTj72HRXxkAKoRUw7D8zS7Wr4mTlivn/exec' ;
135+ // // Replace this URL with your Google Apps Script web app URL
136+ // const googleAppScriptUrl = 'https://script.google.com/macros/s/AKfycbwiGxv02KdERUK68Gaf80V0BUlMGNyyrhVJPHTj72HRXxkAKoRUw7D8zS7Wr4mTlivn/exec';
137137
138- // Security check: ensure scriptUrl and hostname pair is valid to make sure other deployments do not use the same url
139- const currentHostname = window . location . hostname ;
140- const isLocalhost = currentHostname === 'localhost' || currentHostname === '127.0.0.1' ;
141- const isOriginalSite = currentHostname === 'oliver.hausdoerfer.de' ;
142- const originalScriptUrl = 'https://script.google.com/macros/s/AKfycbwiGxv02KdERUK68Gaf80V0BUlMGNyyrhVJPHTj72HRXxkAKoRUw7D8zS7Wr4mTlivn/exec'
143-
144- const isValidConfig = isLocalhost ||
145- ( isOriginalSite && googleAppScriptUrl === originalScriptUrl ) ||
146- ( ! isOriginalSite && googleAppScriptUrl !== originalScriptUrl ) ;
138+ // // Security check: ensure scriptUrl and hostname pair is valid to make sure other deployments do not use the same url
139+ // const currentHostname = window.location.hostname;
140+ // const isLocalhost = currentHostname === 'localhost' || currentHostname === '127.0.0.1';
141+ // const isOriginalSite = currentHostname === 'oliver.hausdoerfer.de';
142+ // const originalScriptUrl = 'https://script.google.com/macros/s/AKfycbwiGxv02KdERUK68Gaf80V0BUlMGNyyrhVJPHTj72HRXxkAKoRUw7D8zS7Wr4mTlivn/exec'
143+
144+ // const isValidConfig = isLocalhost ||
145+ // (isOriginalSite && googleAppScriptUrl === originalScriptUrl) ||
146+ // (!isOriginalSite && googleAppScriptUrl !== originalScriptUrl);
147147
148- if ( ! isValidConfig ) {
149- console . log ( 'Invalid scriptUrl. Please update the scriptUrl in this js file.' ) ;
150- showMessage ( 'An error occurred. Please try again later.' , true ) ;
151- submitButton . disabled = false ;
152- return ;
153- }
154-
155- fetch ( googleAppScriptUrl , {
156- method : 'POST' ,
157- mode : 'no-cors' , // This is critical for avoiding CORS issues with Google Apps Script
158- headers : {
159- 'Content-Type' : 'application/json' ,
160- } ,
161- body : JSON . stringify ( {
162- email : email ,
163- origin : window . location . origin
164- } )
165- } )
166- . then ( response => {
167- console . log ( response )
168- // With no-cors mode, we can't read the response, so we assume success
169- showMessage ( "You'll stay up-to-date with my research!" ) ;
170- emailInput . value = '' ;
171- } )
172- . catch ( error => {
173- showMessage ( 'An error occurred. Please try again later.' , true ) ;
174- console . error ( 'Error:' , error ) ;
175- } )
176- . finally ( ( ) => {
177- submitButton . disabled = false ;
178- } ) ;
179- }
148+ // if (!isValidConfig) {
149+ // console.log('Invalid scriptUrl. Please update the scriptUrl in this js file.');
150+ // showMessage('An error occurred. Please try again later.', true);
151+ // submitButton.disabled = false;
152+ // return;
153+ // }
154+
155+ // fetch(googleAppScriptUrl, {
156+ // method: 'POST',
157+ // mode: 'no-cors', // This is critical for avoiding CORS issues with Google Apps Script
158+ // headers: {
159+ // 'Content-Type': 'application/json',
160+ // },
161+ // body: JSON.stringify({
162+ // email: email,
163+ // origin: window.location.origin
164+ // })
165+ // })
166+ // .then(response => {
167+ // console.log(response)
168+ // // With no-cors mode, we can't read the response, so we assume success
169+ // showMessage("You'll stay up-to-date with my research!");
170+ // emailInput.value = '';
171+ // })
172+ // .catch(error => {
173+ // showMessage('An error occurred. Please try again later.', true);
174+ // console.error('Error:', error);
175+ // })
176+ // .finally(() => {
177+ // submitButton.disabled = false;
178+ // });
179+ // }
0 commit comments