Skip to content

Instantly share code, notes, and snippets.

@brianorwhatever
Last active March 23, 2023 05:34
Show Gist options
  • Select an option

  • Save brianorwhatever/20d1de96e4fbbbd0178cc5f79cd6f55f to your computer and use it in GitHub Desktop.

Select an option

Save brianorwhatever/20d1de96e4fbbbd0178cc5f79cd6f55f to your computer and use it in GitHub Desktop.
Decode & Insert VerifiableCollectible Images
function insertCollectibleImageBeforePreTag() {
// Find the <pre> tag in the document
const preTag = document.querySelector('pre');
if (!preTag) {
console.error('No <pre> tag found in the document.');
return;
}
// Parse the JSON content of the <pre> tag
let jsonData;
try {
jsonData = JSON.parse(preTag.textContent);
} catch (error) {
console.error('Invalid JSON content in the <pre> tag.');
return;
}
// Check if the "type" value is an array containing "VerifiableCollectible"
const typeArray = jsonData.type;
if (Array.isArray(typeArray) && typeArray.includes('VerifiableCollectible')) {
const imageSrc = jsonData.credentialSubject?.image;
if (imageSrc) {
// Create an <img> tag and set its "src" attribute
const imgTag = document.createElement('img');
imgTag.src = imageSrc;
// Insert the <img> tag before the <pre> tag
preTag.parentNode.insertBefore(imgTag, preTag);
} else {
console.error('No "credentialSubject.image" property found in the JSON data.');
}
} else {
console.error('The JSON data does not meet the required conditions.');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment