Repository navigation
Expand file tree
/
Copy pathsquare.html
More file actions
349 lines (313 loc) · 14.6 KB
/
Copy pathsquare.html
File metadata and controls
349 lines (313 loc) · 14.6 KB
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
---
layout: null
title: See information about a Square
description: "Look up individual Su Squares by number and view their latest on-chain personalization data as it appears on the TenThousandSu.com homepage billboard."
permalink: /square
image: "{{ site.baseurl }}/assets/images/su-OG.png"
---
<!doctype html>
<html lang="en">
<head>
<script>window.SITE_BASEURL = "{{ site.baseurl }}";</script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
{% include pwa-meta-tags.html %}
{% seo %}
<link rel="stylesheet" href="{{ site.baseurl }}/assets/css/main.css">
<link rel="stylesheet" href="{{ site.baseurl }}/assets/billboard/billboard.css">
<link rel="stylesheet" href="{{ site.baseurl }}/assets/css/square.css">
<link rel="stylesheet" href="{{ site.baseurl }}/assets/billboard/wrappers/square-location.css">
<link rel="stylesheet" href="{{ site.baseurl }}/assets/square-lookup/styles.css">
<link rel="stylesheet" href="{{ site.baseurl }}/assets/modals/leaving-modal/modal.css">
<link rel="stylesheet" href="{{ site.baseurl }}/assets/modals/blocked-modal/blocked-modal.css">
<script src="{{ site.baseurl }}/assets/modals/blocked-modal/blocked-modal.js"></script>
<script src="{{ site.baseurl }}/assets/modals/leaving-modal/modal-core.js"></script>
<script src="{{ site.baseurl }}/assets/modals/leaving-modal/link-guard.js"></script>
{% include nav-menu-head.html %}
{% include alert-modal-head.html %}
{% include offline-modal-head.html %}
{% include jsonld-nav.html %}
{% include jsonld/webpage.html %}
</head>
<body class="square-body">
{% include nav-header.html %}
<main id="main-content" class="fade-target square-main">
<section class="square-default-state" id="square-default-state">
<h1>Look up <span style="white-space: nowrap;">Su Squares</span></h1>
<p class="square-default-state__description">
Enter a minted Square number to review its appearance and history.
</p>
</section>
<article class="square-page square-page--hidden" id="square-details" aria-hidden="true">
<h1>Square #<span id="square-number">...</span></h1>
<div id="image"></div>
<div class="dl-wrapper">
<dl class="dl-styled" data-testid="square-nft-table">
<dt>Minted</dt>
<dd id="minted"></dd>
<dt>Personalized</dt>
<dd id="personalized"></dd> <!-- also show #X most recent -->
<dt>Title</dt>
<dd id="title"></dd>
<dt>Link</dt>
<dd id="link"></dd>
</dl>
</div>
<div id="etherscan-button-wrapper" style="text-align:center; margin: 1.5rem 0;">
<a id="view-etherscan" class="btn btn-lg square-lookup__submit" href="#" target="_blank" rel="noopener"
style="display:none;">View NFT on Etherscan</a>
</div>
<h2>Location</h2>
<div class="square-location-wrapper">
<div class="square-location">
<div class="square-location__canvas">
<img id="theImage" class="square-location__image"
src="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" alt="All Su Squares">
<img id="arrow" class="square-location__arrow" src="{{ site.baseurl }}/assets/images/dr.png" alt="Location">
</div>
</div>
</div>
<h2>Emojified</h2>
<pre id="emojified" data-testid="square-emojified"></pre>
<button class="btn" id="copy-emojified">Copy</button>
</article>
{% include square-lookup.html variant="narrow" %}
</main>
<footer>
<small>
No cookies. No analytics. Not responsible for content of linked sites. Images shown on homepage are © their
respective owners. This image <a target="_blank"
href="https://github.com/su-squares/tenthousandsu.com/actions/workflows/load-from-blockchain.yml">refreshes
hourly</a>. To the extent possible under law, Su Entriken has waived
all copyright and related or neighboring rights to the TenThousandSu.com website. This work is published from the
United States.
</small>
</footer>
<script type="module">
import { buildBlockUrl, buildTokenUrl, getExplorerName } from "{{ site.baseurl }}/assets/web3/services/explorer-links.js";
import { getWeb3Config } from "{{ site.baseurl }}/assets/web3/config/index.js";
import { initSquareLocation } from "{{ site.baseurl }}/assets/billboard/wrappers/square-location.js";
import { renderSafeLink } from "{{ site.baseurl }}/assets/js/link-utils.js";
document.addEventListener("DOMContentLoaded", () => {
const baseurl = window.SITE_BASEURL || '';
// Fade-in animation trigger for main content only
const mainContent = document.getElementById('main-content');
if (mainContent) {
setTimeout(() => {
mainContent.classList.add('fade-visible');
}, 500); // 0.5s delay before fade-in
}
const runtimeCfg = window.suWeb3 || window.SU_WEB3 || {};
const runtimeChain =
(runtimeCfg.chain || runtimeCfg.CHAIN || runtimeCfg.network || runtimeCfg.NETWORK || "mainnet").toString().toLowerCase();
const runtimeAssetBases = runtimeCfg.assetBases || {};
let assetBase = String(runtimeAssetBases[runtimeChain] || "/build").replace(/\/+$/, "");
if (baseurl && !assetBase.startsWith(baseurl)) {
assetBase = baseurl + assetBase;
}
const assetPath = (rel) => `${assetBase}/${String(rel).replace(/^\/+/, "")}`;
const detailSection = document.getElementById("square-details");
const defaultSection = document.getElementById("square-default-state");
const hideDetails = () => {
if (detailSection) {
detailSection.classList.add("square-page--hidden");
detailSection.setAttribute("aria-hidden", "true");
}
if (defaultSection) {
defaultSection.hidden = false;
}
};
const revealDetails = () => {
if (detailSection) {
detailSection.classList.remove("square-page--hidden");
detailSection.removeAttribute("aria-hidden");
}
if (defaultSection) {
defaultSection.hidden = true;
}
};
const hashValue = window.location.hash.replace(/^#/, "").trim();
const isNumericHash = /^\d+$/.test(hashValue);
const squareNumber = isNumericHash ? parseInt(hashValue, 10) : NaN;
const hasValidHash = Number.isInteger(squareNumber) && squareNumber >= 1 && squareNumber <= 10000;
if (!hasValidHash) {
hideDetails();
return;
}
revealDetails();
const personalizations = fetch(assetPath('squarePersonalizations.json')).then(response => response.json());
const extras = fetch(assetPath('squareExtra.json')).then(response => response.json());
const explorerName = getExplorerName();
const { contracts } = getWeb3Config();
Promise.all([personalizations, extras]).then(([personalizations, extras]) => {
// Each personalization is [title, href] or null
// Each extra is [mintedBlock, updatedBlock, mainIsPersonalized, version] or null
// Arrays are zero indexed, but the first Su Square number is 1!
const personalization = personalizations[squareNumber - 1];
const elSquareNumber = document.getElementById("square-number");
elSquareNumber.innerText = squareNumber;
const elMinted = document.getElementById('minted');
const elViewEtherscan = document.getElementById('view-etherscan');
const mintedData = extras[squareNumber - 1];
const isMinted = Boolean(mintedData);
if (isMinted) {
const mintedBlock = mintedData[0];
const blockUrl = buildBlockUrl(mintedBlock);
elMinted.textContent = "";
if (blockUrl) {
const mintedAnchor = document.createElement("a");
mintedAnchor.href = blockUrl;
mintedAnchor.target = "_blank";
mintedAnchor.rel = "noopener";
mintedAnchor.textContent = `Block ${mintedBlock}`;
elMinted.appendChild(mintedAnchor);
} else {
elMinted.textContent = `Block ${mintedBlock}`;
}
const tokenUrl = buildTokenUrl(contracts.primary, squareNumber);
if (tokenUrl) {
elViewEtherscan.href = tokenUrl;
elViewEtherscan.textContent = `View NFT on ${explorerName}`;
elViewEtherscan.style.display = 'inline-block';
}
} else {
elMinted.innerText = 'Not minted';
elViewEtherscan.style.display = 'none';
}
const elPersonalized = document.getElementById('personalized');
const hasPersonalization = Boolean(personalization && (personalization[0] || personalization[1])) || Boolean(mintedData && mintedData[2]);
if (isMinted && hasPersonalization) {
const personalizedBlock = mintedData ? mintedData[1] : null;
if (personalizedBlock) {
const personalizedBlockUrl = buildBlockUrl(personalizedBlock);
elPersonalized.textContent = "";
if (personalizedBlockUrl) {
const personalizedAnchor = document.createElement("a");
personalizedAnchor.href = personalizedBlockUrl;
personalizedAnchor.target = "_blank";
personalizedAnchor.rel = "noopener";
personalizedAnchor.textContent = `Block ${personalizedBlock}`;
elPersonalized.appendChild(personalizedAnchor);
} else {
elPersonalized.textContent = `Block ${personalizedBlock}`;
}
} else {
elPersonalized.innerText = 'Personalized';
}
} else {
elPersonalized.innerText = 'Not personalized';
}
const elTitle = document.getElementById('title');
elTitle.innerText = personalization ? personalization[0] : 'Not personalized';
const elLink = document.getElementById('link');
const hasPersonalizationLink = isMinted && personalization && personalization[1];
if (hasPersonalizationLink) {
const hrefRaw = personalization[1];
const guardedAnchor = renderSafeLink(elLink, hrefRaw, { anchorId: "square-out-link" });
if (guardedAnchor) {
if (window.SuLeavingLinkGuard && typeof window.SuLeavingLinkGuard.guardLink === 'function') {
window.SuLeavingLinkGuard.guardLink(guardedAnchor);
} else if (window.SuLeavingModal && typeof window.SuLeavingModal.gateAnchor === 'function') {
window.SuLeavingModal.gateAnchor(guardedAnchor);
}
}
} else {
elLink.innerText = 'Not personalized';
}
const elEmojified = document.getElementById('emojified');
// Set image
const row = Math.floor((squareNumber - 1) / 100); // 0 indexed
const col = (squareNumber - 1) % 100; // 0 indexed
const elImage = document.getElementById('image');
elImage.style.backgroundImage = `url("${assetPath('wholeSquare.webp')}")`;
elImage.style.backgroundPosition = `-${col * 10}px -${row * 10}px`;
elImage.style.height = '10px';
elImage.style.width = '10px';
elImage.style.display = 'inline-block';
elImage.style.zoom = '20';
elImage.style.imageRendering = 'pixelated';
// Initialize location view with arrow positioning
const mapImage = document.getElementById('theImage');
if (mapImage) {
mapImage.src = assetPath('wholeSquare.webp');
}
initSquareLocation({
canvas: document.querySelector('.square-location__canvas'),
image: mapImage,
arrow: document.getElementById('arrow'),
squareNumber,
arrowBasePath: 'assets/images',
});
// Emoji squares and RGB values for ⬛⬜🟥🟧🟨🟩🟦🟪🟫
const emojis = [
{ "emoji": "⬛", "red": 0, "green": 0, "blue": 0 },
{ "emoji": "⬜", "red": 255, "green": 255, "blue": 255 },
{ "emoji": "🟥", "red": 255, "green": 0, "blue": 0 },
{ "emoji": "🟧", "red": 255, "green": 165, "blue": 0 },
{ "emoji": "🟨", "red": 255, "green": 255, "blue": 0 },
{ "emoji": "🟩", "red": 0, "green": 128, "blue": 0 },
{ "emoji": "🟦", "red": 0, "green": 0, "blue": 255 },
{ "emoji": "🟪", "red": 128, "green": 0, "blue": 128 },
{ "emoji": "🟫", "red": 139, "green": 69, "blue": 19 },
]
// Create canvas
const canvas = document.createElement('canvas');
canvas.width = 10;
canvas.height = 10;
// Add wholeSquare to canvas
const context = canvas.getContext('2d');
const image = new Image();
image.src = assetPath('wholeSquare.webp');
image.onload = function () {
context.drawImage(image, col * 10, row * 10, 10, 10, 0, 0, 10, 10);
// Get pixels
const imageData = context.getImageData(0, 0, 10, 10);
const pixels = imageData.data;
// Loop pixels
let emojiString = '';
for (let i = 0; i < pixels.length; i += 4) {
// Get pixel color
const red = pixels[i];
const green = pixels[i + 1];
const blue = pixels[i + 2];
// Find closest emoji
let closestEmoji = emojis[0];
let closestDistance = 195075;
for (let j = 0; j < emojis.length; j++) {
const emoji = emojis[j];
const distance = Math.sqrt(
Math.pow(emoji.red - red, 2) +
Math.pow(emoji.green - green, 2) +
Math.pow(emoji.blue - blue, 2)
);
if (distance < closestDistance) {
closestEmoji = emoji;
closestDistance = distance;
}
}
emojiString += closestEmoji.emoji;
// Add line break
if (i % 40 === 36) {
emojiString += "<br>";
}
}
// Set emoji string
elEmojified.innerHTML = emojiString;
}
// Copy emojified
const elCopyEmojified = document.getElementById('copy-emojified');
elCopyEmojified.addEventListener('click', () => {
const range = document.createRange();
range.selectNode(elEmojified);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
document.execCommand('copy');
window.getSelection().removeAllRanges();
});
});
});
</script>
<script type="module" src="{{ site.baseurl }}/assets/square-lookup/index.js"></script>
<script src="{{ site.baseurl }}/assets/js/pwa-init.js"></script>
</body>
</html>