-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
793 lines (698 loc) · 29.7 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
<!DOCTYPE html>
<!-- Author: Rahul Ban [email protected]>
<!-- Github: https://github.com/ikrahul/SHA256-BTC-Generater-->
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SHA-256 Hasher & Bitcoin Address Generator</title>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&family=Roboto+Mono:wght@400;500;700&display=swap" rel="stylesheet">
<style>
/* Reset and Base Styles */
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: 'Inter', sans-serif;
background: linear-gradient(135deg, #f5f7fa, #c3cfe2);
color: #333;
display: flex;
flex-direction: column;
min-height: 100vh;
}
a {
color: inherit;
text-decoration: none;
}
/* Header Styles */
header {
background-color: #2D3748;
color: #EDF2F7;
padding: 15px 30px;
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
position: fixed;
top: 0;
left: 0;
width: 100%;
z-index: 1000;
}
header .logo {
font-size: 1.3em;
font-weight: 700;
display: flex;
align-items: center;
}
header .logo svg {
margin-right: 8px;
fill: #EDF2F7;
}
header .header-right a {
display: flex;
align-items: center;
background-color: #4A5568;
padding: 6px 10px;
border-radius: 6px;
transition: background-color 0.3s ease;
font-size: 0.9em;
}
header .header-right a:hover {
background-color: #2D3748;
}
header .header-right svg {
margin-right: 4px;
fill: #E2E8F0;
}
/* Container Styles */
.container {
background-color: #FFFFFF;
padding: 10px 20px 20px 20px;
border-radius: 12px;
max-width: 800px;
width: 90%;
margin: 80px auto 20px auto; /* Added top margin to account for fixed header */
box-shadow: 0 6px 20px rgba(0,0,0,0.1);
transition: transform 0.3s ease;
margin-top: 105px;
}
.container:hover {
transform: translateY(-3px);
}
h1 {
text-align: center;
margin-bottom: 0px;
font-size: 2em;
color: #2D3748;
font-weight: 500;
}
label {
display: block;
margin-top: 0px;
margin-bottom: 0px;
font-weight: 500;
color: #4A5568;
font-size: 0.95em;
}
input[type="text"],
input[type="number"] {
width: 100%;
padding: 12px 16px;
border: 1px solid #CBD5E0;
border-radius: 6px;
font-size: 0.9em;
transition: border 0.3s ease, box-shadow 0.3s ease;
font-family: 'Inter', sans-serif;
}
input[type="text"]:focus,
input[type="number"]:focus {
border-color: #3182ce;
box-shadow: 0 0 0 2px rgba(49, 130, 206, 0.3);
outline: none;
}
/* New Styles for the Flex Container */
.controls-row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 20px; /* Space between items */
margin-top: 1px; /* Space above the flex container */
}
/* Container for Number Input */
.hash-times-container {
display: flex;
flex-direction: column;
flex: 1; /* Allow the number input to take available space */
}
/* Adjust Checkbox Containers */
.checkbox-container {
display: flex;
align-items: center;
margin-top: 0; /* Remove top margin to align with other elements */
font-size: 0.9em;
}
.checkbox-container input {
margin-right: 8px;
width: 18px;
height: 18px;
cursor: pointer;
accent-color: #3182ce;
}
/* Optional: Adjust Labels for Consistent Styling */
.controls-row label {
margin-right: 8px;
}
/* Custom API Container */
.custom-api-container {
margin-top: 20px;
}
.custom-api-inputs {
margin-top: 10px;
}
.custom-api-inputs label {
margin-top: 10px;
margin-bottom: 5px;
}
.custom-api-inputs input[type="text"] {
width: 100%;
}
button {
margin-top: 5px;
width: 100%;
padding: 14px 0;
background-color: #3182ce;
border: none;
color: white;
font-size: 1em;
border-radius: 6px;
cursor: pointer;
transition: background-color 0.3s ease, transform 0.2s ease;
font-family: 'Inter', sans-serif;
}
button:hover {
background-color: #2b6cb0;
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
#result, #btcAddress, #btcBalance {
margin-top: 5px;
padding: 16px;
background-color: #F7FAFC;
border-radius: 6px;
word-break: break-all;
white-space: pre-wrap;
font-family: 'Roboto Mono', monospace;
font-size: 0.85em;
box-shadow: inset 0 0 8px rgba(0,0,0,0.05);
}
/* Footer Styles */
footer {
background-color: #2D3748;
color: #A0AEC0;
padding: 15px 30px;
text-align: center;
border-top: 1px solid #4A5568;
border-bottom: 1px solid #4A5568;
display: flex;
justify-content: center;
align-items: center;
flex-wrap: wrap;
width: 100%;
}
footer .footer-left {
font-size: 0.85em;
margin-bottom: 8px;
width: 100%;
}
footer .footer-right a {
display: flex;
align-items: center;
background-color: #4A5568;
padding: 6px 10px;
border-radius: 6px;
transition: background-color 0.3s ease;
font-size: 0.9em;
margin-top: 8px;
}
footer .footer-right a:hover {
background-color: #2D3748;
}
footer .footer-right svg {
margin-right: 4px;
fill: #A0AEC0;
}
/* Responsive Design */
@media (max-width: 768px) {
header, footer {
padding: 15px 20px;
}
.container {
padding: 30px 25px 40px 25px;
}
h1 {
font-size: 1.8em;
margin-bottom: 0px;
}
label {
margin-top: 5px;
margin-bottom: 6px;
font-size: 0.88em;
}
input[type="text"],
input[type="number"] {
padding: 10px 14px;
font-size: 0.85em;
}
.checkbox-container {
margin-top: 14px;
font-size: 0.85em;
}
button {
padding: 12px 0;
font-size: 0.95em;
}
#result, #btcAddress, #btcBalance {
margin-top: 20px;
padding: 14px;
font-size: 0.8em;
}
.controls-row {
gap: 15px; /* Reduce space between items on smaller screens */
}
.hash-times-container {
flex: 1; /* Allow the number input to take available space */
}
.custom-api-container {
margin-top: 15px;
}
}
@media (max-width: 480px) {
header .header-right, footer .footer-right {
justify-content: center;
width: 100%;
margin-top: 6px;
}
header .logo, footer .footer-left {
width: 100%;
text-align: center;
font-size: 1.2em;
}
.container {
padding: 25px 20px 35px 20px;
}
h1 {
font-size: 1.6em;
margin-bottom: 0px;
}
label {
font-size: 0.85em;
}
input[type="text"],
input[type="number"] {
padding: 8px 12px;
font-size: 0.8em;
}
.checkbox-container {
font-size: 0.8em;
}
button {
padding: 10px 0;
font-size: 0.9em;
}
#result, #btcAddress, #btcBalance {
padding: 12px;
font-size: 0.75em;
}
.controls-row {
flex-direction: column; /* Stack elements vertically on very small screens */
align-items: flex-start;
}
.hash-times-container,
.checkbox-container,
.custom-api-container {
width: 100%; /* Full width for each element */
}
}
</style>
</head>
<body>
<header>
<div class="logo">
<div class="github-profile-badge" data-user="ikrahul"></div>
<script src="https://cdn.jsdelivr.net/gh/Rapsssito/github-profile-badge@latest/src/widget.min.js"></script>
SHA256-BTC-Generator
</div>
<div class="header-right">
<a href="https://github.com/ikrahul/SHA256-BTC-Generater" target="_blank" rel="noopener noreferrer">
<!-- GitHub Star Icon -->
<svg height="20" width="20" viewBox="0 0 16 16" aria-hidden="true">
<path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82a7.65 7.65 0 012.01-.27c.68 0 1.36.09 2.01.27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"></path>
</svg>
<span id="star-count">0</span> Stars
</a>
</div>
</header>
<div class="container">
<h1>SHA-256 Hasher & Bitcoin Address Generator</h1>
<label for="inputText">Text to Hash:</label>
<input type="text" id="inputText" placeholder="Enter your text here">
<!-- Flex Container for Number Input and Checkboxes -->
<div class="controls-row">
<div class="hash-times-container">
<label for="hashTimes">Number of Times to Hash:</label>
<input type="number" id="hashTimes" min="1" value="1">
</div>
<div class="checkbox-container">
<input type="checkbox" id="autoUpdate">
<label for="autoUpdate">Auto-update Hash</label>
</div>
<div class="checkbox-container">
<input type="checkbox" id="checkBalance">
<label for="checkBalance">Check Balance</label>
</div>
</div>
<!-- End of Flex Container -->
<!-- Custom API Container -->
<div class="custom-api-container">
<div class="checkbox-container">
<input type="checkbox" id="useCustomApi">
<label for="useCustomApi">Use Custom API URL for Balance</label>
</div>
<div class="custom-api-inputs" style="display: none;">
<label for="customApiUrl">Custom API URL:</label>
<input type="text" id="customApiUrl" placeholder="https://api.example.com/balance?address=${address}">
<label for="customApiKey">Response JSON Key for Balance:</label>
<input type="text" id="customApiKey" placeholder="balance">
</div>
</div>
<!-- End of Custom API Container -->
<button id="hashButton">Hash</button>
<div id="result">SHA-256 Hash / Private Key</div>
<div id="btcAddress">Bitcoin Address</div>
<div id="btcBalance">Bitcoin Balance</div>
</div>
<footer>
<div class="footer-left">🚀 Created with ❤️ by Rahul Ban © 2024 | Support:
<a href="bitcoin:1PqDbd9XRmEGfwYK6rnsYYTshdb3PguKuG">
1PqDbd9XRmEGfwYK6rnsYYTshdb3PguKuG
</a>
</div>
<div class="footer-right">
<a href="https://github.com/ikrahul/SHA256-BTC-Generater" target="_blank" rel="noopener noreferrer">
<!-- GitHub Icon -->
<svg height="20" width="20" viewBox="0 0 16 16" aria-hidden="true">
<path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82a7.65 7.65 0 012.01-.27c.68 0 1.36.09 2.01.27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"></path>
</svg>
<!-- GitHub Star Count -->
<span id="footer-star-count">0</span>
</a>
</div>
</footer>
<!-- Including External Libraries via CDN -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/elliptic/6.5.4/elliptic.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js"></script>
<script>
// Initialize elliptic curve
const EC = elliptic.ec;
const ec = new EC('secp256k1');
// Base58 character set
const BASE58_ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
/**
* Converts a hexadecimal string to a byte array.
* @param {string} hex - The hexadecimal string.
* @returns {Uint8Array} - The resulting byte array.
*/
function hexToBytes(hex) {
const bytes = [];
for (let c = 0; c < hex.length; c += 2) {
bytes.push(parseInt(hex.substr(c, 2), 16));
}
return new Uint8Array(bytes);
}
/**
* Encodes a byte array into a Base58 string.
* @param {Uint8Array} bytes - The byte array to encode.
* @returns {string} - The Base58 encoded string.
*/
function base58Encode(bytes) {
const digits = [0];
for (let i = 0; i < bytes.length; i++) {
let carry = bytes[i];
for (let j = 0; j < digits.length; j++) {
carry += digits[j] << 8;
digits[j] = carry % 58;
carry = (carry / 58) | 0;
}
while (carry > 0) {
digits.push(carry % 58);
carry = (carry / 58) | 0;
}
}
// Convert digits to the Base58 string
let result = '';
// Leading zeros
for (let i = 0; i < bytes.length && bytes[i] === 0; i++) {
result += '1';
}
// Convert digits to characters
for (let i = digits.length - 1; i >= 0; i--) {
result += BASE58_ALPHABET[digits[i]];
}
return result;
}
/**
* Fetches the Bitcoin balance using the appropriate API.
* @param {string} address - The Bitcoin address.
* @param {string} customApiUrl - The custom API URL template.
* @param {string} customApiKey - The JSON key to extract balance.
* @returns {Promise<string>} - The balance in BTC as a string.
*/
async function fetchBalance(address, customApiUrl = null, customApiKey = null) {
try {
const resultDiv = document.getElementById('result');
let responseData;
if (customApiUrl && customApiKey) {
// Use Custom API
const apiUrl = customApiUrl.replace('${address}', encodeURIComponent(address));
const response = await fetch(apiUrl);
if (!response.ok) {
throw new Error('Network response was not ok');
}
responseData = await response.json();
if (!(customApiKey in responseData)) {
throw new Error(`Key "${customApiKey}" not found in the response.`);
}
const balanceBTC = parseBalance(responseData[customApiKey]);
if (parseFloat(balanceBTC) > 0) {
const content = `hash: ${resultDiv.textContent}\nAddress: ${address}\nBalance: ${balanceBTC} BTC`;
const blob = new Blob([content], { type: 'text/plain;charset=utf-8;' });
const link = document.createElement("a");
const url = URL.createObjectURL(blob);
link.setAttribute("href", url);
link.setAttribute("download", "balance.txt");
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
return balanceBTC;
} else {
// Use Default Blockchain.info API
const response = await fetch(`https://blockchain.info/q/addressbalance/${address}`);
if (!response.ok) {
throw new Error('Network response was not ok');
}
const balanceSatoshi = await response.text();
const balanceBTC = (parseInt(balanceSatoshi, 10) / 1e8).toFixed(8);
if (parseFloat(balanceBTC) > 0) {
const content = `hash: ${resultDiv.textContent}\nAddress: ${address}\nBalance: ${balanceBTC} BTC`;
const blob = new Blob([content], { type: 'text/plain;charset=utf-8;' });
const link = document.createElement("a");
const url = URL.createObjectURL(blob);
link.setAttribute("href", url);
link.setAttribute("download", "balance.txt");
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
return balanceBTC;
}
} catch (error) {
console.error('Error fetching balance:', error);
return 'Error fetching balance. Rate limit reached for the free api.\nFor dedicated address checker reach out at [email protected].';
}
}
/**
* Parses the balance value to BTC.
* @param {any} value - The value extracted from the API response.
* @returns {string} - The balance in BTC as a string.
*/
function parseBalance(value) {
if (typeof value === 'number') {
return (value / 1e8).toFixed(8);
} else if (typeof value === 'string') {
const parsed = parseFloat(value);
if (isNaN(parsed)) {
throw new Error('Balance value is not a valid number.');
}
return (parsed / 1e8).toFixed(8);
} else {
throw new Error('Invalid balance value type.');
}
}
/**
* Computes the SHA-256 hash of a given message.
* @param {string} message - The input message.
* @returns {Promise<string>} - The SHA-256 hash as a hexadecimal string.
*/
async function sha256(message) {
const encoder = new TextEncoder();
const data = encoder.encode(message);
const hashBuffer = await crypto.subtle.digest('SHA-256', data);
const hashArray = Array.from(new Uint8Array(hashBuffer));
const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
return hashHex;
}
/**
* Performs the hashing process and updates the UI accordingly.
*/
async function performHashing() {
const textInput = document.getElementById('inputText').value;
const times = parseInt(document.getElementById('hashTimes').value, 10);
const resultDiv = document.getElementById('result');
const btcAddressDiv = document.getElementById('btcAddress');
const btcBalanceDiv = document.getElementById('btcBalance');
const checkBalance = document.getElementById('checkBalance').checked;
if (times < 1) {
resultDiv.textContent = 'Number of times to hash must be at least 1.';
btcAddressDiv.textContent = '';
btcBalanceDiv.textContent = '';
return;
}
let currentHash = textInput;
for (let i = 0; i < times; i++) {
currentHash = await sha256(currentHash);
}
resultDiv.textContent = `SHA-256 Hash / Private Key: ${currentHash}`;
generateBitcoinAddress(currentHash, btcAddressDiv, btcBalanceDiv, checkBalance);
}
/**
* Generates a Bitcoin address from a given private key and updates the UI.
* @param {string} privateKeyHex - The private key in hexadecimal format.
* @param {HTMLElement} displayDiv - The div to display the Bitcoin address.
* @param {HTMLElement} balanceDiv - The div to display the Bitcoin balance.
* @param {boolean} checkBalance - Whether to fetch the balance.
*/
function generateBitcoinAddress(privateKeyHex, displayDiv, balanceDiv, checkBalance) {
try {
// Create key pair from private key
const key = ec.keyFromPrivate(privateKeyHex, 'hex');
// Get the public key in compressed format (33 bytes)
const publicKey = key.getPublic(true, 'hex');
// Perform SHA-256 hashing on the public key
const sha256Hash = CryptoJS.SHA256(CryptoJS.enc.Hex.parse(publicKey)).toString(CryptoJS.enc.Hex);
// Perform RIPEMD-160 hashing on the result of SHA-256
const ripemd160Hash = CryptoJS.RIPEMD160(CryptoJS.enc.Hex.parse(sha256Hash)).toString(CryptoJS.enc.Hex);
// Add network byte (0x00 for mainnet)
const networkByte = '00';
const extendedRipemd160 = networkByte + ripemd160Hash;
// Compute checksum: SHA-256 twice
const firstSHA = CryptoJS.SHA256(CryptoJS.enc.Hex.parse(extendedRipemd160)).toString(CryptoJS.enc.Hex);
const secondSHA = CryptoJS.SHA256(CryptoJS.enc.Hex.parse(firstSHA)).toString(CryptoJS.enc.Hex);
const checksum = secondSHA.substring(0, 8); // First 4 bytes (8 hex chars)
// Concatenate extended RIPEMD-160 hash with checksum
const binaryAddress = extendedRipemd160 + checksum;
// Convert hex string to byte array
const addressBytes = hexToBytes(binaryAddress);
// Convert to Base58
const btcAddress = base58Encode(addressBytes);
displayDiv.textContent = `Bitcoin Address: ${btcAddress}`;
// If checkBalance is enabled, fetch and display the balance
if (checkBalance) {
// Check if custom API is used
const useCustomApi = document.getElementById('useCustomApi').checked;
let customApiUrl = null;
let customApiKey = null;
if (useCustomApi) {
customApiUrl = document.getElementById('customApiUrl').value.trim();
customApiKey = document.getElementById('customApiKey').value.trim();
if (!customApiUrl || !customApiKey) {
balanceDiv.textContent = 'Please provide both Custom API URL and Response JSON Key.';
return;
}
}
fetchBalance(btcAddress, customApiUrl, customApiKey).then(balance => {
if (balance === 'Error fetching balance.') {
balanceDiv.textContent = balance;
} else {
balanceDiv.textContent = `Balance: ${balance} BTC`;
}
});
} else {
balanceDiv.textContent = '';
}
} catch (error) {
displayDiv.textContent = 'Error generating Bitcoin address.';
balanceDiv.textContent = '';
console.error(error);
}
}
/**
* Sets up the auto-update functionality based on the checkbox state.
*/
function setupAutoUpdate() {
const autoUpdateCheckbox = document.getElementById('autoUpdate');
const inputText = document.getElementById('inputText');
const hashTimes = document.getElementById('hashTimes');
function handleInputChange() {
if (autoUpdateCheckbox.checked) {
performHashing();
}
}
if (autoUpdateCheckbox.checked) {
inputText.addEventListener('input', handleInputChange);
hashTimes.addEventListener('input', handleInputChange);
} else {
inputText.removeEventListener('input', handleInputChange);
hashTimes.removeEventListener('input', handleInputChange);
}
}
/**
* Fetches the number of GitHub stars for the repository and updates the star count.
*/
async function fetchGitHubStars() {
const repo = 'ikrahul/SHA256-BTC-Generater'; // Replace with your GitHub repo in the format 'username/repo'
const starCountSpans = document.querySelectorAll('#star-count, #footer-star-count');
try {
const response = await fetch(`https://api.github.com/repos/${repo}`);
if (!response.ok) {
throw new Error('Network response was not ok');
}
const repoData = await response.json();
starCountSpans.forEach(span => {
span.textContent = repoData.stargazers_count;
});
} catch (error) {
console.error('Error fetching GitHub stars:', error);
starCountSpans.forEach(span => {
span.textContent = 'N/A';
});
}
}
// Event Listeners
document.getElementById('hashButton').addEventListener('click', performHashing);
document.getElementById('autoUpdate').addEventListener('change', () => {
setupAutoUpdate();
if (document.getElementById('autoUpdate').checked) {
performHashing();
}
});
document.getElementById('useCustomApi').addEventListener('change', () => {
const customApiInputs = document.querySelector('.custom-api-inputs');
if (document.getElementById('useCustomApi').checked) {
customApiInputs.style.display = 'block';
} else {
customApiInputs.style.display = 'none';
}
// Clear previous custom API inputs when unchecked
if (!document.getElementById('useCustomApi').checked) {
document.getElementById('customApiUrl').value = '';
document.getElementById('customApiKey').value = '';
}
});
// Initialize auto-update based on the checkbox state on page load
window.addEventListener('DOMContentLoaded', () => {
setupAutoUpdate();
if (document.getElementById('autoUpdate').checked) {
performHashing();
}
// Fetch GitHub stars on page load
fetchGitHubStars();
});
</script>
</body>
</html>