-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathportfolio2.html
952 lines (819 loc) · 29.5 KB
/
portfolio2.html
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="icon" href="picture.png" type="image/png">
<title>Portfolio / Professional Landing Page</title>
<style>
body, html {
margin: 0;
padding: 0;
height: 100%;
display: flex;
flex-direction: column;
justify-content: space-between;
font-family: 'Ubuntu', sans-serif;
background-color: #2d2d2d;
color: white;
}
/* Header and Footer Styling */
header, footer {
background-color: #1f1f1f;
padding: 15px;
text-align: center;
font-size: 1.2rem;
}
/* General Styles */
section {
padding: 2rem;
}
section h2 {
margin-top: 0;
}
/* General Link Styles */
a {
text-decoration: none; /* Removes the underline */
color: #0078D7; /* Professional blue color */
font-weight: 500; /* Semi-bold for better readability */
transition: color 0.3s ease, text-shadow 0.3s ease; /* Smooth hover effects */
}
/* Hover State */
a:hover {
color: #0056A3; /* Darker blue for hover */
text-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); /* Adds subtle depth */
}
/* Focus State for Accessibility */
a:focus {
outline: 2px dashed #0056A3; /* Focus ring for keyboard users */
outline-offset: 2px;
}
/* Active State */
a:active {
color: #003F7D; /* Even darker blue for active state */
text-shadow: 0 0 3px rgba(0, 0, 0, 0.4); /* Subtle glow on active */
}
/* General List Styles */
ul {
list-style: none; /* Removes default list bullets */
padding: 0; /* Removes default padding */
margin: 0; /* Removes default margin */
}
li {
font-size: 16px; /* Standard font size */
line-height: 1.6; /* Ensures text is comfortably spaced */
color: #333; /* Dark text color for readability */
padding: 8px 0; /* Vertical padding for spacing between items */
transition: color 0.3s ease, background-color 0.3s ease; /* Smooth transitions */
}
/* Hover State for List Items */
li:hover {
color: #0056A3; /* Changes text color on hover */
background-color: #f0f0f0; /* Subtle background color change on hover */
}
/* Active State for List Items */
li:active {
color: #003F7D; /* Darker color on click */
background-color: #e0e0e0; /* Slightly darker background on click */
}
/* Focus State for Accessibility */
li:focus {
outline: 2px dashed #0056A3; /* Focus ring for accessibility */
outline-offset: 2px;
}
/* Optional: Add Custom Styling for Nested Lists */
ul ul {
padding-left: 20px; /* Indentation for nested lists */
}
#contact-form {
display: flex;
flex-direction: column;
}
#contact-form label,
#contact-form input,
#contact-form textarea {
margin-bottom: 1rem;
}
#contact-form button {
align-self: flex-end;
}
/* Toggle Translate */
.flag-fr, .flag-en {
display: none;
}
.active-fr .flag-fr {
display: inline;
}
.active-en .flag-en {
display: inline;
}
.toggle-button {
cursor: pointer;
padding: 10px;
background-color: #007BFF;
color: white;
border: none;
border-radius: 5px;
transition: background-color 0.3s ease;
}
.toggle-button:hover {
background-color: #0056b3;
}
/* Contact form */
.spinner {
display: inline-block;
width: 12px;
height: 12px;
border: 2px solid transparent;
border-top-color: #3498db;
border-radius: 50%;
animation: spin 0.8s linear infinite;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
/* Container Styling */
.container {
text-align: center;
width: 80%;
max-width: 1000px;
margin: 0 auto;
flex-grow: 1;
display: flex;
flex-direction: column;
justify-content: center;
}
/* Chatbot Terminal Styling */
.chatbot {
width: 100%;
max-width: 800px;
background-color: #000;
color: #33ff33;
border-radius: 8px;
padding: 20px;
margin: 20px auto 40px;
font-family: monospace;
text-align: left;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
transition: background-color 0.3s ease, color 0.3s ease;
}
.chatbot .terminal-output {
height: 200px;
overflow-y: auto;
border-bottom: 2px solid #33ff33;
padding: 10px;
word-wrap: break-word;
white-space: pre-wrap;
transition: border-color 0.3s ease;
}
.chatbot .terminal-output:hover {
border-color: #00ff99;
color: white;
}
/* Custom scrollbar for better aesthetics */
.chatbot .terminal-output::-webkit-scrollbar {
width: 8px;
}
.chatbot .terminal-output::-webkit-scrollbar-thumb {
background-color: #33ff33;
border-radius: 8px;
}
.chatbot .loading-animation {
display: flex;
justify-content: flex-start;
align-items: center;
padding: 5px 0;
font-size: 1.2rem;
transition: color 0.3s ease;
}
.loading-animation:hover {
color: #00ff99;
}
/* Loading Animation */
.loading-animation span {
display: inline-block;
width: 8px;
height: 8px;
background-color: #33ff33;
border-radius: 50%;
margin-right: 5px;
animation: blink 1.2s infinite both;
transition: background-color 0.3s ease;
}
.loading-animation:hover span {
background-color: #00ff99;
}
.loading-animation span:nth-child(2) {
animation-delay: 0.2s;
}
.loading-animation span:nth-child(3) {
animation-delay: 0.4s;
}
@keyframes blink {
0%, 100% {
opacity: 0;
}
50% {
opacity: 1;
}
}
/* Glowing effect on hover */
.chatbot:hover {
box-shadow: 0 0 20px rgba(0, 255, 153, 0.8);
}
/* Container for progress */
.progress-container {
width: 100%;
max-width: 400px;
margin: 50px auto;
text-align: center;
}
/* Keep the class name consistent */
.under-construction-image {
width: 100%;
height: 30px;
border-radius: 10px;
appearance: none;
background-color: #ddd;
position: relative;
overflow: hidden;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
}
/* Energy effect and transition */
progress[value]::-webkit-progress-value {
background-color: #4caf50;
transition: width 0.5s ease-out;
}
progress[value]::-moz-progress-bar {
background-color: #4caf50;
transition: width 0.5s ease-out;
}
/* Glowing effect using math functions */
.energy-effect {
animation: energyPulse 2s infinite;
border-radius: 10px;
box-shadow: 0 0 15px rgba(76, 175, 80, 0.6);
}
@keyframes energyPulse {
0% {
box-shadow: 0 0 10px rgba(76, 175, 80, 0.2);
}
50% {
box-shadow: 0 0 20px rgba(76, 255, 3, 0.8);
}
100% {
box-shadow: 0 0 10px rgba(76, 175, 80, 0.2);
}
}
/* Progress label */
.progress-label {
font-size: 1.4em;
margin-bottom: 15px;
color: #333;
}
/* Text Styling */
.centered-text {
font-size: 3rem;
font-weight: bold;
text-shadow: 2px 2px 6px rgba(0, 0, 0, 0.5);
color: #ffffff;
margin-bottom: 20px;
}
/* Button Styling */
.action-button {
margin-top: 20px;
padding: 15px 30px;
background-color: #4CAF50;
color: white;
font-size: 1.2rem;
font-weight: bold;
text-decoration: none;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
transition: background-color 0.3s ease;
display: inline-block;
}
.action-button:hover {
background-color: #45a049;
}
/* Responsive Design */
@media screen and (max-width: 768px) {
.centered-text {
font-size: 2rem;
}
.action-button {
font-size: 1rem;
padding: 10px 20px;
}
}
/* Accessibility Enhancements */
.action-button:focus {
outline: 2px dashed #ffeb3b;
outline-offset: 4px;
}
/* Improved Responsiveness for Larger Screens */
@media screen and (min-width: 1200px) {
.container {
max-width: 1200px;
}
.under-construction-image {
max-width: 1200px;
}
}
</style>
</head>
<body class="active-en">
<!-- Header -->
<style>
@keyframes matrixRain {
0% {
transform: translateY(-100%);
opacity: 0.2;
}
50% {
opacity: 1;
transform: translateY(0%);
}
100% {
transform: translateY(100%);
opacity: 0.2;
}
}
@keyframes characterChange {
0%, 100% {
content: attr(data-text);
}
10% {
content: "A";
}
20% {
content: "B";
}
30% {
content: "3";
}
40% {
content: "7";
}
50% {
content: "X";
}
60% {
content: "2";
}
70% {
content: "P";
}
80% {
content: "9";
}
90% {
content: "L";
}
}
/* Matrix effect applied to text */
.matrix-text {
position: relative;
color: #00ff00;
overflow: hidden;
}
/* Layer of constantly falling characters (background) */
.matrix-text::before {
content: attr(data-text);
position: absolute;
top: 0;
left: 0;
color: rgba(0, 255, 0, 0.2);
white-space: nowrap;
animation: matrixRain 5s infinite linear;
}
/* Layer of changing characters (foreground) */
.matrix-text span {
display: inline-block;
position: relative;
color: #00ff00;
animation: matrixRain 5s infinite linear, characterChange 1.5s infinite;
}
/* Delays for individual characters */
.matrix-text span:nth-child(1) {
animation-delay: 0s;
}
.matrix-text span:nth-child(2) {
animation-delay: 0.1s;
}
.matrix-text span:nth-child(3) {
animation-delay: 0.2s;
}
.matrix-text span:nth-child(4) {
animation-delay: 0.3s;
}
.matrix-text span:nth-child(5) {
animation-delay: 0.4s;
}
.matrix-text span:nth-child(6) {
animation-delay: 0.5s;
}
.matrix-text span:nth-child(7) {
animation-delay: 0.6s;
}
.matrix-text span:nth-child(8) {
animation-delay: 0.7s;
}
.matrix-text span:nth-child(9) {
animation-delay: 0.8s;
}
.matrix-text span:nth-child(10) {
animation-delay: 0.9s;
}
/* Ensure readability and smooth transitions */
.matrix-text:hover {
color: #00ff99;
}
/* Responsive adjustments */
@media (max-width: 768px) {
.matrix-text {
font-size: 1.5rem;
}
}
</style>
<script>
document.querySelectorAll('.matrix-text span').forEach((element) => {
const originalText = element.textContent;
element.setAttribute('data-text', originalText);
});
</script>
<header>
<h1 style="font-family: monospace; color: #00ff00; overflow: hidden; position: relative;">
<span class="matrix-text" style="display: inline-block;">
<span class="flag-fr">Port</span>
<span class="flag-en">folio</span>
</span>
</h1>
<h3>Welcome to My Professional Landing Page</h3>
<nav style="display: flex; justify-content: space-between; align-items: center; padding: 10px; background-color: #f8f9fa; font-family: Arial, sans-serif;" aria-label="Main Navigation">
<!-- Toggle Language Button -->
<button id="language-toggle" aria-label="Toggle Language" style="border: 2px solid #ccc; background-color: transparent; font-size: 16px; padding: 5px 10px; cursor: pointer; border-radius: 5px;">
🇫🇷 Français / 🇬🇧 English
</button>
<!-- Links List -->
<ul style="list-style: none; margin: 0; padding: 0; display: flex; align-items: center;">
<li><a href="#about">About</a></li>
<li><a href="#services">Services</a></li>
<li><a href="#contact">Contact</a></li>
<li style="margin-left: 20px;">
<a href="https://kvnbbg.fr" target="_blank" aria-label="Look at my links" style="text-decoration: none; font-size: 16px; display: inline-flex; align-items: center; color: #007bff; border: 2px solid transparent; padding: 5px 10px; border-radius: 5px; transition: all 0.3s ease;">
<span class="flag-fr" style="display: block; margin-right: 5px;">Voir Plus</span>
<span class="flag-en" style="display: none; margin-left: 5px;">See More</span>
</a>
</li>
</ul>
</nav>
</header>
<section id="about">
<h2>About Me</h2>
<p>I am a professional with many years of experience in my field. I am dedicated to providing high-quality services to my clients and helping them achieve their goals.</p>
</section>
<section id="services">
<h2>Services</h2>
<ul>
<li>Front End</li>
<li>Back End</li>
<li>Metaverse / Digital Creation</li>
</ul>
</section>
<!-- Badges -->
<section id="contact">
<!--
<div class="badge-base LI-profile-badge" data-locale="fr_FR" data-size="medium" data-theme="dark" data-type="VERTICAL" data-vanity="kevinmarville" data-version="v1"><a class="badge-base__link LI-simple-link" href="https://fr.linkedin.com/in/kevinmarville?trk=profile-badge">Kevin M.</a></div>
-->
<h2>Contact Me</h2>
<form id="contact-form">
<label for="name">Name:</label>
<input type="text" id="name" required>
<label for="email">Email:</label>
<input type="email" id="email" required>
<label for="message">Message:</label>
<textarea id="message" required></textarea>
<button type="submit">Send</button>
</form>
<a href="https://app.daily.dev/kevinmarville"><img src="https://api.daily.dev/devcards/v2/Ci75X9sjgBAuP70WotWgd.png?type=wide&r=ljx" width="652" alt="Kevin Marville's Dev Card"/></a>
</section>
<script>
// Add hover effect to the link
const link = document.querySelector('a');
link.addEventListener('mouseover', function() {
link.style.backgroundColor = '#007bff';
link.style.color = '#fff';
link.style.border = '2px solid #007bff';
});
link.addEventListener('mouseout', function() {
link.style.backgroundColor = 'transparent';
link.style.color = '#007bff';
link.style.border = '2px solid transparent';
});
</script>
<!-- Main Container -->
<main class="container">
<!-- Website Image and Call-to-Action -->
<div>
<div class="progress-container">
<div class="progress-label"></div>
<!-- Dynamic progress bar with animation -->
<progress id="progressBar" class="under-construction-image energy-effect" value="0" max="100" aria-label="Website under construction"></progress>
</div>
<script>
// Set initial value
let progress = 0;
const progressBar = document.getElementById('progressBar');
function updateProgress() {
// Increment progress dynamically
if (progress < 20) {
progress += 0.2; // Increment speed
} else {
progress = 0; // Reset for looping effect
}
progressBar.value = progress;
// Apply math-driven color changes for a more energy-like effect
const colorFactor = Math.sin(progress * Math.PI / 20);
const energyColor = `rgb(${76 + colorFactor * 50}, ${175 + colorFactor * 80}, 50)`;
// Update bar's glow effect dynamically
progressBar.style.setProperty('--glow-color', energyColor);
progressBar.style.backgroundColor = energyColor;
// Update every 50ms for smooth animation
requestAnimationFrame(updateProgress);
}
// Start the dynamic progress
requestAnimationFrame(updateProgress);
</script>
<div class="centered-text">
<span class="flag-fr">Développeur Web</span>
<span class="flag-en">Web developer</span>
</div>
</div>
<!-- Chatbot -->
<div class="chatbot">
<div class="terminal-output" id="chat-output">
<p>
<span class="flag-fr">Bienvenue sur mon IA CHAT BOT, toujours en développement, comment puis-je vous aider ?</span>
<span class="flag-en">Welcome to my AI CHAT BOT, early in beta version, how can I assist you?</span>
</p>
</div>
<div class="loading-animation" id="loading-animation" style="display:none;">
<span></span><span></span><span></span>
</div>
<!-- Matrix Effect -->
<div class="matrix-effect" id="matrix-effect" style="display:none;">
<canvas id="matrix-canvas"></canvas>
</div>
<!-- Input field and button for user interaction -->
<div class="user-input">
<input type="text" id="user-message" placeholder="Type your message here..." onkeydown="checkEnterKey(event)" />
<button onclick="sendMessage()">Send</button>
</div>
</div>
<script src="https://platform.linkedin.com/badges/js/profile.js" async defer type="text/javascript"></script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"></script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/universal-sentence-encoder"></script>
<script>
// Initialize the matrix effect variables
let matrixEffectTimeout;
let typingTimeout;
const matrixEffectDuration = 5000; // 5 seconds
const matrixCanvas = document.getElementById('matrix-canvas');
const matrixEffectDiv = document.getElementById('matrix-effect');
const chatOutputDiv = document.getElementById('chat-output');
const ctx = matrixCanvas.getContext('2d');
let matrixColumns;
let drops;
function initMatrixEffect() {
// Setting canvas dimensions to match the chat-output width
matrixCanvas.width = chatOutputDiv.clientWidth;
matrixCanvas.height = chatOutputDiv.clientHeight;
const fontSize = 14;
matrixColumns = matrixCanvas.width / fontSize;
drops = Array(Math.floor(matrixColumns)).fill(1);
}
function drawMatrix() {
ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
ctx.fillRect(0, 0, matrixCanvas.width, matrixCanvas.height);
ctx.fillStyle = '#00FF00'; // Matrix green color
ctx.font = '14px monospace';
drops.forEach((y, x) => {
const text = String.fromCharCode(0x30A0 + Math.random() * 96);
ctx.fillText(text, x * 14, y * 14);
// Random reset drop for a realistic matrix effect
if (y * 14 > matrixCanvas.height && Math.random() > 0.975) {
drops[x] = 0;
}
drops[x]++;
});
}
function startMatrixEffect() {
matrixEffectDiv.style.display = 'block';
chatOutputDiv.style.display = 'none'; // Hide normal chat output
initMatrixEffect();
matrixEffectTimeout = setInterval(drawMatrix, 50);
}
function stopMatrixEffect() {
matrixEffectDiv.style.display = 'none';
chatOutputDiv.style.display = 'block'; // Show chat output again
clearInterval(matrixEffectTimeout);
}
function resetTypingTimer() {
clearTimeout(typingTimeout);
stopMatrixEffect();
typingTimeout = setTimeout(startMatrixEffect, matrixEffectDuration);
}
document.getElementById('user-message').addEventListener('input', resetTypingTimer);
// Start the matrix effect if no typing occurs after 5 seconds
typingTimeout = setTimeout(startMatrixEffect, matrixEffectDuration);
</script>
<script>
// Contact Form
document.getElementById('contact-form').addEventListener('submit', function(event) {
event.preventDefault();
const form = event.target;
const submitButton = form.querySelector('button[type="submit"]');
const spinner = document.createElement('span');
const successMessage = document.createElement('p');
// Add spinner styles
spinner.classList.add('spinner');
spinner.style.marginLeft = '8px';
spinner.innerHTML = '⏳'; // Use an emoji or custom styles for better UX
submitButton.appendChild(spinner);
// Disable submit button during the fake animation
submitButton.disabled = true;
// Fake AJAX request delay
setTimeout(() => {
// Remove spinner
submitButton.removeChild(spinner);
submitButton.disabled = false;
// Show success message
successMessage.textContent = 'Form submitted successfully!';
successMessage.style.color = 'green';
form.appendChild(successMessage);
// Clear the success message after 3 seconds
setTimeout(() => {
form.removeChild(successMessage);
}, 3000);
// Optional: Clear form fields
form.reset();
}, 2000); // Simulate a 2-second delay
});
// Load Universal Sentence Encoder for semantic understanding
let useModel;
let embeddingCache = {}; // Cache to store embeddings
async function loadUSEModel() {
useModel = await use.load(); // Load the Universal Sentence Encoder model
}
loadUSEModel(); // Load the model on script load
// Global variables
let currentLanguage = 'en'; // Default to English
let contextMemory = []; // Store conversation history for contextual responses
// Enhanced language detection with multi-language support
function detectLanguage(input) {
const frenchChars = /[éèàùçâêîôûëïüœ]/i;
const spanishChars = /[áéíóúñü]/i;
const germanChars = /[äöüß]/i;
if (frenchChars.test(input)) {
currentLanguage = 'fr';
} else if (spanishChars.test(input)) {
currentLanguage = 'es';
} else if (germanChars.test(input)) {
currentLanguage = 'de';
} else {
currentLanguage = 'en';
}
}
// Predefined knowledge base with multilingual support (English, French, Spanish, German)
const knowledgeBase = [
{
id: 1,
keywords: { en: ["computer", "history", "first", "invention"], fr: ["ordinateur", "histoire", "premier", "invention"], es: ["ordenador", "historia", "primero", "invención"], de: ["computer", "geschichte", "erste", "erfindung"] },
fact: { en: "The first mechanical computer was created by Charles Babbage in 1822.", fr: "Le premier ordinateur mécanique a été créé par Charles Babbage en 1822.", es: "El primer ordenador mecánico fue creado por Charles Babbage en 1822.", de: "Der erste mechanische Computer wurde 1822 von Charles Babbage erfunden." }
},
{
id: 2,
keywords: { en: ["software", "history", "first", "program"], fr: ["logiciel", "histoire", "premier", "programme"], es: ["software", "historia", "primero", "programa"], de: ["software", "geschichte", "erste", "programm"] },
fact: { en: "The first high-level programming language was Fortran, developed in the 1950s.", fr: "Le premier langage de programmation de haut niveau était Fortran, développé dans les années 1950.", es: "El primer lenguaje de programación de alto nivel fue Fortran, desarrollado en los años 50.", de: "Die erste Programmiersprache war Fortran, entwickelt in den 1950er Jahren." }
}
// Add more entries with multilingual facts and keywords...
];
// Tokenization function to extract meaningful words
function tokenize(text) {
return text.toLowerCase().replace(/[^a-z0-9 ]/g, '').split(/\s+/);
}
// Using Universal Sentence Encoder to calculate similarity between embeddings
async function calculateUSESimilarity(userInput, knowledgeEntry) {
const inputKey = `${currentLanguage}:${userInput}`;
// Use cache if embedding is already computed
let inputEmbedding;
if (embeddingCache[inputKey]) {
inputEmbedding = embeddingCache[inputKey];
} else {
inputEmbedding = await useModel.embed(userInput);
embeddingCache[inputKey] = inputEmbedding;
}
const knowledgeEmbedding = await useModel.embed(knowledgeEntry.keywords[currentLanguage].join(" "));
const similarityScore = cosineSimilarity(inputEmbedding, knowledgeEmbedding);
return similarityScore;
}
// Function to calculate cosine similarity between two embeddings
function cosineSimilarity(vec1, vec2) {
const dotProduct = tf.dot(vec1, vec2).dataSync()[0];
const magnitudeA = tf.norm(vec1).dataSync()[0];
const magnitudeB = tf.norm(vec2).dataSync()[0];
if (!magnitudeA || !magnitudeB) return 0;
return dotProduct / (magnitudeA * magnitudeB);
}
// Contextual memory for better conversation handling
function updateContextMemory(userMessage) {
contextMemory.push({ message: userMessage, language: currentLanguage });
if (contextMemory.length > 5) {
contextMemory.shift(); // Limit memory size to avoid overflow
}
}
// Find best fact with Universal Sentence Encoder and context handling
async function findBestFact(userInput) {
let bestMatch = null;
let highestScore = 0;
// Apply language detection
detectLanguage(userInput);
// Update context memory with new user input
updateContextMemory(userInput);
for (let entry of knowledgeBase) {
const similarityScore = await calculateUSESimilarity(userInput, entry);
if (similarityScore > highestScore) {
highestScore = similarityScore;
bestMatch = entry;
}
}
return bestMatch ? bestMatch.fact[currentLanguage] : (currentLanguage === 'en' ? "I'm not sure, can you ask something else?" : (currentLanguage === 'fr' ? "Je ne suis pas sûr, pouvez-vous poser une autre question ?" : (currentLanguage === 'es' ? "No estoy seguro, ¿puedes preguntar otra cosa?" : "Ich bin mir nicht sicher, können Sie etwas anderes fragen?")));
}
// Simulate chatbot response with context and language detection
async function chatbotResponse(userMessage) {
const chatOutput = document.getElementById("chat-output");
const loadingAnimation = document.getElementById("loading-animation");
// Show loading animation after slight delay for realism
setTimeout(() => {
loadingAnimation.style.display = 'block';
}, 300);
// Simulate a delayed response for a better user experience
setTimeout(async () => {
loadingAnimation.style.display = 'none';
const response = await findBestFact(userMessage); // Get response based on input
// Display the response
const newMessage = document.createElement('p');
newMessage.textContent = response;
chatOutput.appendChild(newMessage);
// Smooth scroll to the latest message
chatOutput.scroll({ top: chatOutput.scrollHeight, behavior: 'smooth' });
}, 2000);
}
// Capture input and send to chatbot
function sendMessage() {
const userInput = document.getElementById("user-message").value.trim();
if (userInput === "") {
const chatOutput = document.getElementById("chat-output");
const warningMessage = document.createElement('p');
warningMessage.style.color = 'red';
warningMessage.textContent = currentLanguage === 'en' ? "Please enter a message before sending!" : (currentLanguage === 'fr' ? "Veuillez entrer un message avant d'envoyer!" : (currentLanguage === 'es' ? "¡Por favor ingresa un mensaje antes de enviarlo!" : "Bitte geben Sie eine Nachricht ein, bevor Sie sie senden!"));
chatOutput.appendChild(warningMessage);
chatOutput.scroll({ top: chatOutput.scrollHeight, behavior: 'smooth' });
return;
}
chatbotResponse(userInput);
// Clear input field after sending
document.getElementById("user-message").value = "";
}
// Function to trigger send on pressing the "Enter" key
function checkEnterKey(event) {
if (event.key === 'Enter') {
sendMessage();
}
}
</script>
</main>
<!-- Footer -->
<footer>
© 2025 Kevin Marville. All rights reserved.
</footer>
<script>
// JavaScript for Language Toggle
const toggleButton = document.getElementById('language-toggle');
const body = document.body;
toggleButton.addEventListener('click', function() {
if (body.classList.contains('active-en')) {
body.classList.remove('active-en');
body.classList.add('active-fr');
} else {
body.classList.remove('active-fr');
body.classList.add('active-en');
}
});
</script>
</body>
</html>