-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
285 lines (273 loc) · 9.61 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
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
const generateBtn = document.getElementById("generate-btn");
const codeBoxArea = document.getElementById("code");
const cryptoOptions = document.getElementById("crypto-options");
const copyBtn = document.getElementById("copy-btn");
// get the current year
const createdYear = new Date().getFullYear();
// Show/hide wallet address fields based on checkbox status if checked
cryptoOptions.addEventListener("change", (e) => {
const checkbox = e.target;
const ticker = checkbox.value;
const walletAddressField = document.querySelector(
`input[name='${ticker}']`
).parentNode;
if (checkbox.checked) {
walletAddressField.style.display = "block";
} else {
walletAddressField.style.display = "none";
}
}
);
// hide each individual input fields on startup
const cryptoFields = document.querySelectorAll(".crypto-field");
cryptoFields.forEach((field) => {
field.style.display = "none";
});
// after the text area inputs for wallet addresses are populated, when the user clicks the generate button, generate the code for a static website and put that code in the codeboxArea of the code box
generateBtn.addEventListener("click", (e) => {
e.preventDefault();
const codeBox = document.getElementById("code-box");
codeBox.style.display = "block";
const code = generateCode();
codeBoxArea.value = code;
});
// when the copy button is clicked, copy the code in the code box to the clipboard
copyBtn.addEventListener("click", (e) => {
e.preventDefault();
codeBoxArea.select();
document.execCommand("copy");
}
);
// urls for the images for all the coins
const coinUrls = {
"ADA" : "https://s2.coinmarketcap.com/static/img/coins/64x64/2010.png",
"BTC": "https://s2.coinmarketcap.com/static/img/coins/64x64/1.png",
"BCH" : "https://s2.coinmarketcap.com/static/img/coins/64x64/1831.png",
"BNB" : "https://s2.coinmarketcap.com/static/img/coins/64x64/1839.png",
"DOGE": "https://s2.coinmarketcap.com/static/img/coins/64x64/74.png",
"ETH": "https://s2.coinmarketcap.com/static/img/coins/64x64/1027.png",
"LTC" : "https://s2.coinmarketcap.com/static/img/coins/64x64/2.png",
"MATIC" : "https://s2.coinmarketcap.com/static/img/coins/64x64/3890.png",
"NEO" : "https://s2.coinmarketcap.com/static/img/coins/64x64/1376.png",
"SOL" : "https://s2.coinmarketcap.com/static/img/coins/64x64/5426.png",
"XMR" : "https://s2.coinmarketcap.com/static/img/coins/64x64/328.png",
"XRP" : "https://s2.coinmarketcap.com/static/img/coins/64x64/52.png"
};
// generate the code for the static website
function generateCode() {
let code = "";
// get the name of the organization from the text input of the form
const orgName = document.getElementById("org-name").value;
const orgSite = document.getElementById("org-website").value;
const cryptoOptions = document.querySelectorAll(
"#crypto-options input[type='checkbox']"
);
// get the text from each text input and keep track of which coin it goes to using the labels of the text boxes
const cryptoFields = document.querySelectorAll(".crypto-field");
const cryptoFieldsText = [];
cryptoFields.forEach((field) => {
const label = field.querySelector("label").textContent;
const input = field.querySelector("input").value;
cryptoFieldsText.push({ label, input });
}
);
// generate the code for the static website
//add style code to the website in a multiline string
code += `
<style>
body {
background-color: #000;
}
#crypto-donations {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.crypto-donation {
background-color: #f0f0f0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
margin: 1rem;
padding: 1rem;
border: 1px solid white;
border-radius: 20px;
}
.crypto-donation-header {
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
margin-top: 30px;
margin-bottom: 30px;
}
.crypto-donation-header img {
width: 2rem;
height: 2rem;
margin-right: 1rem;
}
.crypto-donation-header h3 {
margin: 0;
}
.crypto-donation-body {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.crypto-donation-body p {
margin: 0.5rem;
}
.code-box {
background-color: #e3e3e3;
padding: 20px;
border-radius: 10px;
}
.copy-btn {
background-color: #1DA1F2;
border: none;
color: white;
padding: 8px 20px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 2.5rem;
margin: 10px 2px;
cursor: pointer;
border-radius: 30px;
font-weight: bold;
}
.crypto-donation-top {
margin-bottom: 30px;
}
.thicc-text {
font-weight: bold;
font-size: 3rem;
}
.footer {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
height: 80px;
background-color: #f0f0f0;
border-radius: 30px;
box-shadow: 2px 2px 5px rgba(0,0,0,.3);
margin: 0 auto;
/* center text horizontally and vertically */
display: flex;
align-items: center;
justify-content: center;
text-align: center;
}
.footer a {
/* text-decoration: none; */
color: #000;
}
h1 {
color: #fff;
text-align: center;
font-size: 4rem;
margin-top: 50px;
}
h3 {
font-size: 5rem;
}
canvas {
padding-left: 0;
padding-right: 0;
margin-left: auto;
margin-right: auto;
display: block;
}
p {
font-size: 2rem;
}
.blank-space {
height: 100px;
}
</style>
`;
code += `
<script src="https://cdnjs.cloudflare.com/ajax/libs/qrious/4.0.2/qrious.min.js"></script>
<h1> Donate To ${orgName}!</h1>
`;
code += "<div id='crypto-donations'>";
cryptoOptions.forEach((option) => {
if (option.checked) {
let ticker = option.value;
let cryptoField = cryptoFieldsText.find(
(field) => field.label === option.parentNode.textContent
);
let walletAddress = cryptoField.input;
code += `
<div class='crypto-donation'>
<div class='crypto-donation-header'>
<img src='${coinUrls[ticker]}' style="width: 10vw; height: auto;">
<h3>${ticker}</h3>
</div>
<div class='crypto-donation-body'>
<div class="crypto-donation-top">
<p class="thicc-text">Send ${ticker} to the following address:</p>
<div class='${ticker}-code code-box'>
<p id='${ticker}-address' class="wallet-address"></p>
</div>
<button class="copy-btn" onclick="${ticker}copyCode()">Copy</button>
</div>
<div class='crypto-donation-bottom'>
<p class="thicc-text">Or scan the following QR code:</p>
<canvas id="${ticker}-qr"></canvas>
</div>
</div>
</div>
`;
// add javascript for the qr code
code += `
<script type="text/javascript">
var ${ticker}walletAddress = "${walletAddress}";
new QRious({
element: document.getElementById("${ticker}-qr"),
value: ${ticker}walletAddress,
size: 400
});
function ${ticker}copyCode() {
var textToCopy = ${ticker}walletAddress;
navigator.clipboard.writeText(${ticker}walletAddress);
}
var ${ticker}walletAddressElement = document.getElementById("${ticker}-address");
if (${ticker}walletAddress.length > 10) {
if (${ticker}walletAddress.length >= 15) {
var fp = ${ticker}walletAddress.substring(0, 10);
var lp = ${ticker}walletAddress.substring(${ticker}walletAddress.length - 5);
var mp = ".....";
${ticker}walletAddressElement.textContent = fp + mp + lp;
} else {
var shortenedText = ${ticker}walletAddress.substring(0, 10) + ".....";
${ticker}walletAddressElement.textContent = shortenedText;
}
} else {
${ticker}walletAddressElement.textContent = ${ticker}walletAddress;
}
</script>
`;
}
});
code += "</div>";
// add the footer
code += `
<div class="blank-space">
<p> </p>
</div>
<div class="footer">
<p id="copywright"></p>
</div>
<script>
const currentYear = new Date().getFullYear();
var copywrightele = document.getElementById("copywright");
copywrightele.innerHTML = "Copyright © ${createdYear}-" + currentYear + " <a href=\\"${orgSite}\\"> ${orgName}</a>";
</script>
`;
return code;
}