////////////// // Against The Wall // by jiwa // 2025 // https://jiwa.art //////////////////////// let inscriptionId = window.location.pathname.split("/").pop(); let ids = []; var inscriptionData ={ hash : inscriptionId, child : false, level : -1 } async function children() { let more = true; let page = 0; while (more) { try { const response = await fetch('/r/children/' + inscriptionId + '/' + page); if (!response.ok) { throw new Error('Network response was not ok'); } const data = await response.json(); if(data.ids) ids = ids.concat(data.ids); more = data.more; page++; } catch (error) { console.error("Error fetching data:", error); more = false; } } } children().then(()=>{ if (ids.length > 0) { let lastItem = ids[ids.length - 1]; fetch('/r/metadata/' + lastItem) .then(response => { return response.json(); }) .then(data => { try { let hexString = data; if (typeof data === 'string') { hexString = data.replace(/^"(.*)"$/, '$1'); } const bytes = new Uint8Array(hexString.match(/.{1,2}/g).map(byte => parseInt(byte, 16))); const metadata = window.cbor.decode(bytes.buffer); if (metadata && metadata.level) { inscriptionData.level = metadata.level; console.log("Level set to:", inscriptionData.level); } else { //no metadata } } catch (error) { console.error("Error decoding CBOR:", error); } }) .catch(error => { console.error("Error:", error); }) .finally(() => { if(inscriptionData.level == -1){ inscriptionData.level = ids.length; } sendData(); }); } else { inscriptionData.level = 0; sendData(); } }) // Function to send data to parent function sendData() { // Send the inscription data to the parent page window.parent.postMessage({ type: 'inscriptionData', value: inscriptionData }, '*'); // Replace '*' with parent's origin in production }