diff --git a/.vscode/settings.json b/.vscode/settings.json index 6f3a291..f673a71 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,3 @@ { - "liveServer.settings.port": 5501 + "liveServer.settings.port": 5502 } \ No newline at end of file diff --git a/hihi/answer.txt b/hihi/answer.txt new file mode 100644 index 0000000..dcd7a5d --- /dev/null +++ b/hihi/answer.txt @@ -0,0 +1 @@ +Yes diff --git a/hihi/backend.js b/hihi/backend.js index ea5abb0..0cd8d1a 100644 --- a/hihi/backend.js +++ b/hihi/backend.js @@ -1,20 +1,27 @@ const express = require('express'); -const fs = require('fs'); +const cors = require('cors'); +const writeFileAtomic = require('write-file-atomic'); const app = express(); +const port = 3000; +app.use(cors()); app.use(express.json()); app.post('/save_answer', (req, res) => { const answer = req.body.answer; - fs.writeFile('answer.txt', answer, err => { + console.log(`Received answer: ${answer}`); // Print the received answer + + writeFileAtomic('answer.txt', `${answer}\n`, { encoding: 'utf8', mode: 0o600 }, function (err) { if (err) { - console.error(err); - res.status(500).send('An error occurred while writing the answer to a file.'); + console.error(`Error writing to file: ${err}`); // Print the error + res.status(500).json({ message: 'Error writing to file' }); } else { - console.log('Answer saved to file.'); - res.status(200).send('Answer saved to file.'); + console.log('Saved!'); + res.status(200).json({ message: 'Answer saved' }); } }); }); -app.listen(3000, () => console.log('Server listening on port 3000.')); \ No newline at end of file +app.listen(port, () => { + console.log(`Server listening at http://localhost:${port}`); +}); \ No newline at end of file diff --git a/hihi/cat.gif b/hihi/cat.gif new file mode 100644 index 0000000..c2777fa Binary files /dev/null and b/hihi/cat.gif differ diff --git a/hihi/index.html b/hihi/index.html index 76f7aea..a797ff3 100644 --- a/hihi/index.html +++ b/hihi/index.html @@ -1,27 +1,24 @@ -
Valentine's Date -
- + -
-

Will you be my Valentine?

-
- -
-

Dear Leonie,

-

I wanted to ask you something very special...

-

Will you be my Valentine?

- - -
- - + +
+
+

Dear Leonie,

+

I wanted to ask you something very special...

+

Will you be my Valentine?

+ + +
+ + +
\ No newline at end of file diff --git a/hihi/sarlah-sarlahthecat.gif b/hihi/sarlah-sarlahthecat.gif new file mode 100644 index 0000000..d883a40 Binary files /dev/null and b/hihi/sarlah-sarlahthecat.gif differ diff --git a/hihi/script.js b/hihi/script.js index 1c3ab38..2f537f3 100644 --- a/hihi/script.js +++ b/hihi/script.js @@ -1,47 +1,46 @@ -window.onload = function() { +document.addEventListener('DOMContentLoaded', function() { + var yesButton = document.getElementById('yesButton'); + var noButton = document.getElementById('noButton'); + + yesButton.style.cursor = 'pointer'; + noButton.style.cursor = 'pointer'; + function sendAnswer(answer) { + fetch('http://localhost:3000/save_answer', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ answer: answer }), + }) + .then(response => { + console.log(response); + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + return response.json(); + }) + .then(data => console.log('Success:', data)) + .catch((error) => console.error('Error:', error)); + } + document.getElementById('yesButton').addEventListener('click', function() { + console.log('Yes button clicked'); sendAnswer('Yes'); // Change the title - document.getElementById('title').textContent = 'Yippie!!'; - - // Embed the Tenor GIF - var gifEmbed = document.createElement('div'); - gifEmbed.innerHTML = ` -
- Yippee Cat GIFfrom - Yippee GIFs -
- - `; - document.body.appendChild(gifEmbed); + document.getElementById('message').textContent = 'Yippie!!'; + var image = document.getElementById('image'); + image.src = 'cat.gif'; + image.style.display = 'block'; }); document.getElementById('noButton').addEventListener('click', function() { sendAnswer('No'); - // Change the title - document.getElementById('title').textContent = 'No button is just for show'; // Replace 'New Title' with your actual title - - // Remove the "No" button + document.getElementById('message').textContent = 'No button is just for show'; var noButton = document.getElementById('noButton'); noButton.parentNode.removeChild(noButton); - - // Display the image var image = document.getElementById('image'); - image.src = 'https://www.reddit.com/media?url=https%253A%252F%252Fi.redd.it%252F4kcezfmr06s41.png%0'; // Replace 'image.jpg' with the path to your image + image.src = 'sarlah-sarlahthecat.gif'; image.style.display = 'block'; }); - - function sendAnswer(answer) { - fetch('http://loaclhost:3000/hihi/save_answer', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ answer: answer }), - }) - .then(response => response.json()) - .then(data => console.log('Success:', data)) - .catch((error) => console.error('Error:', error)); - } -} \ No newline at end of file +}); \ No newline at end of file diff --git a/hihi/styles.css b/hihi/styles.css index 3036911..1b4f17e 100644 --- a/hihi/styles.css +++ b/hihi/styles.css @@ -46,10 +46,12 @@ body { cursor: pointer; text-decoration: none; transition: all 0.3s ease-out; + cursor: pointer; } .button:hover { background: #ff4500; + cursor: pointer; } #yesButton, #noButton { @@ -58,21 +60,12 @@ body { min-height: 50px; } - - -.title { - font-size: 3em; - color: white; - text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5); - position: absolute; - top: 20px; - left: 20px; - right: 20px; - bottom: 20px; - text-align: center; - margin-top: 600px; +#yesButton:hover, #noButton:hover { + background: #ff4500; + cursor: pointer; } + .footer { position: absolute; bottom: 20px;