-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurlmkr.html
1854 lines (1559 loc) · 76 KB
/
urlmkr.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>URLmkr</title>
<!-- Favicon for most browsers -->
<link rel="icon" href="/img/favicon_io/favicon.ico" type="image/x-icon">
<!-- PNG icons for better resolution -->
<link rel="icon" type="image/png" sizes="32x32" href="/img/favicon_io/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/img/favicon_io/favicon-16x16.png">
<!-- Apple Touch Icon (for iOS) -->
<link rel="apple-touch-icon" href="/img/favicon_io/apple-touch-icon.png">
<!-- Web Manifest (for PWAs) -->
<link rel="manifest" href="/img/favicon_io/site.webmanifest">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/easy.qrcode.min.js"></script>
<link rel="stylesheet" href="styles.css">
<script src="urlmkrAgreement.js"></script>
<script src="backgroundImages.js"></script>
<script src="crypto-js.min.js"></script>
<script src="dec.js"></script>
<script src="enc.js"></script>
<script src="bech32.js"></script>
<script src="fontList.js"></script>
<!-- <script src="footer.js"></script> // IS AT THE BOTTOM-->
<script src="font.js"></script>
</head>
<style>
</style>
<body>
<div id="dim-overlay" class="dim-overlay"></div>
<div class="url-output-container">
<div class="url-output" id="url_output"></div>
<div class="url-output" id="byte_counter"></div>
<div class="error-message" id="error_message"></div>
<div class="warning-message" id="warning_message"></div>
<div class="info-message" id="info_message"></div>
<button class="copy-button" id="copy_button">Copy URL</button>
<button class="copy-button" id="qr_button">Create QR Code</button>
</div>
<div id="agreementModal" class="agreement-modal">
<div class="agreement-modal-content">
<h4>Terms and Conditions</h4>
<div class="agreement-modal-text" id="agreementText">
<!-- Text injected with irlmkrAgreement -->
</div>
<div class="modal-buttons">
<button id="declineAgreement">Decline</button>
<button id="acceptAgreement" disabled>Accept</button>
</div>
</div>
</div>
<!-- QR Code Modal -->
<div id="qr-modal" style="display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.8); justify-content: center; align-items: center;">
<div style="z-index: 1005 !important; background: #fff; padding: 20px; border-radius: 8px; text-align: center;">
<div id="qr-code"></div>
<div id="qr-title">Spread it!</div>
<button id="save_qr_button" class="copy-button">Save QR Code</button>
<button id="share_qr_button" class="copy-button">Share QR Code</button>
<button id="close_qr_button" class="copy-button" style="background: #ff4d4d;">Close</button>
</div>
</div>
<!-- avatar style selection modal -->
<div id="avatar-modal" class="modal avatar-modal" style="display: none;">
<div class="avatar-modal-content">
<h6 class="avatars-attribute">Avatars provided by <a href="https://www.dicebear.com" target="_blank">dicebear.com</a></h6>
<span class="close-modal">×</span>
<div id="avatar-grid" class="avatar-grid"></div>
</div>
</div>
<!-- font modal -->
<div id="font-modal" class="modal font-modal">
<div class="font-modal-content">
<span class="close-modal">×</span>
<div id="font-grid" class="font-grid"></div>
</div>
</div>
<!-- Background Modal -->
<div id="background-modal" class="modal background-modal">
<div class="background-modal-content">
<span class="close-modal">×</span>
<div class="background-grid" id="background-grid"></div>
<!-- The color picker and URL input will be dynamically added here -->
</div>
</div>
<!-- shortened URL modal prompt -->
<div id="shorten-modal" style="display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.8); justify-content: center; align-items: center; z-index: 9999;">
<div style="background: rgb(44, 44, 44); padding: 20px; border-radius: 8px; text-align: center; width: 70vwpx;">
<p style="color: white;">Do you want to create a short link, or leave original as is before copying?</p>
<div class="button-container" style="display: flex; justify-content: space-between; margin-top: 20px;">
<button id="modal-yes" class="copy-button" style="flex: 1; margin-right: 10px;">Short</button>
<button id="modal-no" class="copy-button" style="flex: 1; margin-left: 10px;">Original</button>
</div>
</div>
</div>
<div class="maker-title-and-what">
<div class="maker-title">
<h1><span style="font-size: 0.9rem;">postanote.org </span> URL Maker</h1>
</div>
<div class="maker-subtitle">
<h3 id="toggle-description">What this tool does?</h3>
<div class="maker-what-text hidden">
<p>This tool allows you to easily create a custom URL that links to a customized postanote.org website by adjusting the selected parameters.
You can choose an NTAG type with the appropriate memory size or select "no NTAG" if you plan to use a QR code instead. Optionally, you can:</p>
<ul>- Add a title and a subtitle.</ul>
<ul>- Include a custom avatar for users.</ul>
<ul>- Lock a message or leave it open for end users to post freely.</ul>
<ul>- Set a character limit for user submissions.</ul>
<ul>- Add hashtags for better later discoverability on Nostr.</ul>
<ul>- Specify custom Nostr relays where the notes will be posted by end users through your custom link.</ul>
<ul>- Additionally, you can encrypt the URL so that only the correct key can unlock it. (This is a powerful feature and should not be used for illegal purposes.)</ul>
<p>The tool will automatically generate and display the URL, which can then be written to an NTAG using various NFC applications or converted into a QR code to share with others.
This tool also includes a built-in URL shortener. The corresponding long URL is stored on my server, but the original (non-shortened) URL is not tracked. Keep this in mind when using the tool.</p>
</div>
</div>
</div>
<hr class="hrLine">
<div class="form-group">
<label>NTAG Type:</label>
<div class="ntag-group">
<label for="ntag_none">
No NTAG (∞) <input type="radio" id="ntag_none" name="ntag_type" value="none">
</label>
<label for="ntag203">
* 203 (144 B) <input type="radio" id="ntag203" name="ntag_type" value="203" data-bytes="137">
</label>
<label for="ntag213">
* 213 (144 B) <input type="radio" id="ntag213" name="ntag_type" value="213" data-bytes="137">
</label>
<label for="ntag215">
* 215 (504 B) <input type="radio" id="ntag215" name="ntag_type" value="215" data-bytes="492">
</label>
<label for="ntag216">
* 216 (888 B)<input type="radio" id="ntag216" name="ntag_type" value="216" data-bytes="868">
</label>
<label for="ntag413DNA">
* 413 DNA (888 B) <input type="radio" id="ntag413DNA" name="ntag_type" value="413DNA" data-bytes="398">
</label>
<label for="ntag424DNA">
* 424 DNA (888 B)<input type="radio" id="ntag424DNA" name="ntag_type" value="424DNA" data-bytes="916">
</label>
<!-- <label for="ntag_i2c_1K">
* I²C 1K (888 B) <input type="radio" id="ntag_i2c_1K" name="ntag_type" value="I2C_1K" data-bytes="868">
</label>
<label for="ntag216">
* I²C 2K (1904 B)<input type="radio" id="ntag_i2c_2K" name="ntag_type" value="I2C_2K" data-bytes="1900">
</label> -->
</div>
</div>
<hr class="hrLine">
<div class="form-group">
<label for="include_avatar" class="avatar-label-container">
<span id="avatar-preview-container"></span>
<span id="avatar-label">Avatar Styles</span>
<input type="checkbox" id="include_avatar">
</label>
</div>
<hr class="hrLine">
<div class="form-group">
<label for="include_ln">
Add Lightning Address <span style="font-size: 0.35em; padding: 10px;">LUD-16 only</span> <input type="checkbox" id="include_ln">
</label>
<input type="text" id="ln_input" placeholder="[email protected]" disabled>
</div>
<hr class="hrLine">
<div class="form-group">
<label for="include_font">
Choose Font <input type="checkbox" id="include_font">
</label>
<div id="font-container" class="font-container"></div>
</div>
<hr class="hrLine">
<div class="form-group">
<label for="include_background">
Include Background <input type="checkbox" id="include_background">
</label>
<div id="background-container" class="background-container">
</div>
</div>
<hr class="hrLine">
<div class="form-group">
<label for="include_h1">
Add Custom Title (h1) <input type="checkbox" id="include_h1">
</label>
<input type="text" id="h1_input" placeholder="Title" disabled>
<hr class="hrLine">
<label for="include_h3">
Add Custom Subtitle (h3) <input type="checkbox" id="include_h3">
</label>
<input type="text" id="h3_input" placeholder="Subtitle" disabled>
<hr class="hrLine">
<label for="include_p">
Add longer text (p) <input type="checkbox" id="include_p">
</label>
<textarea id="p_input" placeholder="Let me tell you a story..." disabled></textarea>
</div>
<hr class="hrLine">
<div class="form-group">
<label for="include_message">
Include Fixed Custom Message <input type="checkbox" id="include_message">
</label>
<textarea id="message_input" placeholder="Enter a preset message here; it will be fixed and uneditable by the end user." disabled></textarea>
</div>
<div class="form-group">
<label for="custom_characters">
Max Characters Allowed In a Message (default is 280) <input type="checkbox" id="custom_characters">
</label>
<input type="number" id="characters_input" placeholder="(1-5000)" min="1" max="5000" disabled>
</div>
<!-- <hr class="hrLine">
<div class="form-group">
<label for="prevent_reuse">
Prevent Reusing IDs
<input type="checkbox" id="prevent_reuse" title="This will prevent posting notes more than 1 time per pubKey. Use with caution because it deletes the current privKey from local storage">
</label>
</div> -->
<hr class="hrLine">
<div class="form-group">
<label for="hashtag1">Add Hashtags:</label>
<input type="text" id="hashtag1" placeholder="1'st (do NOT include #)">
<input type="text" id="hashtag2" placeholder="2'nd (do NOT include #)">
<input type="text" id="hashtag3" placeholder="3'rd (do NOT include #)">
</div>
<hr class="hrLine">
<div class="form-group">
<label for="include_relays">
Select Custom or Random Relays<input type="checkbox" id="include_relays" title="if leaved empty, the default relays (greyed relays in the input) will be used by the main website where the user will post the note">
</label>
<div class="relay-group">
<input type="text" id="relay1" placeholder="wss://relay.nostr.band" disabled>
<input type="radio" id="random1" name="random_relay1" title="Clicking this will chose random online relays from the nostr.watch" disabled> <small>random</small>
</div>
<div class="relay-group">
<input type="text" id="relay2" placeholder="wss://relay.damus.io" disabled>
<input type="radio" id="random2" name="random_relay2" title="Clicking this will chose random online relays from the nostr.watch" disabled> <small>random</small>
</div>
<div class="relay-group">
<input type="text" id="relay3" placeholder="wss://njump.me" disabled>
<input type="radio" id="random3" name="random_relay3" title="Clicking this will chose random online relays from the nostr.watch" disabled> <small>random</small>
</div>
<div class="relay-group">
<input type="text" id="relay4" placeholder="wss://relay.snort.social" disabled>
<input type="radio" id="random4" name="random_relay4" title="Clicking this will chose random online relays from the nostr.watch" disabled> <small>random</small>
</div>
<div class="relay-group">
<input type="text" id="relay5" placeholder="wss://nos.lol" disabled>
<input type="radio" id="random5" name="random_relay5" title="Clicking this will chose random online relays from the nostr.watch" disabled> <small>random</small>
</div>
</div>
<div class="form-group">
<label for="encrypt_url">Encrypt URL with a password:
<input type="checkbox" id="encrypt_url">
</label>
<label for="encryption_password">Your URL will only be accessible with a password</label>
<div class="password-container">
<input type="password" id="encryption_password" placeholder="Enter password" disabled>
<span id="toggle_password" class="toggle-password">👁️</span>
</div>
<p id="password_strength" class="password-strength"> </p>
<label for="password_hint">
Add a password hint
<input type="checkbox" id="enable_hint">
</label>
<input type="text" id="password_hint" placeholder="Enter password hint" disabled>
<button id="toggle_encryption" disabled>Encrypt</button>
</div>
<footer class="footerStatic">
<a href="about.html">About</a> |
<a href="FAQ.html">FAQ</a> |
<a href="urlmkr.html">URLmkr</a>
<!-- <button id="showHistoryBtn" title="a History data of all the posted notes from this device">Show History</button> -->
</footer>
<script>
const includeFontCheckbox = document.getElementById('include_font');
const fontModal = document.getElementById('font-modal');
const fontGrid = document.getElementById('font-grid');
let selectedFontIndex = localStorage.getItem('selectedFontIndex') || null; // Ensure it's null by default
// const preventReuseCheckbox = document.getElementById('prevent_reuse'); // Get the checkbox
const ntagRadios = document.querySelectorAll('input[name="ntag_type"]');
const includeH1Checkbox = document.getElementById('include_h1');
const includeH3Checkbox = document.getElementById('include_h3');
const include_p_Checkbox = document.getElementById('include_p');
const includeMessageCheckbox = document.getElementById('include_message');
const includeRelaysCheckbox = document.getElementById('include_relays');
const customCharactersCheckbox = document.getElementById('custom_characters');
const h1Input = document.getElementById('h1_input');
const h3Input = document.getElementById('h3_input');
const p_Input = document.getElementById('p_input');
const messageInput = document.getElementById('message_input');
const charactersInput = document.getElementById('characters_input');
const hashtagInputs = [document.getElementById('hashtag1'), document.getElementById('hashtag2'), document.getElementById('hashtag3')];
const relayInputs = [document.getElementById('relay1'), document.getElementById('relay2'), document.getElementById('relay3'), document.getElementById('relay4'), document.getElementById('relay5')];
const randomRelayButtons = [document.getElementById('random1'), document.getElementById('random2'), document.getElementById('random3'), document.getElementById('random4'), document.getElementById('random5')];
const urlOutput = document.getElementById('url_output');
const byteCounter = document.getElementById('byte_counter');
const errorMessage = document.getElementById('error_message');
const warningMessage = document.getElementById('warning_message');
const infoMessage = document.getElementById('info_message');
const copyButton = document.getElementById('copy_button');
let relayList = [];
let maxBytes = 0;
// Background and font modals
const includeBackgroundCheckbox = document.getElementById('include_background');
const backgroundModal = document.getElementById('background-modal');
const backgroundGrid = document.getElementById('background-grid');
const closeModal = document.querySelector('.close-modal');
let selectedBackgroundIndex = null;
const solidColorPicker = document.getElementById('solid-color-picker');
const customUrlInput = document.getElementById('custom-background-url');
// avatar styles
const includeAvatarCheckbox = document.getElementById('include_avatar');
const avatarModal = document.getElementById('avatar-modal');
const avatarGrid = document.getElementById('avatar-grid');
const avatarLabel = document.getElementById('avatar-label');
const avatarPreviewContainer = document.getElementById('avatar-preview-container');
let selectedAvatarIndex = null;
const todaySeed = new Date().toISOString().split('T')[0]; // Seed for consistency
// Enable/Disable LN address input when checkbox is toggled
const includeLnCheckbox = document.getElementById('include_ln');
const lnInput = document.getElementById('ln_input');
let validationTimeout; // for not be banned by their server
// Regex for LUD-16 (email style)
const lud16Regex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
ntagRadios.forEach(radio => {
radio.addEventListener('change', updateURL);
});
// Open modal on checkbox check
includeAvatarCheckbox.addEventListener('change', function () {
if (this.checked) {
avatarModal.style.display = 'block';
loadAvatarGrid();
} else {
avatarModal.style.display = 'none';
resetAvatar();
updateURL();
}
});
const avatarStylesList = {
1: 'croodles',
2: 'adventurer-neutral',
3: 'avataaars',
4: 'avataaars-neutral',
5: 'big-ears',
6: 'big-ears-neutral',
7: 'big-smile',
8: 'bottts',
9: 'bottts-neutral',
10: 'adventurer',
11: 'croodles-neutral',
12: 'fun-emoji',
13: 'icons',
14: 'identicon',
15: 'rings',
16: 'lorelei',
17: 'lorelei-neutral',
18: 'micah',
19: 'miniavs',
20: 'notionists',
21: 'notionists-neutral',
22: 'open-peeps',
23: 'personas',
24: 'pixel-art',
25: 'pixel-art-neutral',
26: 'shapes',
27: 'thumbs',
28: 'dylan',
29: 'glass',
// 30: 'initials'
};
const avatarNames = {
'croodles': 'croodles',
'adventurer-neutral': 'adventurer-neutral',
'avataaars': 'avataaars',
'avataaars-neutral': 'avataaars-neutral',
'big-ears': 'big-ears',
'big-ears-neutral': 'big-ears-neutral',
'big-smile': 'big-smile',
'bottts': 'bottts',
'bottts-neutral': 'bottts-neutral',
'adventurer': 'adventurer',
'croodles-neutral': 'croodles-neutral',
'dylan': 'dylan',
'fun-emoji': 'fun-emoji',
'glass': 'glass',
'icons': 'icons',
'identicon': 'identicon',
'thumbs': 'thumbs',
'lorelei': 'lorelei',
'lorelei-neutral': 'lorelei-neutral',
'micah': 'micah',
'miniavs': 'miniavs',
'notionists': 'notionists',
'notionists-neutral': 'notionists-neutral',
'open-peeps': 'open-peeps',
'personas': 'personas',
'pixel-art': 'pixel-art',
'pixel-art-neutral': 'pixel-art-neutral',
'rings': 'rings',
'shapes': 'shapes'
// 'initials': 'initials',
};
// Open modal on checkbox check
includeAvatarCheckbox.addEventListener('change', function () {
if (this.checked) {
avatarModal.style.display = 'block';
loadAvatarGrid();
} else {
resetAvatar();
updateURL();
}
});
function loadAvatarGrid() {
avatarGrid.innerHTML = ''; // Clear existing avatars
for (const [index, style] of Object.entries(avatarStylesList)) {
const avatarContainer = document.createElement('div');
avatarContainer.classList.add('avatar-container');
const avatarImg = document.createElement('img');
avatarImg.src = `https://api.dicebear.com/9.x/${style}/svg?seed=${todaySeed}`;
avatarImg.alt = avatarNames[style];
avatarImg.title = `https://www.dicebear.com/styles${avatarNames[style]}/`;
avatarImg.classList.add('avatar-preview');
// Avatar name label
const avatarLabel = document.createElement('div');
avatarLabel.classList.add('avatar-label');
avatarLabel.textContent = avatarNames[style];
// Append image and label
avatarContainer.appendChild(avatarImg);
avatarContainer.appendChild(avatarLabel);
// Avatar selection logic
avatarImg.addEventListener('click', () => {
selectedAvatarIndex = index;
avatarModal.style.display = 'none';
// Replace label text with the avatar preview
avatarPreviewContainer.innerHTML = `
<img src="${avatarImg.src}" alt="${avatarNames[style]}" title="${avatarNames[style]}" style="width: 150px; height: 150px; border-radius: 5px;">
`;
// Hide "Avatar Styles" text
document.getElementById('avatar-label').style.display = 'none';
updateURL();
});
avatarGrid.appendChild(avatarContainer);
}
}
// Reset to default when unchecked
function resetAvatar() {
selectedAvatarIndex = null;
// Show "Avatar Styles" and clear avatar preview
avatarLabel.style.display = 'inline'; // Show the label text
avatarPreviewContainer.innerHTML = ''; // Clear the avatar image
updateURL();
}
include_p_Checkbox.addEventListener('change', function () {
p_Input.disabled = !this.checked;
if (this.checked) {
p_Input.style.height = '100vh'; // Resize input box to a larger height
p_Input.style.width = '100%'; // Optional: Adjust width for better input
} else {
p_Input.style.height = 'auto'; // Reset to default size
p_Input.style.width = '50%';
}
});
// Lightning start
// Checkbox Change - Enable/Disable Input
includeLnCheckbox.addEventListener('change', function () {
lnInput.disabled = !this.checked;
lnInput.style.backgroundColor = '';
warningMessage.textContent = '';
if (this.checked) {
lnInput.focus();
lnInput.addEventListener('input', handleLnInputChange);
lnInput.addEventListener('paste', handleLnInputChange);
} else {
lnInput.removeEventListener('input', handleLnInputChange);
lnInput.removeEventListener('paste', handleLnInputChange);
}
// Immediately update the URL when checkbox is toggled
updateURL();
});
// Update URL as the LN address is typed or pasted
function handleLnInputChange() {
updateURL();
if (validationTimeout) clearTimeout(validationTimeout);
validationTimeout = setTimeout(validateLn, 4000); // Debounced Validation
}
// Restrict invalid characters in LN input (no spaces or invalid symbols)
lnInput.addEventListener('keypress', function (event) {
const allowedChars = /^[a-zA-Z0-9._%+@-]+$/;
const key = String.fromCharCode(event.keyCode || event.which);
if (!allowedChars.test(key)) {
event.preventDefault(); // Block invalid characters
warningMessage.textContent = `Invalid character detected: '${key}'`;
warningMessage.style.color = 'orange';
warningMessage.style.fontSize = '0.6rem';
scrollToMessage(warningMessage);
} else {
warningMessage.textContent = ''; // Clear message if valid
}
});
// Prevent pasting invalid characters
lnInput.addEventListener('paste', function (event) {
const pastedText = (event.clipboardData || window.clipboardData).getData('text');
const allowedChars = /^[a-zA-Z0-9._%+@-]+$/;
const invalidChars = pastedText.split('').filter(char => !allowedChars.test(char));
if (invalidChars.length > 0) {
event.preventDefault(); // Block paste if invalid characters are detected
warningMessage.textContent = `Invalid character(s) detected: '${invalidChars.join('')}'. Please paste a valid LN address.`;
warningMessage.style.color = 'orange';
warningMessage.style.fontSize = '0.6rem';
scrollToMessage(warningMessage);
} else {
warningMessage.textContent = ''; // Clear message if valid
}
});
// LUD-16 Validation Handler
async function validateLn() {
const lnAddress = lnInput.value.trim();
if (!lnAddress) {
lnInput.style.backgroundColor = ''; // Reset if empty
warningMessage.textContent = '';
return;
}
lnInput.style.backgroundColor = '#fff7c1'; // Yellow for pending validation
if (lud16Regex.test(lnAddress)) {
const isValid = await validateLud16(lnAddress);
setValidationColor(isValid);
} else {
warningMessage.textContent = 'Invalid LN address format.';
warningMessage.style.color = 'orange';
warningMessage.style.fontSize = '0.6rem';
scrollToMessage(warningMessage); // Scroll to warning message
setValidationColor(false);
}
}
// Set Background Color Based on Validation
function setValidationColor(isValid) {
lnInput.style.backgroundColor = isValid ? '#d4f78c' : '#fbb3ae'; // Green or Red
}
// LUD-16 Validation
async function validateLud16(address) {
const lnAddress = address.trim(); // Trim spaces from input
const [name, domain] = lnAddress.split('@');
// If invalid characters exist, stop further validation
if (!lud16Regex.test(lnAddress)) {
warningMessage.textContent = 'Invalid LN address format.';
warningMessage.style.color = 'orange';
warningMessage.style.fontSize = '0.6rem';
scrollToMessage(warningMessage); // Scroll to warning message
lnInput.style.backgroundColor = '#f9a999'; // Red - Invalid
return false;
}
const url = `https://${domain}/.well-known/lnurlp/${name}`;
try {
const response = await fetch(url);
if (response.status === 404) {
warningMessage.textContent = `Wallet not found at: ${url}`;
warningMessage.style.color = 'orange';
warningMessage.style.fontSize = '0.6rem';
scrollToMessage(warningMessage); // Scroll to warning message
lnInput.style.backgroundColor = '#f9a999'; // Red - Invalid
return false;
}
const data = await response.json();
if (response.ok && data) {
// 1. Check for status: 'OK' first
if (data.status === 'OK') {
infoMessage.textContent = `Wallet verified: ${data.metadata?.[1]?.[1] || 'Valid'}`;
infoMessage.style.color = 'white';
infoMessage.style.fontSize = '0.6rem';
scrollToMessage(infoMessage); // Scroll to warning message
lnInput.style.backgroundColor = '#d4fa99'; // Green
return true;
}
// 2. Fallback to essential lnurlp active wallet fields
const requiredKeys = ['callback', 'tag'];
const optionalKeys = ['minSendable', 'maxSendable'];
const hasRequiredKeys = requiredKeys.every(key => key in data);
const hasOptionalKeys = optionalKeys.some(key => key in data);
if (hasRequiredKeys && hasOptionalKeys) {
infoMessage.textContent = 'Wallet verified based on certain criteria.';
infoMessage.style.color = 'white';
infoMessage.style.fontSize = '0.6rem';
scrollToMessage(infoMessage); // Scroll to warning message
lnInput.style.backgroundColor = '#d4fa99'; // Green
return true;
}
// 3. Handle missing fields
const missingKeys = requiredKeys.filter(key => !(key in data));
warningMessage.textContent = `Missing fields: ${missingKeys.join(', ')}. Validation failed.`;
warningMessage.style.color = 'orange';
warningMessage.style.fontSize = '0.6rem';
scrollToMessage(warningMessage); // Scroll to warning message
lnInput.style.backgroundColor = '#f9a999'; // Red
} else {
warningMessage.textContent = `Validation error at: ${url}`;
warningMessage.style.color = 'orange';
warningMessage.style.fontSize = '0.6rem';
scrollToMessage(warningMessage); // Scroll to warning message
}
} catch (error) {
warningMessage.textContent = `Network error: ${error.message}`;
warningMessage.style.color = 'orange';
warningMessage.style.fontSize = '0.6rem';
scrollToMessage(warningMessage); // Scroll to warning message
lnInput.style.backgroundColor = '#f9a999'; // Red
console.error(`Validation error: ${error.message}`);
}
return false;
}
// Simple Reverse String Function (for URL inclusion)
function reverseString(str) {
return str.split('').reverse().join('');
}
// lightning END
// Font selection logic
includeFontCheckbox.addEventListener('change', function () {
if (this.checked) {
fontModal.style.display = 'block';
updateFontGrid();
} else {
fontModal.style.display = 'none';
selectedFontIndex = null; // Clear font selection
document.documentElement.style.setProperty('--main-font', `'inconsolata', monospace`); // Apply fallback
localStorage.removeItem('selectedFontIndex');
updateURL();
}
});
function updateFontGrid() {
fontGrid.innerHTML = '';
for (const [index, fontName] of Object.entries(fontList)) {
const fontPreview = document.createElement('div');
fontPreview.textContent = fontName.split(':')[0];
fontPreview.classList.add('font-preview');
// Create and add link tag for each font
const link = document.createElement('link');
link.rel = 'stylesheet';
link.href = `https://fonts.bunny.net/css?family=${fontName}`;
document.head.appendChild(link); // Append to head
// Apply the font to the preview
const cleanFontName = fontName.split(':')[0].replace(/-/g, ' ');
fontPreview.style.fontFamily = `'${cleanFontName}', sans-serif`;
// Font selection logic on click
fontPreview.addEventListener('click', () => {
selectedFontIndex = index;
applyFont(index); // Apply the selected font to the page
fontModal.style.display = 'none';
localStorage.setItem('selectedFontIndex', index);
updateURL();
});
fontGrid.appendChild(fontPreview);
}
}
// Apply font dynamically
function applyFont(index) {
// console.log('Font List:', fontList);
if (!fontList || !fontList[index]) {
console.error('Font not found at index:', index);
return;
}
const fontUrl = `https://fonts.bunny.net/css?family=${fontList[index]}`;
const existingLink = document.querySelector('#dynamic-font');
if (existingLink) {
existingLink.href = fontUrl;
} else {
const link = document.createElement('link');
link.id = 'dynamic-font';
link.rel = 'stylesheet';
link.href = fontUrl;
document.head.appendChild(link);
}
// Replace dashes with spaces for font-family
const cleanFontName = fontList[index].split(':')[0].replace(/-/g, ' ');
// Apply to the whole document
document.documentElement.style.setProperty('--main-font', `'${cleanFontName}', sans-serif`);
}
// Apply stored font on load
function applyStoredFont() {
const storedIndex = localStorage.getItem('selectedFontIndex');
if (storedIndex && fontList[storedIndex]) {
applyFont(storedIndex);
}
}
includeH1Checkbox.addEventListener('change', function () {
h1Input.disabled = !this.checked;
updateURL();
});
includeH3Checkbox.addEventListener('change', function () {
h3Input.disabled = !this.checked;
updateURL();
});
include_p_Checkbox.addEventListener('change', function () {
p_Input.disabled = !this.checked;
updateURL();
});
includeMessageCheckbox.addEventListener('change', function () {
const isChecked = this.checked;
messageInput.disabled = !isChecked;
if (isChecked) {
messageInput.style.height = '40vh'; // Expand height when enabled
messageInput.style.width = '95%'; // Widen for easier input
messageInput.style.verticalAlign = 'top';
} else {
messageInput.style.height = 'auto'; // Shrink when disabled
messageInput.style.width = '50%';
}
customCharactersCheckbox.disabled = isChecked; // Disable the checkbox for custom characters
customCharactersCheckbox.disabled = isChecked; // Also disable the input for character limit if message is included
charactersInput.disabled = isChecked;
if (isChecked) {
customCharactersCheckbox.checked = false;
}
// if (isChecked) {
// customCharactersCheckbox.checked = false;
// warningMessage.textContent = 'Characters limit is disabled when a fixed custom message is included.';
// warningMessage.style.color = 'orange';
// warningMessage.style.fontSize = '0.6rem'; // Adjust font size here (e.g., 1rem, 16px, etc.)
// scrollToMessage(warningMessage); // Scroll to warning message
// } else {
// warningMessage.textContent = '';
// }
updateURL();
});
customCharactersCheckbox.addEventListener('change', function () {
const isChecked = this.checked;
charactersInput.disabled = !isChecked;
if (isChecked) {
includeMessageCheckbox.checked = false; // Uncheck include_message if custom_characters is selected
messageInput.disabled = true;
}
updateURL();
});
// preventReuseCheckbox.addEventListener('change', function () {
// if (this.checked) {
// warningMessage.textContent = 'Be careful with this!';
// warningMessage.style.color = 'orange';
// warningMessage.style.fontSize = '0.6rem';
// scrollToMessage(warningMessage); // Scroll to warning message
// } else {
// warningMessage.textContent = ''; // Clear warning if unchecked
// }
// updateURL();
// });
function initializeRelayInputs() {
const includeRelaysChecked = includeRelaysCheckbox.checked;
relayInputs.forEach((input, index) => {
input.disabled = !includeRelaysChecked;
randomRelayButtons[index].disabled = !includeRelaysChecked;
if (!includeRelaysChecked) {
randomRelayButtons[index].checked = false; // Uncheck the radio buttons when disabled
}
});
}
randomRelayButtons.forEach((button, index) => {
button.addEventListener('click', () => {
if (relayList.length > 0 && includeRelaysCheckbox.checked) {
relayInputs[index].value = getRandomRelay();
updateURL();
}
});
});
includeRelaysCheckbox.addEventListener('change', function () {
relayInputs.forEach((input, index) => {
input.disabled = !this.checked;
randomRelayButtons[index].disabled = !this.checked;
if (!this.checked) {
randomRelayButtons[index].checked = false; // Uncheck the radio buttons when disabled
input.value = ''; // Clear relay input value
}
});
initializeRelayInputs();
updateURL();
});
h1Input.addEventListener('input', updateURL);
h3Input.addEventListener('input', updateURL);
p_Input.addEventListener('input', updateURL);
messageInput.addEventListener('input', updateURL);
charactersInput.addEventListener('input', updateURL);
hashtagInputs.forEach(input => input.addEventListener('input', updateURL));
relayInputs.forEach(input => input.addEventListener('input', updateURL));
copyButton.addEventListener('click', copyURL);
randomRelayButtons.forEach((button, index) => {
button.addEventListener('click', () => {
if (relayList.length > 0) {
relayInputs[index].value = getRandomRelay();
updateURL();
}
});
});
const relayInvalidChars = /[^a-zA-Z0-9://.-]/;
const hashtagInvalidChars = /[^a-zA-Z0-9]/;
function validateInput(input, area, regex) {
const match = input.match(regex);
if (match) {
errorMessage.textContent = `Invalid character detected in the ${area}: '${match[0]}' is what you entered. (#) will be added programmatically`;
errorMessage.style.color = 'red'; // Make the error message red
errorMessage.style.fontSize = '0.6rem';
scrollToMessage(errorMessage); // Scroll to the error message
return false;
}
return true;
}
function updateBackground() {
backgroundGrid.innerHTML = ''; // Clear grid
// Add color picker at the top
const colorPickerContainer = document.createElement('div');
colorPickerContainer.classList.add('color-picker-item');
const colorLabel = document.createElement('label');
colorLabel.textContent = 'Color Picker:';
colorLabel.id = 'color_picker_label';
colorPickerContainer.appendChild(colorLabel);
const colorInput = document.createElement('input');
colorInput.type = 'color';
colorInput.id = 'solid-color-picker';
colorInput.value = '#ffffff'; // Default to white
colorPickerContainer.appendChild(colorInput);
// Apply solid color on selection
colorInput.addEventListener('input', () => {
const selectedColor = colorInput.value;
selectedBackgroundIndex = selectedColor; // Store HEX value
document.body.style.backgroundColor = selectedColor; // Apply solid color
document.body.style.backgroundImage = ''; // Clear image
document.getElementById('dim-overlay').style.display = 'block'; // Show overlay
localStorage.setItem('selectedBackgroundIndex', selectedColor);
updateURL();
});
backgroundGrid.appendChild(colorPickerContainer);
// Add custom URL input below the color picker
const customUrlContainer = document.createElement('div');
customUrlContainer.classList.add('custom-url-item');
const urlLabel = document.createElement('label');
urlLabel.textContent = 'img URL:';
urlLabel.id = 'custom_url_label';
customUrlContainer.appendChild(urlLabel);