-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
252 lines (231 loc) · 7.62 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Banner Check</title>
<link rel="shortcut icon" href="favicon.ico" />
<style>
@import url(fonts/carbon-bold.css);
body {
margin-top: 50px;
text-align: center;
background: black;
}
body, input {
font-size: 18px;
color: white;
text-transform: uppercase;
font-family: "Carbon Bold", "Helvetica Neue", Arial, sans-serif;
}
form, p {
padding: 1em;
}
p {
line-height: 2em;
}
input {
background: #111;
padding: .5em;
outline: none;
border: none;
}
input:focus {
background: #222;
}
input[type="submit"]:hover {
cursor: pointer;
background: #222;
}
input[type="submit"]:active {
position: relative;
top: 1px;
}
a {
color: white;
}
canvas {
border: 5px #111 solid;
}
.check-container {
display: inline-block;
position: relative;
padding-right: 35px;
padding-top: 4px;
margin-top: 20px;
margin-bottom: 12px;
margin-right: 12px;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.check-container input {
position: absolute;
opacity: 0;
cursor: pointer;
height: 0;
width: 0;
}
.check {
position: absolute;
top: 0;
right: 0;
height: 25px;
width: 25px;
background-color: #111;
border-radius: 5px;
}
.check::before {
content: " ";
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
border-radius: 5px;
background-color: #111;
transform: rotateY(0deg) rotate(45deg);
}
.check-container:hover input ~ .check, .check-container:hover input ~ .check::before {
background-color: #222;
}
.check-container:active {
top: 1px;
}
.check-container input:checked ~ .check, .check-container input:checked ~ .check::before {
background-color: #60B1F4;
}
.check:after {
content: "";
position: absolute;
display: none;
}
.check-container input:checked ~ .check:after {
display: block;
}
.check-container .check:after {
left: 9px;
top: 5px;
width: 5px;
height: 10px;
border: solid #111;
border-width: 0 3px 3px 0;
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}
</style>
</head>
<body>
<h1>Banner Check</h1>
<form action="" id="form">
<div>
<input type="text" id="token_ids" name="ids" placeholder="4094,4095,4096" />
<input type="submit" value="Generate" />
</div>
<div>
<label class="check-container">Include Token Ids?<input type="checkbox" name="include_token_ids" id="include_token_ids" /> <span class="check"></span></label>
</div>
</form>
<canvas id="banner" width="1500" height="500"></canvas>
<form action="" id="download" style="display: none;">
<input type="submit" value="Download ↓" />
</form>
<p>
This banner may or may not be notable.
<br />
Made for enjoyoors of <a href="https://checks.art" target="_blank">VV Checks</a> by <a href="https://twitter.com/jackbutcher" target="_blank">Jack Butcher</a>.
<br />
Created by <a href="https://twitter.com/0xdownshift" target="_blank">downshift.eth</a>.
</p>
<script type="module">
import {ethers} from "https://cdnjs.cloudflare.com/ajax/libs/ethers/6.0.3/ethers.min.js";
const provider = new ethers.AlchemyProvider("mainnet", "UmMROr9RT6mlpwWnRyKZF2m0CKeDUM8-");
// application binary interface
const abi = [{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"svg","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"}];
const contract = new ethers.Contract("0x036721e5A769Cc48B3189EFbb9ccE4471E8A48B1", abi, provider);
const parser = new DOMParser();
let tokenIds;
function validateIds(string) {
const pattern = /^(\d{1,5},){0,4}\d{1,5}$/;
const result = pattern.test(string);
if (!result) {
alert('Please provide between 1 and 5 valid token IDs in the following format: 4094,4095,4096');
}
return result;
}
// get token ids from url, if present
const params = new Proxy(new URLSearchParams(window.location.search), {
get: (searchParams, prop) => searchParams.get(prop),
});
let ids = params.ids;
const includeTokenIds = !!params.include_token_ids;
if (includeTokenIds) {
document.getElementById('include_token_ids').setAttribute("checked", "checked");
}
if (ids) {
ids = ids.replace(/\s/g, "");
if (validateIds(ids)) {
document.getElementById('token_ids').value = ids;
tokenIds = ids.split(",");
const getSVGs = tokenIds.map(id => contract.svg(id));
let svgs = await Promise.all(getSVGs);
// alter styling of svgs
svgs = svgs.map(data => {
const node = parser.parseFromString(data, "image/svg+xml");
node.firstChild.setAttribute("style", "background: none;");
node.firstChild.setAttribute("width", 500);
node.firstChild.setAttribute("height", 500);
node.querySelectorAll('rect')[1].setAttribute("fill", "none");
return node.firstChild.outerHTML;
});
// paint canvas black
const canvas = document.getElementById("banner");
const ctx = canvas.getContext("2d");
ctx.rect(0, 0, 1500, 500);
ctx.fill();
// draw svgs onto canvas
const DOMURL = window.URL || window.webkitURL || window;
const offset = 1500 / (svgs.length + 1);
svgs.forEach((data, i) => {
const img = new Image();
const svg = new Blob([data], {type: 'image/svg+xml'});
const url = DOMURL.createObjectURL(svg);
img.onload = function() {
ctx.drawImage(img, (offset * (i + 1)) - 250, 0, 500, 500);
DOMURL.revokeObjectURL(url);
}
img.src = url;
if (includeTokenIds) {
// draw token id
ctx.font = "26px Carbon Bold";
ctx.fillStyle = "#ffffff";
ctx.textAlign = "center";
ctx.fillText(tokenIds[i], (offset * (i + 1)), 430);
}
});
document.getElementById('download').setAttribute("style", "display:block;");
}
}
function validateForm(e) {
let tokenIds = document.getElementById('token_ids').value;
tokenIds = tokenIds.replace(/\s/g, "");
if (!validateIds(tokenIds)) {
e.preventDefault();
}
}
const form = document.getElementById('form');
form.addEventListener('submit', validateForm);
const downloadForm = document.getElementById('download');
downloadForm.addEventListener('submit', download);
function download(e) {
e.preventDefault();
const link = document.createElement('a');
link.download = 'banner-check.png';
link.href = document.getElementById('banner').toDataURL()
link.click();
}
</script>
</body>
</html>