This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
1379 lines (1124 loc) · 51.5 KB
/
index.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">
<!-- Main styling for BHB and CS2-->
<style>
/* Fonts */
@font-face {
font-family: "Minecraft";
src: url("resources/fonts/Minecraft.ttf") format("truetype");
}
@font-face {
font-family: "Wingdings";
src: url("resources/fonts/Wingding.ttf") format("truetype");
}
@font-face {
font-family: "Arial";
src: url("resources/fonts/Arial.ttf") format("truetype");
}
/* Dark Mode */
@media (prefers-color-scheme: dark) {
body {
background-color: #60646c;
color: black;
}
input[type="text"],
select,
input[type="color"] {
background-color: #989ca4;
}
button,
fieldset,
input:disabled,
.mst_div,
.slv_div,
.topnav {
background-color: #84868c;
}
.topnav a {
color: #f2f2f2;
}
.topnav a:hover {
background-color: #ddd;
color: black;
}
.topnav a.active {
background-color: #04AA6D;
color: white;
}
}
/* Light Mode */
@media (prefers-color-scheme: light) {
body {
background-color: #f8f4f4;
color: black;
}
fieldset,
input[type="text"],
select,
input[type="color"],
button,
input:disabled,
div.mst_div.topnav,
div.mst_div.float-child,
div.slv_div,
.topnav {
background-color: white;
}
.topnav a {
color: black;
}
.topnav a:hover {
background-color: #ddd;
color: black;
}
.topnav a.active {
background-color: #04AA6D;
color: white;
}
}
/* Common Styles */
.topnav {
display: flex;
overflow: hidden;
align-items: center;
vertical-align: middle;
}
.topnav a {
float: left;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
body {
padding: 25px;
font-size: 25px;
}
h2 {
margin-top: 3px;
margin-bottom: 10px;
}
input[type="color"] {
height: 25px;
margin-right: 5px;
}
div.code_box {
align-items: center;
margin-top: 2px;
}
button {
box-shadow: 2px 2px #60646c;
pointer-events: all;
}
button.bhb_button {
border-radius: 6px;
height: 30px;
margin-right: 10px;
}
select.bhb_select {
border-radius: 3px;
margin-right: 10px;
}
fieldset {
border: 2px solid black;
border-radius: 5px;
}
.code_input {
text-transform: uppercase;
width: 50px;
height: 22px;
border: 2px solid black;
margin-right: 10px;
border-radius: 4px;
padding-right: 10px;
}
.code_input_label {
font-size: 20px;
padding-right: 10px;
}
.mst_div, .slv_div {
box-shadow: 5px 5px;
border: 6px solid black;
border-radius: 10px;
padding: 10px;
}
.slv_div {
box-shadow: 3px 3px;
}
.float-child {
float: left;
padding: 20px;
}
/* Cookie Consent */
#cookieNotice {
display: none;
position: fixed;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
width: 80%;
max-width: 400px;
padding: 20px;
background-color: rgba(0, 0, 0, 0.8);
color: #fff;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
z-index: 1000;
text-align: center;
}
#cookieNotice h4 {
margin-bottom: 15px;
font-size: 18px;
}
#cookieNotice p {
font-size: 14px;
margin-bottom: 20px;
}
.cookie-btn {
display: inline-block;
padding: 10px 20px;
border-radius: 5px;
font-size: 14px;
cursor: pointer;
}
.cookie-btn.accept {
background-color: #007bff;
color: #fff;
margin-right: 10px;
}
.cookie-btn.decline {
background-color: #ccc;
color: #000;
}
#closeIcon {
display: none;
}
</style>
<script>
'use strict';
function Scheme(name, codes) {
this.name = name;
this.codes = codes;
this.index = 0;
}
Scheme.prototype.nextCode = function () {
var curIndex = this.index;
this.index = (this.index++ == (this.codes.length - 1) ? 0 : this.index++);
return this.codes[curIndex];
}
function CS2ColorCode(hex, value) {
this.hex = hex;
this.value = value;
this.getHex = function () {
return this.hex;
}
}
function checkInputMP() {
var input = document.getElementById('mp_enter_box').value;
if (input != '') buildPreviewMP(input);
else buildPreviewMP("");
updateBHBCookies();
}
var cs2Schemes = [];
var mcc = {
black: new CS2ColorCode("#000000", "0"),
dark_blue: new CS2ColorCode("#0000AA", "1"),
dark_green: new CS2ColorCode("#00AA00", "2"),
dark_aqua: new CS2ColorCode("#00AAAA", "3"),
dark_red: new CS2ColorCode("#AA0000", "4"),
dark_purple: new CS2ColorCode("#AA00AA", "5"),
gold: new CS2ColorCode("#FFAA00", "6"),
gray: new CS2ColorCode("#AAAAAA", "7"),
dark_gray: new CS2ColorCode("#555555", "8"),
blue: new CS2ColorCode("#5555FF", "9"),
green: new CS2ColorCode("#55FF55", "a"),
aqua: new CS2ColorCode("#55FFFF", "b"),
red: new CS2ColorCode("#FF5555", "c"),
light_purple: new CS2ColorCode("#FF55FF", "d"),
yellow: new CS2ColorCode("#FFFF55", "e"),
white: new CS2ColorCode("#FFFFFF", "f")
}
//Generate a lookup table
var cs2Lookup = {};
for (var color in mcc) {
cs2Lookup[mcc[color].value] = mcc[color].getHex();
}
var cs2ExactLookup = {};
for (var colorTwo in mcc) {
cs2ExactLookup[mcc[colorTwo].value] = mcc[colorTwo];
}
function randomHexColor() {
return Math.floor(Math.random() * 0xFFFFFF).toString(16).padStart(6, '0');
}
//Random Scheme
var randomSchemeColors = [];
for (var co in mcc) randomSchemeColors.push(mcc[co]);
var randomScheme = new Scheme("Random", randomSchemeColors);
randomScheme.nextCode = function () {
return this.codes[Math.floor(Math.random() * this.codes.length)];
}
cs2Schemes.push(randomScheme);
//Random Hex Scheme
var randomHexScheme = new Scheme("Random Hex", []);
randomHexScheme.nextCode = function () {
var hex = randomHexColor();
return new CS2ColorCode('#' + hex, hex);
}
cs2Schemes.push(randomHexScheme);
//Rainbow Scheme
var rainbowSchemeColors = [mcc.dark_red, mcc.red, mcc.gold, mcc.yellow,
mcc.green, mcc.aqua, mcc.blue, mcc.light_purple, mcc.dark_purple];
cs2Schemes.push(new Scheme("Rainbow", rainbowSchemeColors));
//Ordered Scheme
var orderedSchemeColors = [];
for (var col in mcc) orderedSchemeColors.push(mcc[col]);
cs2Schemes.push(new Scheme("Ordered", orderedSchemeColors));
function buildPreviewMP(input) {
var div = document.getElementById('mp_preview_box');
var div2 = document.getElementById('mp_preview_label_container');
var label = document.getElementById('mp_preview_box_label');
//Clear old preview
div2.innerHTML = '';
// Create a document fragment to hold the span elements
const fragment = document.createDocumentFragment();
// Create a regular expression to match formatting codes and non-formatted text
const formatRegex = /&#[0-9a-fA-F]{6}|&[0-9a-fA-F]{1}|&|[^&]/g;
// Start off by assuming the color is black
let curColor = '000000';
const fontAddendum = document.getElementById('font_select').value != 'default' ? " font-family: " + document.getElementById('font_select').value + ";" : "";
// Use the exec method to iterate over the matches
let match;
while ((match = formatRegex.exec(input)) !== null) {
if (match[0] === '&') {
const span = document.createElement('span');
span.style = "color: #" + curColor + ";" + fontAddendum;
span.innerText = '&';
fragment.appendChild(span);
} else if (match[0][0] === '&') {
if (match[0][1] === '#') {
curColor = match[0].slice(2, 8);
} else if (/^[0-9a-fA-F]$/.test(match[0][1])) {
curColor = cs2Lookup[match[0][1].toLowerCase()].replace('#', '');
} else {
const span = document.createElement('span');
span.style = "color: #" + curColor + ";" + fontAddendum;
span.innerText = '&';
fragment.appendChild(span);
curColor = '000000';
}
} else {
const span = document.createElement('span');
span.style = "color: #" + curColor + ";" + fontAddendum;
span.innerText = match[0];
fragment.appendChild(span);
}
}
// Append the span elements to the div2 element
div2.appendChild(fragment);
//Show the preview if there is something to show, else hide the entire div
const displayValue = div2.innerHTML == '' ? 'none' : 'block';
div.style.display = displayValue;
div.style.border = displayValue == 'none' ? '0px solid black' : '3px solid black';
label.style.display = displayValue;
Array.from(document.getElementsByClassName('mp-cond-break')).forEach(b => b.style.display = displayValue == 'none' ? 'none' : 'inline');
}
let bhbOutput = '';
let cs2Output = '';
/*
Sleep for [delay] number of milliseconds
*/
function sleep(delay) {
var start = new Date().getTime();
while (new Date().getTime() < start + delay);
}
function animate({ timing, draw, duration }) {
let start = performance.now();
requestAnimationFrame(function animate(time) {
// timeFraction goes from 0 to 1
let timeFraction = (time - start) / duration;
if (timeFraction > 1) timeFraction = 1;
// calculate the current animation state
let progress = timing(timeFraction)
draw(progress); // draw it
if (timeFraction < 1) {
requestAnimationFrame(animate);
}
});
}
//Validate the hex color is good
function isHexOk(hex) {
return (hex.length == 6 && !isNaN(parseInt(hex, 16)));
}
//Cookie functions
function updateBHBCookies() {
//Only set the cookie if the user has accepted cookies
let cookie_consent = getCookie('user_cookie_consent');
//If the user has not accepted cookies, or has not interacted with the prompt, do not set any cookies
if (cookie_consent == '0' || cookie_consent == '' || cookie_consent == undefined) {
setCookie('user_cookie_consent', '0');
return;
}
//Start compiling the cookie
var inputs = '';
//Add code fields to the cookie
var fields = Array.prototype.slice.call(document.getElementsByClassName("code_input"));
//For each field, if the value exists, or there is a value after it, add the field.
// after checking was done to prevent 'disabled' fields from being excluded from the cookie
fields.forEach((f, i) => inputs += ((isHexOk(f.value) || f.value == '' && i < 5 && fields[i + 1].value != '') ? f.value + ',' : ''));
inputs = inputs.slice(0, -1);
//Add color codes to the cookies
setCookie('bhb_codes', inputs);
//Add justification to the cookie
setCookie('justification', document.getElementById('left_just').checked ? 'left' : 'right');
//Add input to the cookie
setCookie('bhb_input', document.getElementById('main_enter_box').value);
//Add CS2 scheme to the cookie
const schemeSelectVal = document.getElementById('cs2_scheme_select').value;
if(schemeSelectVal?.startsWith("Custom")){
setCookie('cs2_scheme', "custom:" + document.getElementById('cs2_custom_scheme_enter_box').value);
} else {
setCookie('cs2_scheme', schemeSelectVal);
}
//Add CS2 input to the cookie
setCookie('cs2_input', document.getElementById('cs2_enter_box').value);
//Add MP input to the cookie
setCookie('mp_input', document.getElementById('mp_enter_box').value);
//Add font to the cookie
setCookie('font_select', document.getElementById('font_select').value);
}
//Clear all existing cookies
function deleteAllCookies() {
var cookies = document.cookie.split(";");
for (const cookie of cookies)
eraseCookie(cookie.split("=")[0]);
}
function eraseCookie(name, domain, path) {
domain = domain || document.domain;
path = path || "/";
document.cookie = name + "=; samesite=none; expires=" + +new Date + "; domain=" + domain + "; path=" + path;
}
//Parse an existing cookie
function handleBHBCookies() {
var cookie = document.cookie;
if (cookie == '') {
console.log("No cookies found - skipping cookie handling");
checkInput();
return;
}
//Bhb inputs
var codes = getCookie('bhb_codes').split(',');
var just = getCookie('justification');
var input = getCookie('bhb_input');
const cs2Scheme = getCookie('cs2_scheme');
//cs2input should only get up to the first semi-colon
var cs2input = getCookie('cs2_input').split(';')[0];
var mpinput = getCookie('mp_input');
//Handle CS2 scheme in cookie
if(cs2Scheme != null){
const schemeSplit = cs2Scheme.split(':');
if(schemeSplit[0] == "custom"){
document.getElementById('cs2_scheme_select').value = "Custom";
document.getElementById('cs2_custom_scheme_enter_box').value = schemeSplit[1];
} else {
document.getElementById('cs2_scheme_select').value = schemeSplit[0];
}
}
//Handle codes in cookie
var fields = Array.prototype.slice.call(document.getElementsByClassName("code_input"));
fields.forEach((f, i) => {
if (codes[i] && isHexOk(codes[i])) f.value = codes[i];
f.dispatchEvent(new Event('change'));
});
//Handle input in cookie
if (input) document.getElementById('main_enter_box').value = input;
if (just) {
if (just == 'left') document.getElementById('left_just').checked = true;
else document.getElementById('right_just').checked = true;
}
//Handle CS2 input in cookie
if (cs2input) document.getElementById('cs2_enter_box').value = cs2input;
//Handle MP input in cookie
if (mpinput) document.getElementById('mp_enter_box').value = mpinput;
//Handle font in cookie
var font = getCookie('font_select');
if (document.querySelector(`option[value="${font}"]`)) document.getElementById('font_select').value = font;
checkInput();
checkInputCS2();
}
// Create cookie
function setCookie(cname, cvalue) {
document.cookie = cname + "=" + cvalue + "; samesite=none; secure; max-age=31536000; path=/";
}
//Delete cookie
function deleteCookie(cname) {
const d = new Date();
d.setTime(d.getTime() + (24 * 60 * 60 * 1000));
let expires = "expires=" + d.toUTCString();
document.cookie = cname + "=;samesite=none;secure;" + expires + ";path=/";
}
//Read cookie
function getCookie(cname) {
let name = cname + "=";
let decodedCookie = decodeURIComponent(document.cookie);
let ca = decodedCookie.split(';');
for (const element of ca) {
let c = element;
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
// Set cookie consent
function acceptCookieConsent() {
deleteCookie('user_cookie_consent');
setCookie('user_cookie_consent', 1);
document.getElementById("cookieNotice").style.display = "none";
}
function declineCookieConsent() {
deleteAllCookies();
deleteCookie('user_cookie_consent');
setCookie('user_cookie_consent', 0);
document.getElementById("cookieNotice").style.display = "none";
}
//Reload all previews
function fontChanged(oldvalue) {
if (document.getElementById('font_select').value == 'Upload') {
var url = prompt('Enter the URL of the font file:');
if (url == null || url == '') document.getElementById('font_select').value = oldvalue;
else {
var name = prompt("Enter the name of the font:");
if (name == null || name == '') document.getElementById('font_select').value = oldvalue;
else {
const style = document.createElement('style');
style.innerHTML = `
@font-face {
font-family: ${name};
src: url(${url});
}
`;
document.head.appendChild(style);
var newOpt = document.createElement('option');
newOpt.value = name;
newOpt.innerHTML = name;
//Insert before the last option
document.getElementById('font_select').insertBefore(newOpt, document.getElementById('font_select').lastElementChild);
//Select the new option
document.getElementById('font_select').value = name;
}
}
}
checkInputMP();
checkInputCS2();
checkInput();
updateBHBCookies();
}
function copyFunctionBhb() {
document.getElementById('main_output_box').style.display = 'inline';
document.getElementById('main_output_box').select();
document.execCommand('copy');
document.getElementById('main_output_box').style.display = 'none';
}
function findSplitLengths(word, numSplits) {
//List of lengths of each split
var solutions = [];
var roughSolution = parseInt(Math.ceil(parseFloat(word.length) / numSplits), 10);
var remaining = word.length;
var reduced = false;
for (var i = 0; i < numSplits; ++i) {
var x = (roughSolution - 1) * (numSplits - i);
if (!reduced && x === remaining) {
roughSolution -= 1;
reduced = true;
}
solutions.push(roughSolution);
remaining -= roughSolution;
}
return solutions;
}
function findSplits(rightJustified, splitsLengths, input) {
var result = [];
if (rightJustified) splitsLengths = splitsLengths.reverse();
var newIndex = 0;
for (var i = 0; i < splitsLengths.length; i++) {
result[i] = input.substring(newIndex, newIndex + splitsLengths[i]);
newIndex += splitsLengths[i];
}
return result;
}
function blendTwo(hexOne, hexTwo, input) {
//Start to compile the output
var output = "";
//Put the R, G, and B values for each into an array
let componentsOne = [hexR(hexOne), hexG(hexOne), hexB(hexOne)];
let componentsDif = [hexR(hexTwo) - hexR(hexOne), hexG(hexTwo) - hexG(hexOne), hexB(hexTwo) - hexB(hexOne)];
//Loop through each step
for (var j = 0; j <= (input.length - 1); ++j) {
//Append the signifier
output += "&#";
//Append each hex value's parts
componentsOne.forEach((c, i) => output += padHex(c + (componentsDif[i] * (j / (input.length - 1)))).toUpperCase());
//Append the index character to the output
output += input[j];
}
return output;
}
function blendMain(howManyCodes, input, codeList) {
//Get the "Right justified" setting from the HTML
var rightJustified = document.getElementById("right_just").checked;
//Create an output
var output = "";
//Find the splits of the input
var splits = findSplits(rightJustified, findSplitLengths(input, (howManyCodes - 1)), input);
//Compile the output
for (var i = 0, codeIndex = 0; i < splits.length; i++, codeIndex++) {
if (i !== (splits.length - 1)) splits[i] = (splits[i] + splits[i + 1].substring(0, 1));
var addendum = blendTwo(codeList[codeIndex], codeList[codeIndex + 1], splits[i]);
output += (i !== (splits.length - 1) ? addendum.substring(0, addendum.length - 9) : addendum);
}
return output;
}
function padHex(input) {
var convertedHex = Math.round(input).toString(16);
return convertedHex.length == 1 ? "0" + convertedHex : convertedHex;
}
function hexR(hex) { return parseInt(hex.substring(0, 2), 16) }
function hexG(hex) { return parseInt(hex.substring(2, 4), 16) }
function hexB(hex) { return parseInt(hex.substring(4, 6), 16) }
function slotMachine() {
var codeBoxesArr = Array.prototype.slice.call(document.getElementsByClassName("code_input"));
var colorPickerArr = Array.prototype.slice.call(document.getElementsByClassName("color_picker"));
var intProgress = 0;
var maximumCodes = Math.floor((document.getElementById('main_enter_box').value.length + 1) / 2);
if(maximumCodes < 2) return;
else if(maximumCodes > 6) maximumCodes = 6;
//Clear all fields
clearAll();
animate({//Timing loop
duration: 2520,
timing: function (timeFraction) {
return timeFraction;
},
draw: function (progress) {
if (progress % 2 != 0) {
for (var j = maximumCodes - 1; j >= Math.floor(intProgress / 40); --j) {
codeBoxesArr[j].value = randomHexColor();
colorPickerArr[j].value = "#" + codeBoxesArr[j].value;
if (intProgress < 10) unlockFields();
checkInput();
}
}
sleep(4);
intProgress++;
}
});
}
function clearAll() {
Array.prototype.slice.call(document.getElementsByClassName("code_input")).forEach(i => i.value = '');
Array.prototype.slice.call(document.getElementsByClassName("color_picker")).forEach(p => p.value = "#000000");
checkInput();
unlockFields();
}
function buildPreviewBhb(input) {
var div = document.getElementById('preview_box');
var div2 = document.getElementById('preview_label_container');
var copyButton = document.getElementById('bhb_copy_button');
var label = document.getElementById('preview_box_label');
//Clear old preview
div2.innerHTML = "";
/*
Input will be in the form &#FF00FF{char}, etc., where each character will be preceded by a color code
The following code will split the input into an array of corresponding color codes and characters:
[#FF00FF[char: A], #00FF00[char: B], #0000FF[char: C], etc.]
*/
var inputSplit = input.split("&").slice(1);
//Create an addendum for font
var fontAddendum = document.getElementById('font_select').value != 'default' ? " font-family: " + document.getElementById('font_select').value + ";" : "";
//Create a label for each character
inputSplit.forEach(element => {
var label = document.createElement('label');
label.style = "color: " + element.substring(0, 7) + ";" + fontAddendum;
label.innerText = element.substring(7, 8);
div2.appendChild(label);
});
var hideCondition = (div2.innerHTML == '' || input.length == 0 || input == null || input == undefined);
div.style.display = (hideCondition ? 'none' : 'block');
div.style.border = ((hideCondition ? '0px' : '3px') + 'solid black');
label.style.display = (hideCondition ? 'none' : 'inline');
copyButton.style.display = (hideCondition ? 'none' : 'inline');
Array.from(document.getElementsByClassName('cond-break')).forEach(b => b.style.display = (hideCondition ? 'none' : 'inline'));
}
//Figure out which fields should be enabled/disabled
function unlockFields() {
var fields = Array.from(document.getElementsByClassName("code_input"));
var pickers = Array.from(document.getElementsByClassName("color_picker"));
// f=field, i=index
fields.forEach((f, i) => {
if (i + 1 < 6) {
fields[i + 1].disabled = !(f.value.length == 6 && !f.disabled);
pickers[i + 1].disabled = !(f.value.length == 6 && !f.disabled);
}
});
Array.from(document.getElementsByClassName("color_shifter")).forEach((shifter, i) => {
shifter.disabled = !(i !== 0 && fields[i].value.length === 6 && !fields[i].disabled);
});
}
/*
Given an index, swap the code with the code at the index - 1
*/
function shiftColor(index) {
var fields = Array.prototype.slice.call(document.getElementsByClassName("code_input"));
var pickers = Array.prototype.slice.call(document.getElementsByClassName("color_picker"));
var currentIndexColor = fields[index].value;
var oneUpIndexColor = fields[index - 1].value;
fields[index].value = oneUpIndexColor;
pickers[index].value = "#" + oneUpIndexColor;
fields[index - 1].value = currentIndexColor;
pickers[index - 1].value = "#" + currentIndexColor;
unlockFields();
checkInput();
}
function checkInput() {
//Need to be at least 2 valid codes
var validCodes = 0;
//Compile the code fields
var codeFields = function () { var x = []; for (var i = 0; i < 6; i++) { x.push(document.getElementById('code_input' + i)); } return x; }();
//Count number of valid codes
codeFields.forEach(el => { if (isHexOk(el.value) && !el.disabled) validCodes++; });
var bhbOutput;
//Build the preview if conditions are met
if (validCodes >= 2 && (document.getElementById('main_enter_box').value.length >= (validCodes * 2) - 1)) {
bhbOutput = blendMain(validCodes, document.getElementById('main_enter_box').value, codeFields.map(f => { return (!f.disabled ? f.value : '') }));
}
else bhbOutput = '';
buildPreviewBhb(bhbOutput);
updateBHBCookies();
document.getElementById('main_output_box').value = bhbOutput;
}
function findScheme(input) {
var scheme = cs2Schemes.find(s => s.name == input);
return scheme;
}
function checkInputCS2() {
var input = document.getElementById('cs2_enter_box').value;
var scheme = document.getElementById('cs2_scheme_select').value;
if(scheme.toLowerCase() == 'custom'){
document.getElementById('custom-scheme-box').style.display = 'block';
checkCustomCS2Scheme();
} else{
document.getElementById('custom-scheme-box').style.display = 'none';
if (input != '' && scheme != 'default') var cs2Output = buildPreviewCS2(input, findScheme(scheme));
else cs2Output = buildPreviewCS2("", 'default');
updateBHBCookies();
document.getElementById('cs2_output_box').value = cs2Output;
}
}
function checkCustomCS2Scheme() {
var schemeInput = document.getElementById('cs2_custom_scheme_enter_box').value;
var separated = schemeInput.split(",");
//Remove all empty strings
separated = separated.filter(s => s != '');
// Filter out empty strings from the array
const filteredSeparated = separated.filter(s => s !== '');
// Create an array for the processed values
const schemeArr = filteredSeparated.map(s => {
if (s.length === 1) {
return cs2ExactLookup[s] || '#FFFFFF'; // Use logical OR to provide a default value
} else if (s.length === 7 && s[0] === '#' || s.length === 6 && /^[0-9a-fA-F]+$/.test(s)) {
if(s.length === 6) s = '#' + s;
return new CS2ColorCode(s, s);
}
return null; // Return null for invalid values or use an appropriate default
}).filter(value => value !== null); // Remove null values from the processed array
var input = document.getElementById('cs2_enter_box').value;
var customScheme = new Scheme("Custom", schemeArr);
if (input != '') var cs2Output = buildPreviewCS2(input, customScheme);
else cs2Output = buildPreviewCS2("", 'default');
updateBHBCookies();
document.getElementById('cs2_output_box').value = cs2Output;
}
function copyFunctionCS2() {
document.getElementById('cs2_output_box').style.display = 'inline';
document.getElementById('cs2_output_box').select();
document.execCommand('copy');
document.getElementById('cs2_output_box').style.display = 'none';
}
function buildPreviewCS2(input, scheme) {
if(scheme != 'default')
scheme.index = 0;
var div = document.getElementById('cs2_preview_box');
var div2 = document.getElementById('cs2_preview_label_container');
var copyButton = document.getElementById('cs2_copy_button');
var label = document.getElementById('cs2_preview_box_label');
//Clear old preview
while (div2.firstChild) {
div2.removeChild(div2.firstChild);
}
var charSplit = input.split('');
var compOut = '';
if (scheme != 'default') {
//Create an addendum for font
var fontAddendum = document.getElementById('font_select').value != 'default' ? " font-family: " + document.getElementById('font_select').value + ";" : "";
//Create new preview
charSplit.forEach(c => {
let nextColor = scheme.nextCode();
var label = document.createElement('label');
label.style = "color: " + nextColor.hex + ";" + fontAddendum;
label.innerText = c;
if (c == ' ') scheme.index--;
div2.appendChild(label);
compOut += "&" + (nextColor.value.length == 6 ? ("#" + nextColor.value) : nextColor.value) + c;
});
}
//Show the preview if there is something to show, else hide the entire div
const showElements = (div2.innerHTML != '');
div.style.display = showElements ? 'block' : 'none';
div.style.border = showElements ? '3px solid black' : '0px solid black';
label.style.display = showElements ? 'inline' : 'none';
copyButton.style.display = showElements ? 'inline' : 'none';
Array.from(document.getElementsByClassName('cs2-cond-break')).forEach(b => b.style.display = showElements ? 'inline' : 'none');
/*
if (div2.innerHTML == '') {
div.style.display = 'none';
div.style.border = '0px solid black';
label.style.display = 'none';
copyButton.style.display = 'none';
Array.from(document.getElementsByClassName('cs2-cond-break')).forEach(b => b.style.display = 'none');
}
else {
div.style.display = 'block';
div.style.border = '3px solid black';
label.style.display = 'inline';
copyButton.style.display = 'inline';
Array.from(document.getElementsByClassName('cs2-cond-break')).forEach(b => b.style.display = 'inline');
}
*/
return compOut;
}
</script>
<head>
<!-- Discord preview stuff -->
<meta property="og:type" content="website">
<meta property="og:url" content="https://davidarthurcole.github.io/bhb-webapp/">
<meta property="og:title" content="BHB | Blazin's Hex Blender">
<meta property="og:description" content="BHB lets you customize & preview nicknames using Hex Codes & Color Codes.">
<meta property="og:fields" content="[{"name": "Version", "value": "1.0", "inline": true}]">
<meta property="og:image" content="https://davidarthurcole.github.io/bhb-webapp/resources/icons/144.png">
<meta charset="utf-8">
<title>Blazin's Hex Blender</title>
<!-- Load in the favicon from resources -->
<link rel="icon" type="image/x-icon" href="resources/favicon.ico">
<!-- Chrome Webapp setup -->