-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
272 lines (250 loc) · 10.2 KB
/
script.js
File metadata and controls
272 lines (250 loc) · 10.2 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
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
document.addEventListener('DOMContentLoaded', () => {
// --- Particle Animation ---
const canvas = document.getElementById('particles');
const ctx = canvas.getContext('2d');
let particlesArray = [];
let mouse = { x: null, y: null, radius: 100 };
let currentTheme = localStorage.getItem('theme') || 'default';
// Helper do pobierania właściwości motywu
function getThemeProps(theme) {
switch(theme) {
case 'space':
return {
particleCount: 200,
baseSizeMin: 0.5,
baseSizeMax: 1.5,
speedMin: -0.2,
speedMax: 0.2,
opacityMin: 0.4,
opacityMax: 0.6,
useHue: false,
connectLines: false,
glowEffect: true
};
case 'cyber':
return {
particleCount: 120,
baseSizeMin: 0.8,
baseSizeMax: 2.2,
speedMin: -0.25,
speedMax: 0.25,
opacityMin: 0.5,
opacityMax: 0.9,
useHue: true,
hueMin: 180,
hueMax: 300,
connectLines: true,
lineDistance: 120,
glowEffect: true
};
default: // default
return {
particleCount: 50,
baseSizeMin: 1,
baseSizeMax: 2,
speedMin: -0.15,
speedMax: 0.15,
opacityMin: 0.2,
opacityMax: 0.4,
useHue: true,
hueMin: 200,
hueMax: 230,
connectLines: true,
lineDistance: 100,
glowEffect: false
};
}
}
class Particle {
constructor(themeProps) {
this.themeProps = themeProps;
this.x = Math.random() * canvas.width;
this.y = Math.random() * canvas.height;
this.size = Math.random() * (themeProps.baseSizeMax - themeProps.baseSizeMin) + themeProps.baseSizeMin;
this.baseSize = this.size;
this.speedX = Math.random() * (themeProps.speedMax - themeProps.speedMin) + themeProps.speedMin;
this.speedY = Math.random() * (themeProps.speedMax - themeProps.speedMin) + themeProps.speedMin;
this.opacity = Math.random() * (themeProps.opacityMax - themeProps.opacityMin) + themeProps.opacityMin;
if (themeProps.useHue) {
this.hue = Math.random() * (themeProps.hueMax - themeProps.hueMin) + themeProps.hueMin;
} else {
this.hue = 0; // nieużywane dla space
}
this.glow = themeProps.glowEffect;
}
update(themeProps, mouse) {
this.x += this.speedX;
this.y += this.speedY;
// Spadek rozmiaru/opacity tylko dla domyślnego motywu
if (currentTheme === 'default') {
if (this.size > 0.5) this.size -= 0.003;
if (this.opacity > 0.2) this.opacity -= 0.0003;
}
// Interakcja z myszką tylko dla domyślnego
if (currentTheme === 'default' && mouse.x !== null && mouse.y !== null) {
const dx = mouse.x - this.x;
const dy = mouse.y - this.y;
const distance = Math.sqrt(dx * dx + dy * dy);
if (distance < mouse.radius) {
const force = (mouse.radius - distance) / mouse.radius;
this.speedX += dx * force * 0.01;
this.speedY += dy * force * 0.01;
this.size = this.baseSize + force * 1.5;
}
}
// Odbijanie od krawędzi
if (this.x < 0 || this.x > canvas.width) this.speedX *= -1;
if (this.y < 0 || this.y > canvas.height) this.speedY *= -1;
}
draw(ctx) {
if (this.themeProps.useHue) {
ctx.fillStyle = `hsla(${this.hue}, 70%, 60%, ${this.opacity})`;
} else {
// Dla space: białe cząstki
ctx.fillStyle = `hsla(0, 0%, 100%, ${this.opacity})`;
}
if (this.glow) {
ctx.shadowBlur = 6;
ctx.shadowColor = this.themeProps.useHue ? `hsl(${this.hue}, 80%, 60%)` : 'white';
} else {
ctx.shadowBlur = 0;
}
ctx.beginPath();
ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
ctx.fill();
}
}
function connectParticles(particlesArray, themeProps) {
if (!themeProps.connectLines) return;
const distanceLimit = themeProps.lineDistance || 100;
for (let i = 0; i < particlesArray.length; i++) {
for (let j = i + 1; j < particlesArray.length; j++) {
const dx = particlesArray[i].x - particlesArray[j].x;
const dy = particlesArray[i].y - particlesArray[j].y;
const distance = Math.sqrt(dx * dx + dy * dy);
if (distance < distanceLimit) {
const opacity = (1 - distance / distanceLimit) * 0.2;
if (themeProps.useHue) {
ctx.strokeStyle = `hsla(${particlesArray[i].hue}, 70%, 60%, ${opacity})`;
} else {
ctx.strokeStyle = `rgba(255, 255, 255, ${opacity})`;
}
ctx.lineWidth = 0.5;
ctx.beginPath();
ctx.moveTo(particlesArray[i].x, particlesArray[i].y);
ctx.lineTo(particlesArray[j].x, particlesArray[j].y);
ctx.stroke();
}
}
}
}
function initParticles() {
particlesArray.length = 0;
const themeProps = getThemeProps(currentTheme);
for (let i = 0; i < themeProps.particleCount; i++) {
particlesArray.push(new Particle(themeProps));
}
}
function animateParticles() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
const themeProps = getThemeProps(currentTheme);
for (let i = 0; i < particlesArray.length; i++) {
particlesArray[i].update(themeProps, mouse);
particlesArray[i].draw(ctx);
// Odświeżanie cząstek jeśli za małe (tylko default)
if (currentTheme === 'default' && (particlesArray[i].size <= 0.5 || particlesArray[i].opacity <= 0.2)) {
particlesArray.splice(i, 1);
particlesArray.push(new Particle(themeProps));
i--;
}
}
connectParticles(particlesArray, themeProps);
requestAnimationFrame(animateParticles);
}
// Obsługa rozmiaru okna
function handleResize() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
initParticles();
}
// --- Theme Toggle (3 motywy) ---
const themeToggle = document.getElementById('themeToggle');
const themes = ['default', 'space', 'cyber'];
function applyTheme(theme) {
currentTheme = theme;
document.body.classList.remove('space-theme', 'cyber-theme');
if (theme === 'space') {
document.body.classList.add('space-theme');
} else if (theme === 'cyber') {
document.body.classList.add('cyber-theme');
}
initParticles();
localStorage.setItem('theme', theme);
}
themeToggle.addEventListener('click', () => {
let nextIndex = (themes.indexOf(currentTheme) + 1) % themes.length;
applyTheme(themes[nextIndex]);
});
// --- Mouse tracking dla interakcji (tylko domyślny motyw) ---
document.addEventListener('mousemove', (e) => {
mouse.x = e.clientX;
mouse.y = e.clientY;
});
document.addEventListener('mouseout', () => {
mouse.x = null;
mouse.y = null;
});
window.addEventListener('resize', handleResize);
// Inicjalizacja
if (ctx) {
handleResize();
applyTheme(currentTheme);
animateParticles();
} else {
console.warn('Canvas not supported');
}
// --- Form validation ---
const searchForm = document.querySelector('.search-form');
const input = document.querySelector('.search-input');
if (searchForm) {
searchForm.addEventListener('submit', function(e) {
const query = input.value.trim();
if (!query) {
e.preventDefault();
alert('Proszę wpisać frazę wyszukiwania!');
}
});
}
// --- Keyboard accessibility ---
if (input) {
document.addEventListener('keydown', (e) => {
if (e.key === 'Enter' && document.activeElement !== input) {
input.focus();
}
});
}
// --- Language detection ---
const userLang = navigator.language || navigator.userLanguage;
if (!userLang.startsWith('pl')) {
document.documentElement.lang = 'en';
if (input) input.placeholder = 'Search with Ecosia...';
const footer = document.querySelector('footer');
if (footer) {
footer.innerHTML = `
Powered by <a href="https://www.ecosia.org" target="_blank" aria-label="Ecosia Website">Ecosia</a> |
<a href="https://hackeros-linux-system.github.io/HackerOS-Website/" target="_blank" aria-label="HackerOS Website">HackerOS</a> | © 2026
`;
}
// Uwaga: link w bottom-left-link jest już zmieniony statycznie w HTML, ale tekst pozostawiamy angielski
const bottomLeftLink = document.querySelector('.bottom-left-link a');
if (bottomLeftLink && bottomLeftLink.textContent === 'Odkryj nasz ekosystem') {
bottomLeftLink.textContent = 'Discover our ecosystem';
}
} else {
document.documentElement.lang = 'pl';
const bottomLeftLink = document.querySelector('.bottom-left-link a');
if (bottomLeftLink && bottomLeftLink.textContent === 'Discover our ecosystem') {
bottomLeftLink.textContent = 'Odkryj nasz ekosystem';
}
}
});