This repository has been archived by the owner on Mar 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.js
143 lines (134 loc) · 4.8 KB
/
main.js
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
var correctedAddress = ""
var qrcode = new QRCode("qrcode", {
text: "",
width: 128,
height: 128,
colorDark : "#000000",
colorLight : "#ffffff",
correctLevel : QRCode.CorrectLevel.M
});
var qrcode2 = new QRCode("qrcode2", {
text: "",
width: 128,
height: 128,
colorDark : "#000000",
colorLight : "#ffffff",
correctLevel : QRCode.CorrectLevel.M
});
window.onload = window.onhashchange = function() {
document.getElementById('addressToTranslate').value = window.location.hash.slice(1)
document.getElementById('addressToTranslate').oninput()
}
document.getElementById('demo').onclick = function() {
window.location.hash = '#1BpEi6DfDAUFd7GtittLSdBeYJvcoaVggu';
}
document.getElementsByClassName('btn btn-outline-primary btn-lg btn-block')[0].onclick = function() {
document.getElementById("addressToTranslate").value = "";
cleanResultAddress();
}
document.getElementById('correctedButton').onclick = function() {
document.getElementById('correctedButton').style = "display: none"
document.getElementById('addressToTranslate').value = correctedAddress
document.getElementById('addressToTranslate').oninput()
}
document.getElementById('copy').onclick = function() {
document.getElementById('copy').innerHTML = 'Copied';
document.getElementById('resultAddress').select();
document.execCommand('Copy');
window.getSelection().removeAllRanges();
}
document.getElementById("addressToTranslate").oninput = function() {
cleanResultAddress();
input = document.getElementById("addressToTranslate").value;
try {
if (
input[11] == ":" &&
input.length == 54 &&
(input[12] == "q" || input[12] == "p")
) {
for (var i = 0; i < 11; i++) {
if (input[i] != "bitcoincash"[i]) {
cleanResultAddress();
return;
}
}
setResultOldAddress(
parseAndConvertCashAddress("bitcoincash", input.slice(12))
);
} else if (
input[0] == "1" ||
(input[0] == "3" && input.length > 25 && input.length < 35)
) {
setResultCashAddress(parseAndConvertOldAddress(input));
} else if ((input[0] == "q" || input[0] == "p") && input.length == 42) {
setResultOldAddress(parseAndConvertCashAddress("bitcoincash", input));
} else if (
input[7] == ":" &&
input.length == 50 &&
(input[8] == "q" || input[8] == "p")
) {
for (var i = 0; i < 7; i++) {
if (input[i] != "bchtest"[i]) {
cleanResultAddress();
return;
}
}
setResultOldAddress(
parseAndConvertCashAddress("bchtest", input.slice(8))
);
} else if (
input[11] == ":" &&
input.length == 54 &&
(input[12] == "Q" || input[12] == "P")
) {
for (var i = 0; i < 11; i++) {
if (input[i] != "BITCOINCASH"[i]) {
cleanResultAddress();
return;
}
}
setResultCashAddress(parseAndConvertOldAddress(input.toLowerCase()));
} else if (input[0] == "m" || input[0] == "n" || input[0] == "2") {
setResultCashAddress(parseAndConvertOldAddress(input));
} else if (
(input[0] == "C" || input[0] == "H") &&
input.length > 25 &&
input.length < 36
) {
setResultCashAddress(parseAndConvertOldAddress(input));
} else {
cleanResultAddress();
}
} catch (e) {
cleanResultAddress();
}
};
function setResultOldAddress(a) {
// Error correction
if (a == "") {return}
qrcode.makeCode(document.getElementById("addressToTranslate").value.toUpperCase());
document.getElementById("qrcode").style = "display: inline-block;";
document.getElementById("resultAddress").value = a;
qrcode2.makeCode(document.getElementById("resultAddress").value);
document.getElementById("qrcode2").style = "display: inline-block;";
document.getElementById("resultAddressBlock").style.display = "block";
document.getElementById('copy').innerHTML = 'Copy';
}
function setResultCashAddress(a) {
qrcode.makeCode(document.getElementById("addressToTranslate").value);
document.getElementById("qrcode").style = "display: inline-block;";
document.getElementById("resultAddress").value = a;
qrcode2.makeCode(document.getElementById("resultAddress").value.toUpperCase());
document.getElementById("qrcode2").style = "display: inline-block;";
document.getElementById("resultAddressBlock").style.display = "block";
document.getElementById('copy').innerHTML = 'Copy';
}
function cleanResultAddress() {
window.location.hash = "";
document.getElementById("resultAddress").value = "";
document.getElementById("resultAddressBlock").style.display = "none";
document.getElementById("correctedButton").style = "display: none";
document.getElementById("qrcode2").style = "display: none;";
document.getElementById("qrcode").style = "display: none;";
document.getElementById('copy').innerHTML = 'Copy';
}