forked from GarimaSingh0109/Resum-Resume
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
96 lines (73 loc) · 2.58 KB
/
script.js
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
const toggleSwitch = document.getElementById('dark-mode-toggle');
// Check for saved user preference in local storage
const currentTheme = localStorage.getItem('theme') ? localStorage.getItem('theme') : null;
if (currentTheme) {
document.body.classList.toggle('dark-mode', currentTheme === 'dark');
toggleSwitch.checked = currentTheme === 'dark';
}
toggleSwitch.addEventListener('change', () => {
document.body.classList.toggle('dark-mode');
// Save preference to local storage
if (document.body.classList.contains('dark-mode')) {
localStorage.setItem('theme', 'dark');
} else {
localStorage.setItem('theme', 'light');
}
});
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const app = express();
const PORT = 3000;
let comments = [];
app.use(cors());
app.use(bodyParser.json());
app.get('/comments', (req, res) => {
res.json(comments);
});
app.post('/comments', (req, res) => {
const newComment = req.body.comment;
comments.push(newComment);
res.status(201).json(newComment);
});
app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});
document.addEventListener('DOMContentLoaded', () => {
const commentForm = document.getElementById('comment-form');
const commentInput = document.getElementById('comment-input');
const commentsDiv = document.getElementById('comments');
// Load comments from the server
fetch('http://localhost:3000/comments')
.then(response => response.json())
.then(comments => {
comments.forEach(comment => {
const div = document.createElement('div');
div.textContent = comment;
commentsDiv.appendChild(div);
});
});
// Handle form submission
commentForm.addEventListener('submit', (e) => {
e.preventDefault();
const comment = commentInput.value;
fetch('http://localhost:3000/comments', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ comment })
})
.then(response => response.json())
.then(newComment => {
const div = document.createElement('div');
div.textContent = newComment;
commentsDiv.appendChild(div);
commentInput.value = ''; // Clear the input
});
});
});
// var typed = new Typed('#newlogo', {
// strings: ['EnhanCV.'],
// typeSpeed: 50,
// });