Last active
October 22, 2023 01:25
-
-
Save khursani8/08c8dae24d894c65ae2bd87dbc78d8a9 to your computer and use it in GitHub Desktop.
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 characters
| // Create a function to check for the live preview | |
| function checkLivePreview() { | |
| console.log("123") | |
| var script = document.createElement('script');script.src = "https://code.jquery.com/jquery-3.4.1.min.js";document.getElementsByTagName('head')[0].appendChild(script); | |
| // const parentElement = document.querySelector('gradio-app'); | |
| // const shadowRoot = parentElement.shadowRoot; | |
| const livePreview = document.querySelector('.livePreview'); | |
| // const livePreview = $('.livePreview'); | |
| if (livePreview) { | |
| // Initialize variables to hold highest resolution and corresponding image node | |
| let highestResolution = 0; | |
| let highestResImgNode = null; | |
| // Loop through all child nodes in livePreview to find the image with the highest resolution | |
| for (let imgNode of livePreview.querySelectorAll('img')) { | |
| const resolution = imgNode.naturalHeight * imgNode.naturalWidth; | |
| if (resolution > highestResolution) { | |
| highestResolution = resolution; | |
| highestResImgNode = imgNode; | |
| } | |
| } | |
| // If no suitable image found, skip | |
| if (highestResImgNode === null || highestResImgNode.naturalHeight < 1100) { | |
| console.log("skip"); | |
| return; | |
| } | |
| // Create a new window for the gallery | |
| const galleryWindow = window.open('', 'galleryWindow', 'width=100%,height=100%,resizable=yes,scrollbars=yes'); | |
| // Clone the highest resolution image | |
| const highestResImgNodeClone = highestResImgNode.cloneNode(); | |
| highestResImgNodeClone.style.width = '100%'; | |
| highestResImgNodeClone.style.height = '100%'; | |
| // Populate the new window | |
| galleryWindow.document.body.innerHTML = highestResImgNodeClone.outerHTML; | |
| galleryWindow.document.body.style.position = 'fixed'; | |
| galleryWindow.document.body.style.top = '0'; | |
| galleryWindow.document.body.style.right = '0'; | |
| } | |
| } | |
| // Call the function every 1 second | |
| out = setInterval(checkLivePreview, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment