-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.js
More file actions
916 lines (710 loc) · 37.2 KB
/
Copy pathapp.js
File metadata and controls
916 lines (710 loc) · 37.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
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
//
// | | | | | | | | | | |
// | | |
//
// | | | | | | | | | | | | | |
// | | | |
// | | | | | | | | | | | | | | | | |
// | | | | | | | | | | | | | | | |
//
// | | | | | | | | | | |
// | | | | | | | | | | | | | | | | | |
//
// | |
// | | | | | | | | | | | | | | | | |
// | | | | | | | | | | | | | | |
//
// | | PRESENTATION | | | | | | | | | | | |
// | | | | | | | | | | |
// | / \ | | | | | | | | | | | |
//
// | Javascript to generate QrCode | | | | | | | |
//
// / | v | \
//
// and barcode images from url for a github website project | | | | | | | | | | |
// | ! | | | | | | | | | | | | | |
// | | |
// | | Anyway ! | | | | | | | | | | | |
//
// | | have | | | | | | | | | | | | | |
// //
// | FUN | | | | | | | | | | | | | |
//
// =)
//
//
// | or | | | | | | | | | | |
// //
// | | DIE ! ! ! | | | | | | | | | | |# | | | |
//
//
// ! | | | | | | | | | | | |
//
// | | !
//
// | | | | | | | | | | |
// | ! |
//
// | | | | | | | | | | | | | |
// | | | !
// | | | | | | | | | | | | | | | | | |
// | | | | | | | | | | | | | | |
//
// | | | | | | | | | | |
// | | | | | | | | | | | | | | | | |
//
// | |
// | | | | | | | | | | | | | | | |
// | | ! | | | | | | | | | | | |
//
//___ ____ _ _ _ ____ ____ ___ _ ____ _ _ ___
//|__] | | | | | |___ |__/ |__] | |__| |\ | |
//| |__| |_|_| |___ | \ | |___ | | | \| |
//OPENING | https://www.youtube.com/watch?v=_85LaeTCtV8 :3
/*
___ ____ ___ ___ ____ ____ _ _ ____ ____ ____ _ _ _ _ ___
___| |___ | | |__] |__| | |_/ | __ |__/ | | | | |\ | | \
___| |___| |___| |__] | | |___ | \_ |__] | \ |__| |__| | \| |__/
*/
import * as THREE from "https://cdn.skypack.dev/three@0.130.0";
import { OrbitControls } from "https://cdn.skypack.dev/three@0.130.0/examples/jsm/controls/OrbitControls.js";
let intro360_scene, intro360_camera, intro360_renderer, intro360_controls, intro360_textureLoader, intro360_sphere1, intro360_sphere2, intro360_material1, intro360_material2;
const intro360_images = ['img/sky.jpg', 'img/sky2.jpg', 'img/sky3.jpg'];
let intro360_index = 0;
function BG360() {
// Créer une scène
intro360_scene = new THREE.Scene();
// Créer une caméra
intro360_camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
intro360_camera.position.z = 1;
// Créer un renderer
intro360_renderer = new THREE.WebGLRenderer();
intro360_renderer.setSize(window.innerWidth, window.innerHeight);
document.getElementById('intro360').appendChild(intro360_renderer.domElement);
// Créer des contrôles pour gérer les événements de la souris
intro360_controls = new OrbitControls(intro360_camera, intro360_renderer.domElement);
// Créer des contrôles pour gérer les événements de la souris
intro360_controls = new OrbitControls(intro360_camera, intro360_renderer.domElement);
// Créer un chargeur de texture pour charger nos images
intro360_textureLoader = new THREE.TextureLoader();
// Créer une sphère
const geometry = new THREE.SphereGeometry(5, 32, 32);
// Créer les matériaux avec la première texture
intro360_material1 = new THREE.MeshBasicMaterial({color: 0xffffff, side: THREE.BackSide, transparent: true, opacity: 1});
intro360_material2 = new THREE.MeshBasicMaterial({color: 0xffffff, side: THREE.BackSide, transparent: true, opacity: 0});
intro360_sphere1 = new THREE.Mesh(geometry, intro360_material1);
intro360_scene.add(intro360_sphere1);
intro360_sphere2 = new THREE.Mesh(geometry, intro360_material2);
intro360_scene.add(intro360_sphere2);
// Lorsque la fenêtre est redimensionnée
window.addEventListener('resize', () => {
// Mettre à jour l'aspect de la caméra
intro360_camera.aspect = window.innerWidth / window.innerHeight;
// Mettre à jour la matrice de projection de la caméra
intro360_camera.updateProjectionMatrix();
// Mettre à jour la taille du rendu
intro360_renderer.setSize(window.innerWidth, window.innerHeight);
}, false);
// Charger la première image
intro360_loadNextImage();
function intro360_loadNextImage() {
// Swap spheres and materials
[intro360_sphere1, intro360_sphere2] = [intro360_sphere2, intro360_sphere1];
[intro360_material1, intro360_material2] = [intro360_material2, intro360_material1];
intro360_textureLoader.load(intro360_images[intro360_index], function(texture) {
intro360_material1.map = texture;
intro360_material1.needsUpdate = true;
fadeTransition(8000);
});
// Passer à l'image suivante
intro360_index = (intro360_index + 1) % intro360_images.length;
// Charger la prochaine image après un délai aléatoire entre 100000 et 130000
setTimeout(intro360_loadNextImage, Math.random() * 100000 + 130000);
}
function fadeTransition(duration) {
const startTime = Date.now();
const animateFade = function() {
const elapsed = Date.now() - startTime;
const progress = elapsed / duration;
if(progress < 1) {
intro360_material1.opacity = progress;
intro360_material2.opacity = 1 - progress;
requestAnimationFrame(animateFade);
} else {
intro360_material1.opacity = 1;
intro360_material2.opacity = 0;
}
}
animateFade();
}
function intro360_animate() {
requestAnimationFrame(intro360_animate);
// Faire tourner la sphère
intro360_sphere1.rotation.y += 0.001;
intro360_sphere2.rotation.y += 0.001;
intro360_renderer.render(intro360_scene, intro360_camera);
}
intro360_animate();
}
BG360();
/*
____ _ _ _ ____ ____ ___ _ _ _ ____
|___ \/ | | | |__| | \ | |\ | | __
| _/\_ |___ |__| | | |__/ | | \| |__]
import $ from 'https://code.jquery.com/jquery-3.7.0.js';
*/
function loadPage() {
$(document).ready(function () {
var loadingDuration = 1000;
var intervalDuration = 10;
jQuery(function($) {
// DOM elements used during the loading sequence
var loading = $('#loading');
var blackRectangle = $('#blackRectangle');
var glitchText = $('#glitchText');
var whiteScreen = $('#whiteScreen');
// Calculate how many intervals will run
var intervalsCount = loadingDuration / intervalDuration;
// Calculate how much the height should increase per interval (in %)
var increment = 100 / intervalsCount;
// Start interval animation
var intervalId = setInterval(function() {
// Get current height of the black rectangle (in %)
var currentHeight = blackRectangle.height();
// Compute next height value
var newHeight = currentHeight + increment;
// Prevent exceeding 100%
if (newHeight > 100) newHeight = 100;
// Apply new height
blackRectangle.css('height', newHeight + '%');
// When the rectangle reaches full height
if (newHeight >= 100) {
// Stop the interval loop
clearInterval(intervalId);
// First transition phase
setTimeout(function() {
// Move the black rectangle out of view
blackRectangle.css('bottom', '100%');
// Fade out white overlay
whiteScreen.css('opacity', 0);
// Animate glitch text shrink and fade
glitchText.css({
transition: 'font-size 2s, opacity 0.3s',
fontSize: '4vw',
opacity: 0
});
}, 1000);
// Final cleanup phase
setTimeout(function() {
// Remove white screen from DOM
whiteScreen.remove();
// Reveal services block
$('#servicesBlock').css('bottom', '0%');
loading.remove();
}, 1600);
}
}, intervalDuration);
});
});
}
function leavingPage() {
let rectangles = Array.from(document.getElementsByClassName('overlay-rectangle'));
// Start the white rectangle moving first
rectangles[rectangles.length - 1].style.transition = `top 0.7s`;
rectangles[rectangles.length - 1].style.top = '0';
// Start each black rectangle moving after a delay
for (let i = 0; i < rectangles.length - 1; i++) {
setTimeout(function() {
rectangles[i].style.transition = `top 1s`;
rectangles[i].style.top = '100vh';
}, 200 * i); // Delay each rectangle by 0.5s
}
}
function endPage() {
// Select all links that should trigger the leaving animation
let links = document.getElementsByClassName('leaving');
// Loop through each matching link
for (let i = 0; i < links.length; i++) {
// Attach click event listener
links[i].addEventListener('click', function(event) {
// Prevent the default immediate navigation behavior
event.preventDefault();
// Store the target URL from the href attribute
let href = this.getAttribute('href');
leavingPage();
setTimeout(function() {
// Redirect to the original link destination
window.location.href = href;
}, 1333);
});
}
}
loadPage();
endPage();
/*
____ ____ ____ ___
| |__| |__/ | \
|___ | | | \ |__/
import $ from 'https://code.jquery.com/jquery-3.7.0.js';
*/
$(document).ready(function() {
if (isMobile()) return;
$(".card").on({
mousemove: function(e) {
if (isMobile()) return;
const card = this;
const glowElement = card.querySelector('.glowMou, .glowMouCrea, .glowMouTech');
const cardRect = card.getBoundingClientRect();
const offsetX = e.clientX - cardRect.left;
const offsetY = e.clientY - cardRect.top;
const diffX = (cardRect.width / 2) - offsetX;
const diffY = (cardRect.height / 2) - offsetY;
const rotateY = (2 * diffX) / (cardRect.width / 2);
const rotateX = (2 * diffY) / (cardRect.height / 2);
const invertRotateX = -rotateX;
card.style.transform = `rotateX(${invertRotateX}deg) rotateY(${rotateY}deg)`;
glowElement.style.setProperty('--mouse-x', `${offsetX}px`);
glowElement.style.setProperty('--mouse-y', `${offsetY}px`);
glowElement.classList.add("glowing");
},
mouseleave: function() {
if (isMobile()) return;
const card = this;
card.style.transform = "";
const glowElement = card.querySelector('.glowMou, .glowMouCrea, .glowMouTech');
glowElement.classList.remove("glowing");
}
});
});
/*
_ _ ____ _ _ ____ ____
|\/| | | | | [__ |___
| | |__| |__| ___] |___
*/
function isMobile() {
// Basic UA-based mobile detection
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini|Mobile|mobile|CriOS|IEMobile/i.test(navigator.userAgent);
}
if (!isMobile()) {
// Pointer state (position, velocity, size/opacity targets)
let mouseX = 0, mouseY = 0, lastMouseX = 0, lastMouseY = 0, speedX = 0, speedY = 0;
let posX = 0, posY = 0, size = 28, opacity = 1;
let targetSize = 28, targetOpacity = 1;
// Mode flags
let isRectangle = false, isScrollFastActivated = false;
// Rotation animation state
let rotation = 0;
let animateRotation = false;
const customPointer = document.getElementById('customPointer');
function animouse() {
if (isMobile()) return;
// Smoothing factor (slower when hidden / fast-scroll mode)
const factor = isScrollFastActivated || (opacity < 0.1 && targetOpacity < 0.1) ? 0.05 : 0.5;
posX += (mouseX - posX) * factor;
posY += (mouseY - posY) * factor;
size += (targetSize - size) * factor;
opacity += (targetOpacity - opacity) * factor;
// One-shot rotation burst
if (animateRotation) {
rotation += 6;
if (rotation >= 360) {
rotation = 0;
animateRotation = false;
}
}
// Stretch pointer based on mouse speed
const newSize = Math.max(size, size + Math.sqrt(speedX * speedX + speedY * speedY) / 8);
const width = newSize + Math.abs(speedX);
const height = newSize + Math.abs(speedY);
customPointer.style.top = `${posY - newSize / 2}px`;
customPointer.style.left = `${posX - newSize / 2}px`;
customPointer.style.width = `${width}px`;
customPointer.style.height = `${height}px`;
customPointer.style.opacity = `${opacity}`;
customPointer.style.transform = `rotate(${rotation}deg)`;
requestAnimationFrame(animouse);
}
// Track mouse position + speed
document.addEventListener('mousemove', (event) => {
if (isMobile()) return;
mouseX = event.clientX;
mouseY = event.clientY;
speedX = mouseX - lastMouseX;
speedY = mouseY - lastMouseY;
lastMouseX = mouseX;
lastMouseY = mouseY;
});
// Middle mouse button: temporary hide pointer (fast scroll)
document.addEventListener('mousedown', (event) => {
if (isMobile()) return;
if (event.button === 1) {
isScrollFastActivated = true;
targetSize = 0;
targetOpacity = 0;
}
});
document.addEventListener('mouseup', (event) => {
if (isMobile()) return;
if (event.button === 1) {
isScrollFastActivated = false;
targetSize = 28;
targetOpacity = 1;
}
});
// Hide on leaving window, restore on re-enter
document.addEventListener('mouseleave', () => {
if (isMobile()) return;
targetSize = 0;
targetOpacity = 0;
});
document.addEventListener('mouseenter', () => {
if (isMobile()) return;
targetSize = 28;
targetOpacity = 1;
});
// Click: toggle rectangle mode + trigger rotation burst
document.addEventListener('click', () => {
if (isMobile()) return;
isRectangle = !isRectangle;
customPointer.classList.toggle('mouRectangle');
animateRotation = true;
});
// Hover feedback on clickable elements
const clickableElements = document.querySelectorAll('a, button');
clickableElements.forEach((element) => {
element.addEventListener('mouseover', () => {
if (isMobile()) return;
targetSize = 12;
});
element.addEventListener('mouseout', () => {
if (isMobile()) return;
targetSize = 28;
});
});
// Start animation loop
animouse();
}
/*
____ _ _ ____ ____ _ _ ___ ___ ____ ___ ____ _ _ ___
|___ \/ | |__/ \_/ |__] | | | | |___ \/ |
| _/\_ |___ | \ | | | |__| | |___ _/\_ |
*/
// Select all elements with the class "auto-matrix"
const autoMatrixButtons = document.querySelectorAll('.auto-matrix');
// Iterate over each selected button
autoMatrixButtons.forEach((button) => {
// Adjustable variables
let intervalTime = 50; // Time for interval
let delayTime = 20; // Time delay for setTimeout
let loopTimes = 2; // Number of times the loop will run
// Original text of the button
const originalText = button.textContent;
// Variable to hold the interval instance
let decryptInterval;
// Apply multipliers based on classes present in the button
if(button.classList.contains('x2')) { // If class 'x2' is present
intervalTime /= 2; // Halve the intervalTime
delayTime /= 2; // Halve the delayTime
loopTimes *= 2; // Double the loopTimes
}
if(button.classList.contains('x4')) { // If class 'x4' is present
intervalTime /= 4; // Quarter the intervalTime
delayTime /= 4; // Quarter the delayTime
loopTimes *= 4; // Quadruple the loopTimes
}
if(button.classList.contains('x8')) { // If class 'x8' is present
intervalTime /= 8; // Divide intervalTime by 8
delayTime /= 8; // Divide delayTime by 8
loopTimes *= 8; // Multiply loopTimes by 8
}
function autoMatrix() {
// If there's already an interval running, clear it
if (decryptInterval) {
clearInterval(decryptInterval);
}
// Get the original text data attribute if exists, else get current textContent
const decryptedText = button.dataset.originalText || button.textContent;
// Start the textContent as '_'
button.textContent = '_';
// Initial variables for the decryption process
let decryptedIndex = 0;
let loopCounter = 0;
// Start an interval with the adjusted intervalTime
decryptInterval = setInterval(() => {
// If the loopCounter is less than the adjusted loopTimes
if (loopCounter < loopTimes) {
// Delay the execution of the function inside setTimeout by delayTime
setTimeout(() => {
const encryptedChar = getRandomChar(); // Get a random character
// Replace the last character of the textContent with the random character
button.textContent = button.textContent.slice(0, -1) + encryptedChar;
}, delayTime);
loopCounter++;
}
// If the decrypted index is less than the length of the decryptedText
else if (decryptedIndex < decryptedText.length) {
// Remove the last character from the textContent
button.textContent = button.textContent.slice(0, -1);
// Get the decrypted character from the decryptedText by index
const decryptedChar = decryptedText[decryptedIndex];
// Append the decrypted character and '█' to the textContent
button.textContent += decryptedChar;
button.textContent += "█";
// Increase the decrypted index and reset the loop counter
decryptedIndex++;
loopCounter = 0;
}
// If the entire decryptedText has been processed
else {
// Remove the last character from the textContent
button.textContent = button.textContent.slice(0, -1);
// Clear the running interval and restore the original text
clearInterval(decryptInterval);
button.textContent = originalText;
}
}, intervalTime);
}
// Start the decryption process
autoMatrix();
});
function getRandomChar() {
const chars = 'Σ_—RΣT-9uΣ5T';
const randomIndex = Math.floor(Math.random() * chars.length);
return chars[randomIndex];
}
//____ ____ _ _ ____ ____ ____ ___ ____ ____ ____
//| __ |___ |\ | |___ |__/ |__| | | | |__/ [__
//|__] |___ | \| |___ | \ | | | |__| | \ ___]
// Core UI elements
const generatorForm = document.getElementById('generator-form');
const urlInput = document.getElementById('url-input');
const pageContent = document.getElementById('page-content');
const generatedBlock = document.getElementById('generated');
// Output containers
const qrCodeContainer = document.getElementById('qr-code-container');
const textContainer = document.getElementById('text-container');
const barcodeContainer = document.getElementById('barcode-container');
// Status / feedback
const formMessage = document.getElementById('form-message');
// Matrix text config
const memePhrase = '⚔️ Bruh have to save the generated ⚔️';
let matrixWriteInterval;
// Bind form submit
if (generatorForm) {
generatorForm.addEventListener('submit', generateImages);
}
// Bind Enter key submit (input only)
if (urlInput) {
urlInput.addEventListener('keydown', (event) => {
if (event.key === 'Enter') {
event.preventDefault();
generateImages(event);
}
});
}
// Enable horizontal wheel scrolling on media containers
if (qrCodeContainer) {
enableHorizontalWheel(qrCodeContainer);
}
if (barcodeContainer) {
enableHorizontalWheel(barcodeContainer);
}
// Collapse expanded layout on mobile breakpoint
window.addEventListener('resize', () => {
if (!pageContent) return;
if (isMobileViewport()) {
pageContent.classList.remove('card-expanded');
}
});
function generateImages(event) {
if (event) event.preventDefault();
const url = urlInput.value.trim();
const cardContent = document.querySelector('.card-content');
// Validate input
if (!url) {
setFormMessage('Enter URL / text before Generate.');
return;
}
setFormMessage('');
// Expand card on desktop
if (pageContent && !isMobileViewport()) {
pageContent.classList.add('card-expanded');
}
// Reset outputs + states
qrCodeContainer.innerHTML = '';
textContainer.innerHTML = '';
barcodeContainer.innerHTML = '';
qrCodeContainer.classList.remove('media-ready');
textContainer.classList.remove('media-ready', 'matrix-writing');
barcodeContainer.classList.remove('media-ready');
// Replay "expanded" animation
generatedBlock.classList.remove('expanded');
void generatedBlock.offsetWidth;
generatedBlock.classList.add('expanded');
// Responsive QR sizing based on card width and viewport height
const qrSize = Math.max(
136,
Math.min(
220,
Math.floor(cardContent.offsetWidth * 0.24),
Math.floor(window.innerHeight * 0.25)
)
);
// QR Code generation (if lib is loaded)
if (typeof QRCode === 'function') {
const qrWrap = document.createElement('div');
qrWrap.className = 'qr-wrap';
qrCodeContainer.appendChild(qrWrap);
new QRCode(qrWrap, {
text: url,
width: qrSize,
height: qrSize,
colorDark: '#14213d',
colorLight: '#ffffff',
correctLevel: QRCode.CorrectLevel.M
});
// Attach download handler once the QR node exists
setTimeout(() => {
const qrElement = qrWrap.querySelector('img, canvas');
if (qrElement) {
qrCodeContainer.onclick = () => downloadQrElement(qrElement);
qrElement.addEventListener('click', () => downloadQrElement(qrElement));
}
centerScrollableX(qrCodeContainer);
qrCodeContainer.classList.add('media-ready');
}, 130);
}
// Matrix writing effect for the text block
runMatrixWrite(textContainer, memePhrase);
// Barcode generation (if lib is loaded)
if (typeof JsBarcode === 'function') {
const barcodeCanvas = document.createElement('canvas');
const barcodeWrap = document.createElement('div');
// Adapt barcode density to input length
const barcodeLength = url.length;
const barWidth =
barcodeLength > 160 ? 0.55 :
barcodeLength > 110 ? 0.72 :
barcodeLength > 70 ? 0.9 : 1.2;
const barcodeHeight = Math.max(70, Math.floor(qrSize * 0.42));
barcodeWrap.className = 'barcode-wrap';
try {
JsBarcode(barcodeCanvas, url, {
format: 'CODE128',
lineColor: '#14213d',
width: barWidth,
height: barcodeHeight,
displayValue: true,
font: 'Krona One',
fontSize: 11,
margin: 12,
background: '#ffffff'
});
barcodeWrap.appendChild(barcodeCanvas);
barcodeContainer.appendChild(barcodeWrap);
// Click to download
barcodeCanvas.addEventListener('click', () => {
downloadCanvasElement(barcodeCanvas, 'barcode.png');
});
barcodeContainer.onclick = () => {
downloadCanvasElement(barcodeCanvas, 'barcode.png');
};
setTimeout(() => {
centerScrollableX(barcodeContainer);
barcodeContainer.classList.add('media-ready');
}, 230);
} catch (error) {
setFormMessage('Barcode generation failed. Try shorter text.');
}
}
}
function isMobileViewport() {
// Viewport breakpoint (CSS should match this)
return window.matchMedia('(max-width: 570px)').matches;
}
function enableHorizontalWheel(element) {
// Convert vertical wheel to horizontal scroll when overflow exists
element.addEventListener('wheel', (event) => {
if (element.scrollWidth <= element.clientWidth) return;
if (Math.abs(event.deltaY) >= Math.abs(event.deltaX)) {
event.preventDefault();
element.scrollLeft += event.deltaY;
}
}, { passive: false });
}
function centerScrollableX(element) {
// Center content when container is horizontally scrollable
requestAnimationFrame(() => {
if (element.scrollWidth > element.clientWidth) {
element.scrollLeft = Math.floor((element.scrollWidth - element.clientWidth) / 2);
} else {
element.scrollLeft = 0;
}
});
}
function runMatrixWrite(element, finalText) {
// Restart if already running
if (matrixWriteInterval) clearInterval(matrixWriteInterval);
const targetChars = Array.from(finalText);
let revealIndex = 0;
let randomLoops = 0;
element.classList.add('matrix-writing');
element.textContent = '';
matrixWriteInterval = setInterval(() => {
const fixed = targetChars.slice(0, revealIndex).join('');
const randomTailLength = Math.min(3, targetChars.length - revealIndex);
const randomTail = Array.from({ length: randomTailLength }, () => getMatrixChar()).join('');
element.textContent = fixed + randomTail;
randomLoops += 1;
// Reveal one more character every other tick
if (randomLoops % 2 === 0 && revealIndex < targetChars.length) {
revealIndex += 1;
}
// Finish
if (revealIndex >= targetChars.length) {
clearInterval(matrixWriteInterval);
element.classList.remove('matrix-writing');
element.textContent = finalText;
element.classList.add('media-ready');
}
}, 42);
}
function getMatrixChar() {
// Random glyphs used for the matrix tail
const chars = 'Σ_—RΣT-9uΣ5T█▒';
return chars[Math.floor(Math.random() * chars.length)];
}
function setFormMessage(message) {
if (!formMessage) return;
formMessage.textContent = message;
}
function downloadQrElement(qrElement) {
if (!qrElement) return;
// QRCode lib may output either canvas or img
if (qrElement.tagName === 'CANVAS') {
downloadCanvasElement(qrElement, 'QRCode.png');
return;
}
if (qrElement.tagName === 'IMG' && qrElement.src) {
triggerDownload(qrElement.src, 'QRCode.png');
}
}
function downloadCanvasElement(canvasElement, fileName) {
if (!canvasElement || canvasElement.tagName !== 'CANVAS') return;
const dataURL = canvasElement.toDataURL('image/png');
triggerDownload(dataURL, fileName);
}
function triggerDownload(href, filename, revokeAfterDownload = false) {
// Create a temporary <a> and click it to download
const link = document.createElement('a');
link.href = href;
link.download = filename;
link.rel = 'noopener';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
if (revokeAfterDownload) {
setTimeout(() => URL.revokeObjectURL(href), 1200);
}
}