-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
1168 lines (1040 loc) · 38.9 KB
/
Copy pathscript.js
File metadata and controls
1168 lines (1040 loc) · 38.9 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
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
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ── Scroll throttle helper (16ms ≈ 60fps cap) ──
function throttle(fn, ms) {
let last = 0;
return function() {
let now = Date.now();
if (now - last >= ms) {
last = now;
fn.apply(this, arguments);
}
};
}
// ── Toast helper ──
function showToast(msg, duration) {
let toast = document.getElementById('copy-toast');
if (!toast) return;
toast.textContent = msg;
toast.classList.add('show');
setTimeout(function() {
toast.classList.remove('show');
}, duration);
}
// ── Locale helper ──
function isSpanish() {
return typeof currentLocale !== 'undefined' && currentLocale === 'es';
}
function getTrans(locale) {
return translations[locale] || translations.en;
}
// ── Timing constants ──
const TOAST_OK_MS = 3000; // toast after successful clipboard copy
const TOAST_FALLBACK_MS = 5000; // toast when clipboard unavailable
const FAQ_AUTO_CLOSE_MS = 15000; // FAQ modal auto-close delay
const TERMINAL_ROTATE_MS = 3000;
const COUNTER_LONG_MS = 1400; // counter animation for numbers > 100
const COUNTER_SHORT_MS = 900; // counter animation for numbers ≤ 100
const WA_NUMBER = (window.SITE_CONFIG && window.SITE_CONFIG.whatsapp) || atob('NTczMTM2NDU5Mjk5');
// ── Layout / interaction constants ──
const BACK_TO_TOP_THRESHOLD = 400; // px scrollY to show back-to-top button
const MOBILE_BREAKPOINT = 767; // px – matches CSS @media (max-width: 767px)
const CURSOR_RING_LERP = 0.14; // lerp factor for cursor ring follow speed
const TILT_PERSPECTIVE = 900; // px perspective for card 3-D tilt effect
const QC_BAR_MAX_MULT = 1.15; // gauge bar – scale factor vs. max-complexity service
const QC_BAR_MAX_PCT = 92; // gauge bar upper clamp (%)
const QC_BAR_MIN_PCT = 8; // gauge bar lower clamp (%)
const MATRIX_CHAR_SIZE = 16; // px cell size for Matrix rain columns
const MATRIX_DROP_PROB = 0.975; // probability a Matrix drop resets to top
// translations object → translations.js (loaded before this file)
// DOM references
const langButtons = document.querySelectorAll('[data-lang-toggle]');
const metaDescription = document.querySelector('meta[name="description"]');
const ogTitle = document.querySelector('meta[property="og:title"]');
const ogDescription = document.querySelector('meta[property="og:description"]');
const ogLocale = document.querySelector('meta[property="og:locale"]');
const waFloatEl = document.querySelector('.wa-float');
let currentLocale = localStorage.getItem('portfolio-lang') || 'en';
let prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
// Locale
function applyLocale(locale) {
const copy = getTrans(locale);
Object.entries(copy.selectors).forEach((entry) => {
document.querySelectorAll(entry[0]).forEach((node) => {
if (node.dataset.html) node.innerHTML = entry[1];
else node.textContent = entry[1];
});
});
if (copy.placeholders) {
Object.entries(copy.placeholders).forEach((entry) => {
let node = document.querySelector(entry[0]);
if (node) node.placeholder = entry[1];
});
}
document.documentElement.lang = locale === 'es' ? 'es' : 'en';
document.title = copy.documentTitle;
if (metaDescription) metaDescription.setAttribute('content', copy.metaDescription);
if (ogTitle) ogTitle.setAttribute('content', copy.ogTitle);
if (ogDescription) ogDescription.setAttribute('content', copy.ogDescription);
if (ogLocale) ogLocale.setAttribute('content', locale === 'es' ? 'es_CO' : 'en_US');
langButtons.forEach((btn) => {
let active = btn.dataset.langToggle === locale;
btn.classList.toggle('is-active', active);
btn.setAttribute('aria-pressed', active ? 'true' : 'false');
});
const waFloat = waFloatEl; // cached at init
if (waFloat) {
const waNum = WA_NUMBER;
let waMsg = getTrans(locale).waMsg;
waFloat.href = 'https://wa.me/' + waNum + '?text=' + encodeURIComponent(waMsg);
}
// ── Dynamic aria-label updates ──
const _aria = getTrans(locale).aria;
document.querySelectorAll('.qc-svc-card[data-svc]').forEach((btn) => {
let lbl = _aria.svc[btn.dataset.svc];
if (lbl) btn.setAttribute('aria-label', lbl);
});
document.querySelectorAll('.qc-toggle[data-scope]').forEach((b) => {
let k = _aria.tgl[b.dataset.scope];
if (k) b.setAttribute('aria-label', k);
});
document.querySelectorAll('.qc-toggle[data-cplx]').forEach((b) => {
let k = b.dataset.cplx === 'medium' ? _aria.tgl['medium-cplx'] : _aria.tgl[b.dataset.cplx];
if (k) b.setAttribute('aria-label', k);
});
document.querySelectorAll('.qc-toggle[data-tbox]').forEach((b) => {
let k = _aria.tgl[b.dataset.tbox];
if (k) b.setAttribute('aria-label', k);
});
document.querySelectorAll('[data-contact]').forEach(function(emailLink) {
if (emailLink.getAttribute('role') === 'button') {
emailLink.setAttribute('aria-label', _aria.emailCopy);
}
});
let heroBook = document.getElementById('hero-book-link');
if (heroBook) heroBook.setAttribute('aria-label', _aria.bookCall);
localStorage.setItem('portfolio-lang', locale);
}
langButtons.forEach((btn) => {
btn.addEventListener('click', function() {
currentLocale = btn.dataset.langToggle || 'en';
applyLocale(currentLocale);
window.dispatchEvent(new CustomEvent('localechange', {
detail: {
locale: currentLocale
}
}));
});
});
// ── Quote Calculator pricing config (edit here to update estimates) ──
const PRICES = {
pentest_web: {
name: "Web App Pentest",
base: [2000, 5000],
scope: {
small: 1.0,
medium: 1.9,
large: 3.5
},
cplx: {
low: 1.0,
medium: 1.45,
high: 2.1
},
tbox: {
black: 1.0,
grey: 1.2,
white: 1.7
}
},
pentest_ad: {
name: 'Active Directory',
base: [3000, 7000],
scope: {
small: 1.0,
medium: 1.6,
large: 2.8
},
cplx: {
low: 1.0,
medium: 1.4,
high: 2.1
},
tbox: {
black: 1.0,
grey: 1.15,
white: 1.6
}
}
};
function initBookingLinks() {
let url = (typeof SITE_LINKS !== 'undefined' && SITE_LINKS.booking) ? SITE_LINKS.booking.trim() : '';
let heroBook = document.getElementById('hero-book-link');
if (!url || !heroBook) return;
heroBook.href = url;
heroBook.target = '_blank';
heroBook.rel = 'noopener noreferrer';
}
initQuoteCalculator();
initBookingLinks();
applyLocale(currentLocale);
function applySiteLinks() {
const cfg = window.SITE_CONFIG;
if (!cfg || !cfg.links) return;
document.querySelectorAll('[data-social]').forEach((el) => {
const key = el.dataset.social;
if (cfg.links[key]) el.href = cfg.links[key];
});
}
applySiteLinks();
function initStats() {
[
['stat-targets', SITE_STATS.targets],
['stat-paths', SITE_STATS.paths],
['stat-ranking', SITE_STATS.ranking],
['stat-modules', SITE_STATS.modules]
].forEach(function(pair) {
var span = document.getElementById(pair[0]);
if (span && span.parentElement) {
var strong = span.parentElement.querySelector('strong');
if (strong) strong.textContent = pair[1];
}
});
}
initStats();
// Restore obfuscated contact links from data attributes
function initContactBindings() {
document.querySelectorAll('[data-contact]').forEach((el) => {
let decoded = '';
try {
decoded = atob(el.dataset.contact || '');
} catch (e) {
return;
}
if (decoded.startsWith('tel:')) {
// Phone: native dialer is correct on mobile
el.href = decoded;
} else {
// Email: use clipboard — avoids OS mailto: / login redirects
el.setAttribute('href', '#');
el.setAttribute('role', 'button');
el.setAttribute('aria-label', isSpanish() ? 'Copiar correo al portapapeles' : 'Copy email address to clipboard');
let email = decoded.replace(/^mailto:/, '');
el.addEventListener('click', function(e) {
e.preventDefault();
let toast = document.getElementById('copy-toast');
if (navigator.clipboard && window.isSecureContext) {
navigator.clipboard.writeText(email).then(function() {
showToast((isSpanish() ? '✓ Correo copiado: ' : '✓ Email copied: ') + email, TOAST_OK_MS);
}).catch(function() {
// Fallback: show email inline
showToast(email, TOAST_FALLBACK_MS);
});
} else {
showToast(email, TOAST_FALLBACK_MS);
}
});
}
});
}
initContactBindings();
// Contact form — Formspree AJAX handler
function initContactForm() {
let form = document.getElementById('contact-form');
let btn = document.getElementById('cf-submit');
let status = document.getElementById('cf-status');
if (!form || !btn || !status) return;
form.addEventListener('submit', function(e) {
e.preventDefault();
if (btn.disabled) return;
// Client-side validation
let name = form.querySelector('#cf-name').value.trim();
let email = form.querySelector('#cf-email').value.trim();
let message = form.querySelector('#cf-message').value.trim();
let emailRe = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
let msgs = getTrans(currentLocale).formMessages || {};
if (!name || !email || !message) {
status.textContent = msgs.requiredFields || 'Please fill in all fields.';
status.className = 'cf-status error';
return;
}
if (!emailRe.test(email)) {
status.textContent = msgs.invalidEmail || 'Please enter a valid email address.';
status.className = 'cf-status error';
return;
}
// Submit
btn.classList.add('loading');
btn.disabled = true;
status.textContent = '';
status.className = 'cf-status';
let data = new FormData(form);
fetch(form.action, {
method: 'POST',
body: data,
headers: {
'Accept': 'application/json'
}
})
.then(function(res) {
btn.classList.remove('loading');
btn.disabled = false;
if (res.ok) {
status.textContent = msgs.success || '✓ Message sent!';
status.className = 'cf-status success';
form.reset();
} else {
return res.json().then(function(data) {
let msg = (data && data.errors) ? data.errors.map(function(e) {
return e.message;
}).join(', ') : (msgs.submitFailed || 'Submission failed.');
status.textContent = msg;
status.className = 'cf-status error';
});
}
})
.catch(function() {
btn.classList.remove('loading');
btn.disabled = false;
status.textContent = msgs.networkError || 'Network error.';
status.className = 'cf-status error';
});
});
}
initContactForm();
// Scroll reveal — fade+slide cards and elements into view
function initScrollReveal() {
if (!window.IntersectionObserver || prefersReducedMotion) return;
let els = [];
document.querySelectorAll('.card, .mini-card, .social-link').forEach((el) => {
if (!el.closest('.hero')) {
el.classList.add('reveal');
els.push(el);
}
});
let io = new IntersectionObserver(function(entries) {
// Group by parent to stagger siblings
let groups = new Map();
entries.forEach((e) => {
if (!e.isIntersecting) return;
let p = e.target.parentElement || document.body;
if (!groups.has(p)) groups.set(p, []);
groups.get(p).push(e.target);
});
groups.forEach((siblings) => {
siblings.forEach((el, i) => {
if (i > 0 && i <= 3) el.setAttribute('data-delay', i);
el.classList.add('is-visible');
// Also trigger section-tag scan animation
let tag = el.querySelector('.section-tag');
if (tag) tag.classList.add('tag-animate');
io.unobserve(el);
});
});
}, {
threshold: 0.05,
rootMargin: '0px 0px -20px 0px'
});
els.forEach((el) => {
io.observe(el);
});
}
initCounterAnimation();
// Animated stat counters for quick-stats numbers
function initCounterAnimation() {
if (!window.IntersectionObserver || prefersReducedMotion) return;
document.querySelectorAll('.quick-stats strong').forEach((el) => {
let raw = el.textContent.trim();
let num = parseInt(raw, 10);
if (isNaN(num)) return; // Skip "Top 1%" etc.
el.textContent = '0';
let done = false;
let io = new IntersectionObserver(function(entries) {
entries.forEach((e) => {
if (!e.isIntersecting || done) return;
done = true;
io.unobserve(e.target);
let start = null;
let duration = num > 100 ? COUNTER_LONG_MS : COUNTER_SHORT_MS;
function step(ts) {
if (!start) start = ts;
let p = Math.min((ts - start) / duration, 1);
let v = Math.round((1 - Math.pow(1 - p, 3)) * num);
e.target.textContent = v;
if (p < 1) requestAnimationFrame(step);
}
requestAnimationFrame(step);
});
}, {
threshold: 0.6
});
io.observe(el);
});
}
initScrollReveal();
// Active nav highlight
function initActiveNav() {
let navLinks = document.querySelectorAll('.topnav a');
let sections = Array.from(document.querySelectorAll('main section[id]'));
if (!navLinks.length || !sections.length) return;
const HERO_TOP_THRESHOLD = 100;
let visible = new Set();
function clearActive() {
navLinks.forEach((link) => link.classList.remove('active'));
}
function setActive(id) {
navLinks.forEach((link) => {
link.classList.toggle('active', link.getAttribute('href') === '#' + id);
});
}
function updateActive() {
if (window.scrollY < HERO_TOP_THRESHOLD) {
clearActive();
return;
}
for (let i = 0; i < sections.length; i++) {
if (visible.has(sections[i].id) &&
document.querySelector('.topnav a[href="#' + sections[i].id + '"]')) {
setActive(sections[i].id);
return;
}
}
clearActive();
}
let io = new IntersectionObserver(function(entries) {
entries.forEach((entry) => {
if (entry.isIntersecting) visible.add(entry.target.id);
else visible.delete(entry.target.id);
});
updateActive();
}, {
rootMargin: '-60px 0px -30% 0px',
threshold: 0
});
sections.forEach((sec) => {
io.observe(sec);
});
window.addEventListener('scroll', updateActive, { passive: true });
updateActive();
}
// Smooth scroll for nav links
document.querySelectorAll('.topnav a').forEach((a) => {
a.addEventListener('click', function(e) {
const href = this.getAttribute('href');
if (href && href.startsWith('#')) {
e.preventDefault();
const target = document.querySelector(href);
if (target) target.scrollIntoView({
behavior: prefersReducedMotion ? 'auto' : 'smooth',
block: 'start'
});
}
});
});
window.addEventListener('scroll', throttle(function() {}, 16), {
passive: true
});
window.matchMedia('(prefers-reduced-motion: reduce)').addEventListener('change', function(e) {
prefersReducedMotion = e.matches;
});
// Back to top
function initBackToTop() {
const btn = document.querySelector('.back-to-top');
if (!btn) return;
window.addEventListener('scroll', throttle(function() {
btn.classList.toggle('visible', window.scrollY > BACK_TO_TOP_THRESHOLD);
}, 16), {
passive: true
});
btn.addEventListener('click', function() {
window.scrollTo({
top: 0,
behavior: prefersReducedMotion ? 'auto' : 'smooth'
});
});
}
initBackToTop();
// Service Worker registration
if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register('/sw.js').then(function(reg) {
reg.addEventListener('updatefound', function() {
var worker = reg.installing;
if (!worker) return;
worker.addEventListener('statechange', function() {
if (worker.state === 'activated' && navigator.serviceWorker.controller) {
window.location.reload();
}
});
});
}).catch(function(e) {
console.warn('[SW] Registration failed:', e);
});
});
}
// ── HAMBURGER MENU ────────────────────────────
function initHamburgerMenu() {
let topbar = document.getElementById('topbar');
let btn = topbar && topbar.querySelector('.nav-toggle');
if (!topbar || !btn) return;
let links = topbar.querySelectorAll('.topnav a');
function close() {
topbar.classList.remove('nav-open');
btn.setAttribute('aria-expanded', 'false');
}
btn.addEventListener('click', function() {
let open = topbar.classList.toggle('nav-open');
btn.setAttribute('aria-expanded', open ? 'true' : 'false');
});
links.forEach((a) => {
a.addEventListener('click', close);
});
document.addEventListener('click', function(e) {
if (!topbar.contains(e.target)) close();
});
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape') close();
});
}
initHamburgerMenu();
/* ── Konami Code + Matrix Rain Easter Egg ── */
function initKonamiEasterEgg() {
let KONAMI = ['ArrowUp', 'ArrowUp', 'ArrowDown', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'ArrowLeft', 'ArrowRight', 'b', 'a'];
let idx = 0;
document.addEventListener('keydown', function(e) {
let k = e.key.length === 1 ? e.key.toLowerCase() : e.key;
if (k === KONAMI[idx]) {
idx++;
if (idx === KONAMI.length) {
idx = 0;
triggerMatrix();
}
} else {
idx = k === KONAMI[0] ? 1 : 0;
}
});
function triggerMatrix() {
// Overlay
let overlay = document.createElement('div');
overlay.id = 'matrix-overlay';
overlay.style.cssText = [
'position:fixed', 'inset:0', 'z-index:9999',
'background:#000', 'display:flex',
'flex-direction:column', 'align-items:center',
'justify-content:center', 'cursor:pointer'
].join(';');
// Canvas
let canvas = document.createElement('canvas');
canvas.style.cssText = 'position:absolute;inset:0;width:100%;height:100%';
overlay.appendChild(canvas);
// Access Granted message
let msg = document.createElement('div');
msg.style.cssText = [
'position:relative', 'z-index:2', 'text-align:center',
'font-family:"JetBrains Mono",monospace', 'color:#00ff41',
'text-shadow:0 0 20px #00ff41,0 0 40px #00ff41',
'animation:glitch 0.4s infinite alternate'
].join(';');
msg.innerHTML = [
'<div style="font-size:clamp(2rem,8vw,4rem);font-weight:700;letter-spacing:0.15em;">ACCESS GRANTED</div>',
'<div style="font-size:clamp(0.8rem,2vw,1.1rem);margin-top:16px;opacity:0.8;">Welcome, ' + ((navigator.userAgentData && navigator.userAgentData.platform || navigator.platform || 'Unknown') || 'Unknown') + ' operator</div>',
'<div style="font-size:clamp(0.7rem,1.5vw,0.9rem);margin-top:8px;opacity:0.6;">[ click or press ESC to exit ]</div>'
].join('');
overlay.appendChild(msg);
// Add glitch keyframes once
if (!document.getElementById('matrix-style')) {
let st = document.createElement('style');
st.id = 'matrix-style';
st.textContent = '@keyframes glitch{0%{text-shadow:0 0 20px #00ff41,0 0 40px #00ff41;transform:translate(0)}50%{text-shadow:-2px 0 #ff0000,2px 0 #0000ff,0 0 30px #00ff41;transform:translate(-1px,1px)}100%{text-shadow:2px 0 #ff0000,-2px 0 #0000ff,0 0 20px #00ff41;transform:translate(1px,-1px)}}';
document.head.appendChild(st);
}
document.body.appendChild(overlay);
document.body.style.overflow = 'hidden';
// Matrix rain
let ctx = canvas.getContext('2d');
function resize() {
canvas.width = overlay.offsetWidth;
canvas.height = overlay.offsetHeight;
}
resize();
window.addEventListener('resize', resize);
let cols = Math.floor(canvas.width / 16);
let drops = Array.from({
length: cols
}, function() {
return Math.random() * -50 | 0;
});
let CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#$%^&*<>/\\|[]{}アイウエオカキクケコサシスセソタチツテトナニヌネノ';
let raf;
function draw() {
ctx.fillStyle = 'rgba(0,0,0,0.05)';
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.font = '14px "JetBrains Mono", monospace';
for (let i = 0; i < drops.length; i++) {
let ch = CHARS[Math.random() * CHARS.length | 0];
let bright = Math.random() > 0.95;
ctx.fillStyle = bright ? '#ffffff' : '#00ff41';
ctx.fillText(ch, i * MATRIX_CHAR_SIZE, drops[i] * MATRIX_CHAR_SIZE);
if (drops[i] * MATRIX_CHAR_SIZE > canvas.height && Math.random() > MATRIX_DROP_PROB) drops[i] = 0;
drops[i]++;
}
raf = requestAnimationFrame(draw);
}
draw();
function close() {
cancelAnimationFrame(raf);
window.removeEventListener('resize', resize);
if (overlay.parentNode) overlay.parentNode.removeChild(overlay);
document.body.style.overflow = '';
}
overlay.addEventListener('click', close);
document.addEventListener('keydown', function esc(e) {
if (e.key === 'Escape') {
close();
document.removeEventListener('keydown', esc);
}
});
// Auto-close after 15s
setTimeout(close, FAQ_AUTO_CLOSE_MS);
}
}
initKonamiEasterEgg();
// 3D Tilt effect on cards
function initMotionObserver() {
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) return;
if ('ontouchstart' in window) return;
let STRENGTH = 7;
function initTilt(card) {
let glare = document.createElement('div');
glare.style.cssText = 'position:absolute;inset:0;border-radius:inherit;pointer-events:none;opacity:0;transition:opacity 200ms ease;z-index:1';
card.appendChild(glare);
card.style.transformStyle = 'preserve-3d';
card.style.transition = 'transform 100ms ease';
card.style.willChange = 'transform';
function onMove(e) {
let rect = card.getBoundingClientRect();
let x = (e.clientX - rect.left) / rect.width - 0.5;
let y = (e.clientY - rect.top) / rect.height - 0.5;
let rotY = x * STRENGTH * 2;
let rotX = -y * STRENGTH * 2;
card.style.transform = `perspective(${TILT_PERSPECTIVE}px) rotateX(${rotX}deg) rotateY(${rotY}deg) scale3d(1.012,1.012,1.012)`;
let gx = Math.round((x + 0.5) * 100);
let gy = Math.round((y + 0.5) * 100);
glare.style.background = 'radial-gradient(circle at ' + gx + '% ' + gy + '%, rgba(255,255,255,0.035), transparent 65%)';
glare.style.opacity = '1';
}
function onLeave() {
card.style.transition = 'transform 500ms ease';
card.style.transform = `perspective(${TILT_PERSPECTIVE}px) rotateX(0deg) rotateY(0deg) scale3d(1,1,1)`;
glare.style.opacity = '0';
}
card.addEventListener('mousemove', onMove);
card.addEventListener('mouseleave', onLeave);
}
function attachAll() {
document.querySelectorAll('.card').forEach((c) => {
if (c.closest('.hero')) return;
initTilt(c);
});
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', attachAll);
} else {
attachAll();
}
}
initMotionObserver();
/* ── Custom Crosshair Cursor ── */
function initCursorEffect() {
if (!window.matchMedia('(pointer: fine)').matches) return;
let dot = document.querySelector('.cursor-dot');
let ring = document.querySelector('.cursor-ring');
if (!dot || !ring) return;
let mx = -200,
my = -200,
rx = -200,
ry = -200;
let rafId = null;
function animateRing() {
rx += (mx - rx) * CURSOR_RING_LERP;
ry += (my - ry) * CURSOR_RING_LERP;
ring.style.left = rx + 'px';
ring.style.top = ry + 'px';
// Keep looping only while ring hasn't converged (> 0.5px away from target)
if (Math.abs(mx - rx) > 0.5 || Math.abs(my - ry) > 0.5) {
rafId = requestAnimationFrame(animateRing);
} else {
rafId = null;
}
}
function startLoop() {
if (!rafId && !document.hidden) {
rafId = requestAnimationFrame(animateRing);
}
}
document.addEventListener('mousemove', function(e) {
mx = e.clientX;
my = e.clientY;
dot.style.left = mx + 'px';
dot.style.top = my + 'px';
startLoop();
});
// Pause when tab is hidden, resume on return
document.addEventListener('visibilitychange', function() {
if (document.hidden) {
if (rafId) {
cancelAnimationFrame(rafId);
rafId = null;
}
} else {
startLoop();
}
});
let hoverTargets = 'a,button,[role="button"],input,textarea,select,label,.mini-card,.social-link,.lang-button';
document.addEventListener('mouseover', function(e) {
if (e.target.closest(hoverTargets)) document.body.classList.add('cursor-hovering');
});
document.addEventListener('mouseout', function(e) {
if (e.target.closest(hoverTargets)) document.body.classList.remove('cursor-hovering');
});
document.addEventListener('mousedown', function() {
document.body.classList.add('cursor-clicking');
});
document.addEventListener('mouseup', function() {
document.body.classList.remove('cursor-clicking');
});
document.addEventListener('mouseleave', function() {
dot.style.opacity = '0';
ring.style.opacity = '0';
});
document.addEventListener('mouseenter', function() {
dot.style.opacity = '1';
ring.style.opacity = '1';
});
}
initCursorEffect();
/* ── Quote Calculator v4 ─────────────────────────────────── */
function initQuoteCalculator() {
'use strict';
function fmt(n) {
return '$' + Math.round(n).toLocaleString('en-US');
}
function el(id) {
return document.getElementById(id);
}
function recalc() {
const isSp = isSpanish(); // cached — avoids 7 separate calls
const _lbl = getTrans(isSp ? 'es' : 'en').labels; // re-read each call — stays in sync with locale
let SCOPE_LABELS = _lbl.scope;
let CPLX_LABELS = _lbl.cplx;
let TBOX_LABELS = _lbl.tbox;
let svcBtn = document.querySelector('.qc-svc-card.active');
let scopeBtn = document.querySelector('.qc-toggle[data-scope].active');
let cplxBtn = document.querySelector('.qc-toggle[data-cplx].active');
let tboxBtn = document.querySelector('.qc-toggle[data-tbox].active');
if (!svcBtn || !scopeBtn || !cplxBtn) return;
let svc = svcBtn.dataset.svc,
scope = scopeBtn.dataset.scope,
cplx = cplxBtn.dataset.cplx,
tbox = tboxBtn ? tboxBtn.dataset.tbox : 'black';
let p = PRICES[svc];
if (!p) return;
let mn = p.base[0] * (p.scope[scope] || 1) * (p.cplx[cplx] || 1) * (p.tbox[tbox] || 1);
let mx = p.base[1] * (p.scope[scope] || 1) * (p.cplx[cplx] || 1) * (p.tbox[tbox] || 1);
if (el('q-min')) el('q-min').textContent = fmt(mn);
if (el('q-max')) el('q-max').textContent = fmt(mx);
if (el('q-unit')) el('q-unit').textContent = 'USD' + (p.unit || '');
if (el('qc-bar')) {
let svcMax = p.base[0] * (p.scope['large'] || 1) * (p.cplx['high'] || 1) * (p.tbox['white'] || 1) * QC_BAR_MAX_MULT;
el('qc-bar').style.width = Math.min(QC_BAR_MAX_PCT, Math.max(QC_BAR_MIN_PCT, (mn / svcMax) * 100)).toFixed(1) + '%';
}
let ss = _lbl.scopeSets[svc];
if (ss) {
(_qcScopeToggles || document.querySelectorAll('.qc-toggle[data-scope]')).forEach((btn) => {
let s = btn.dataset.scope,
small2 = btn.querySelector('small');
if (small2 && ss[s]) small2.textContent = ss[s];
});
}
if (el('qr-svc-name')) el('qr-svc-name').textContent = isSp ? (_lbl.svcNames?.[svc] ?? p.name) : p.name;
if (el('qr-scope')) el('qr-scope').textContent = SCOPE_LABELS[scope] || scope;
if (el('qr-cplx')) el('qr-cplx').textContent = CPLX_LABELS[cplx] || cplx;
if (el('qr-tbox')) el('qr-tbox').textContent = TBOX_LABELS[tbox] || tbox;
let durMap = _lbl.durations[svc];
if (durMap && el('qr-duration')) el('qr-duration').textContent = durMap[scope] || '1–2 weeks';
}
function activate(group, clicked) {
document.querySelectorAll(group).forEach((b) => {
b.classList.remove('active');
});
clicked.classList.add('active');
document.querySelectorAll(group).forEach((b) => {
b.setAttribute('aria-pressed', b === clicked ? 'true' : 'false');
});
recalc();
}
function ready(fn) {
if (document.readyState !== 'loading') {
fn();
} else {
document.addEventListener('DOMContentLoaded', fn);
}
}
// Cached NodeLists for static QC toggle buttons (assigned once on ready)
let _qcSvcCards, _qcScopeToggles, _qcCplxToggles, _qcTboxToggles;
ready(function() {
_qcSvcCards = document.querySelectorAll('.qc-svc-card');
_qcScopeToggles = document.querySelectorAll('.qc-toggle[data-scope]');
_qcCplxToggles = document.querySelectorAll('.qc-toggle[data-cplx]');
_qcTboxToggles = document.querySelectorAll('.qc-toggle[data-tbox]');
// Event delegation: one listener for all calculator toggle buttons
const _qcContainer = document.getElementById('quote');
if (_qcContainer) {
_qcContainer.addEventListener('click', function(e) {
const btn = e.target.closest('.qc-svc-card, .qc-toggle[data-scope], .qc-toggle[data-cplx], .qc-toggle[data-tbox]');
if (!btn) return;
if (btn.classList.contains('qc-svc-card')) activate('.qc-svc-card', btn);
else if (btn.dataset.scope !== undefined) activate('.qc-toggle[data-scope]', btn);
else if (btn.dataset.cplx !== undefined) activate('.qc-toggle[data-cplx]', btn);
else if (btn.dataset.tbox !== undefined) activate('.qc-toggle[data-tbox]', btn);
});
}
recalc();
window.addEventListener('localechange', recalc);
// Testing type help button toggle
let helpBtn = document.getElementById('qc-tbox-help-btn');
let helpPanel = document.getElementById('qc-tbox-info');
if (helpBtn && helpPanel) {
helpBtn.addEventListener('click', function() {
let isOpen = helpPanel.classList.toggle('open');
helpBtn.setAttribute('aria-expanded', isOpen ? 'true' : 'false');
});
// Close panel when user selects a testing type
document.querySelectorAll('.qc-toggle[data-tbox]').forEach((btn) => {
btn.addEventListener('click', function() {
helpPanel.classList.remove('open');
helpBtn.setAttribute('aria-expanded', 'false');
});
});
}
// service-cta cards on the services section pre-select calc
document.querySelectorAll('.service-cta[data-select]').forEach((link) => {
link.addEventListener('click', function() {
let svc = link.dataset.select;
let card = document.querySelector('.qc-svc-card[data-svc="' + svc + '"]');
if (card) {
activate('.qc-svc-card', card);
}
});
});
// CTA button opens WhatsApp with the selected service pre-filled
let mainCta = document.getElementById('qc-main-cta');
if (mainCta) {
mainCta.addEventListener('click', function(e) {
e.preventDefault();
let svcBtn = document.querySelector('.qc-svc-card.active');
let scopeBtn = document.querySelector('.qc-toggle[data-scope].active');
let cplxBtn = document.querySelector('.qc-toggle[data-cplx].active');
let tboxBtn = document.querySelector('.qc-toggle[data-tbox].active');
let scope = scopeBtn ? scopeBtn.dataset.scope : '';
let cplx = cplxBtn ? cplxBtn.dataset.cplx : '';
let tbox = tboxBtn ? tboxBtn.dataset.tbox : 'black';
let minEl = document.getElementById('q-min');
let maxEl = document.getElementById('q-max');
const waNum = WA_NUMBER;
let svcName = '';
if (svcBtn && minEl && maxEl) {
svcName = (() => {
let p = PRICES[svcBtn.dataset.svc] || {};
return isSpanish() ? (getTrans('es').labels.svcNames?.[svcBtn.dataset.svc] ?? p.name) : p.name;
})() || svcBtn.dataset.svc;
}
let scopeStrong = scopeBtn && scopeBtn.querySelector('strong');
let cplxStrong = cplxBtn && cplxBtn.querySelector('strong');
let tboxStrong = tboxBtn && tboxBtn.querySelector('strong');
// Prefill contact form with calculator selections
let scopeDesc = scopeBtn ? scopeBtn.querySelector('small') : null;
let scopeLine = (scopeStrong ? scopeStrong.textContent : scope) + (scopeDesc ? ' · ' + scopeDesc.textContent : '');
let cplxLine = cplxStrong ? cplxStrong.textContent : cplx;
let tboxLine = tboxStrong ? tboxStrong.textContent : tbox;
let priceLine = (minEl && maxEl) ? minEl.textContent + ' – ' + maxEl.textContent + ' USD' : '';
let cfMsg = document.getElementById('cf-message');
if (cfMsg) {
if (isSpanish()) {
cfMsg.value = (svcName ? 'Servicio: ' + svcName + '\n' : '') +
'Alcance: ' + scopeLine + '\n' +
'Complejidad: ' + cplxLine + '\n' +
'Tipo de prueba: ' + tboxLine + '\n' +
(priceLine ? 'Estimado: ' + priceLine + '\n' : '') +
'\n';
} else {
cfMsg.value = (svcName ? 'Service: ' + svcName + '\n' : '') +
'Scope: ' + scopeLine + '\n' +
'Complexity: ' + cplxLine + '\n' +
'Testing type: ' + tboxLine + '\n' +
(priceLine ? 'Estimated range: ' + priceLine + '\n' : '') +
'\n';
}
}
// Scroll to contact form and focus first empty field
let contactSection = document.getElementById('contact');
if (contactSection) contactSection.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
setTimeout(function() {
let cfName = document.getElementById('cf-name');
if (cfName && !cfName.value.trim()) {
cfName.focus();
} else if (cfMsg) {
cfMsg.focus();
cfMsg.setSelectionRange(cfMsg.value.length, cfMsg.value.length);
}
}, 600);
});