-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
169 lines (134 loc) · 6.07 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
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
const animations = [
{ elements: '.bg h1, .bg p', animationClass: 'bg-ani' },
{ elements: '.navbar .navigation a', animationClass: 'navbar-ani' },
{ elements: '.content .header h1, .content .header h2, .content .header p', animationClass: ['header-ani-right', 'header-ani-left'] },
{ elements: '.FAQ p', animationClass: 'question-anim' },
{ elements: '.FAQ h3', animationClass: 'centred-h3-anim' }
];
document.addEventListener('DOMContentLoaded', function() {
//setupObservers();
});
document.getElementById('loginForm').addEventListener('submit', function(event) {
const username = document.getElementById('username').value;
const password = document.getElementById('password').value;
// Basic validation criteria
if (username === '' || password === '') {
alert('Both username and password are required.');
event.preventDefault(); // Prevent form submission
} else if (password.length < 3) {
alert('Password must be at least 3 characters long.');
event.preventDefault(); // Prevent form submission
} else if (username === 'admin' && password === 'admin') {
alert('Login successful as admin!');
event.preventDefault(); // Prevent form submission
}else if (username === 'user' && password === 'user') {
alert('Successful login, dear User!');
event.preventDefault(); // Prevent form submission
} else {
alert('Invalid username or password.');
event.preventDefault(); // Prevent form submission
}
});
function setupObservers() {
const options = {
root: null,
threshold: 0.1
};
// Helper function to create observers with animation classes
function createObserver(elementsSelector, animationClass) {
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry, index) => {
if (entry.isIntersecting) {
setTimeout(() => {
entry.target.classList.add(animationClass);
observer.unobserve(entry.target);
}, index * 500);
}
});
}, options);
document.querySelectorAll(elementsSelector).forEach(el => observer.observe(el));
}
// Apply observers
createObserver('.bg h1, .bg p', 'bg-ani');
createObserver('.navbar .navigation a', 'navbar-ani');
// Header observer with alternating animation
createObserver('.content .header h1, .content .header h2, .content .header p',
(index) => index % 2 === 0 ? 'header-ani-left' : 'header-ani-right');
// Commented-out sections (you can activate them similarly)
// createObserver('.FAQ p', 'question-anim');
createObserver('.FAQ h3', 'centred-h3-anim');
}
document.addEventListener('DOMContentLoaded', function() {
const bgElement = document.querySelector('.bg');
let x1 = 94.35, y1 = 89.61, x2 = 6.50, y2 = 88.03, x3 = 6.16, y3 = 12.61, x4 = 93.68, y4 = 11.42; // Initial positions
function updateBackground() {
// Update positions with a small, smooth change
x1 = (x1 + (Math.random()) * 0.15) % 500;
y1 = (y1 + (Math.random()) * 0.15) % 500;
x2 = (x2 + (Math.random()) * 0.15) % 500;
y2 = (y2 + (Math.random()) * 0.15) % 500;
x3 = (x3 + (Math.random()) * 0.15) % 500;
y3 = (y3 + (Math.random()) * 0.15) % 500;
x4 = (x4 + (Math.random()) * 0.15) % 500;
y4 = (y4 + (Math.random()) * 0.15) % 500;
// Apply new background style
bgElement.style.background = `radial-gradient(circle at ${x1}% ${y1}%, #83A8F0 0%, 20%, rgba(131,168,240,0) 40%), radial-gradient(circle at ${x2}% ${y2}%, rgba(200,238,245,0.99) 0%, 25%, rgba(200,238,245,0) 50%), radial-gradient(circle at ${x3}% ${y3}%, #155DE9 0%, 42%, rgba(21,93,233,0) 70%), radial-gradient(circle at ${x4}% ${y4}%, #E3E3E3 0%, 42%, rgba(227,227,227,0) 70%), radial-gradient(circle at 48.90% 49.52%, #808080 0%, 100%, rgba(128,128,128,0) 100%)`;
requestAnimationFrame(updateBackground);
}
// Start the animation
requestAnimationFrame(updateBackground);
let textarea = document.getElementById("savedSearches");
textarea.addEventListener('keydown', function(event) {
if (event.key === 'Enter') {
event.preventDefault(); // Prevents the default action of the Enter key
getTextFromTextarea();
}
});
});
async function testGPTReq(apiKey, message, maxTokens = 50, model = "gpt-3.5-turbo-1106") {
const response = await fetch("https://api.openai.com/v1/chat/completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${apiKey}`
},
body: JSON.stringify({
model: model,
messages: message,
max_tokens: 10
})
});
const data = await response.json();
console.log(data.choices[0].message.content);
return data;
}
let switcer = true;
messages = [];
function getTextFromTextarea() {
let textarea = document.getElementById("savedSearches");
let text = textarea.value;
textarea.value = "";
const UserAnswerH3 = document.createElement("h3");
UserAnswerH3.textContent = "User:";
messages.push({role: "user", content: text});
let response = testGPTReq("your api key", messages);
if (switcer){
let element = document.getElementById('placeHolderConversation');
element.remove();
switcer = false;
}
let Div = document.querySelector(".law");
Div.appendChild(UserAnswerH3);
let newParagraph = document.createElement("p");
newParagraph.textContent = text;
Div.appendChild(newParagraph);
response.then(data => {
let newParagraph = document.createElement("p");
newParagraph.textContent = data.choices[0].message.content;
messages.push({role: "assistant", content: data.choices[0].message.content});
const aiAnswerH3 = document.createElement("h3");
aiAnswerH3.textContent = "AI's answer:";
Div.appendChild(aiAnswerH3);
Div.appendChild(newParagraph);
});
}