Last active
March 23, 2023 05:34
-
-
Save brianorwhatever/20d1de96e4fbbbd0178cc5f79cd6f55f to your computer and use it in GitHub Desktop.
Revisions
-
brianorwhatever revised this gist
Mar 23, 2023 . 1 changed file with 20 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ function insertCollectibleImageBeforePreTags() { // Find all <pre> tags in the document const preTags = document.querySelectorAll('pre'); @@ -8,6 +8,12 @@ function insertCollectibleImages() { } preTags.forEach((preTag) => { // Check if the image has already been inserted const prevSibling = preTag.previousElementSibling; if (prevSibling && prevSibling.tagName.toLowerCase() === 'img') { return; } let jsonData; try { jsonData = JSON.parse(preTag.textContent); @@ -35,4 +41,17 @@ function insertCollectibleImages() { console.error('The JSON data does not meet the required conditions.'); } }); } // Run the function once immediately insertCollectibleImageBeforePreTags(); // Find the scrolling container with the attribute 'data-test-id' and value 'virtuoso-scroller' const scrollingContainer = document.querySelector('[data-test-id="virtuoso-scroller"]'); if (scrollingContainer) { // Run the function whenever the scrolling container is scrolled scrollingContainer.addEventListener('scroll', insertCollectibleImageBeforePreTags); } else { console.error('No scrolling container found with the class "scrolling-container".'); } -
brianorwhatever revised this gist
Mar 23, 2023 . 2 changed files with 38 additions and 37 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,37 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ function insertCollectibleImages() { // Find all <pre> tags in the document const preTags = document.querySelectorAll('pre'); if (preTags.length === 0) { console.error('No <pre> tags found in the document.'); return; } preTags.forEach((preTag) => { let jsonData; try { jsonData = JSON.parse(preTag.textContent); } catch (error) { console.error('Invalid JSON content in a <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.'); } }); } -
brianorwhatever revised this gist
Mar 23, 2023 . No changes.There are no files selected for viewing
-
brianorwhatever renamed this gist
Mar 23, 2023 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
brianorwhatever created this gist
Mar 23, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ 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.'); } }