CoolFace
Apppublic

cymic/Waifu_Diffusion_Webui

sourceHugging Faceupdated 4y agoView on Hugging Face
1likes
script.js62 linesDownload Raw Back to root
1function gradioApp(){2    return document.getElementsByTagName('gradio-app')[0].shadowRoot;3}4 5function get_uiCurrentTab() {6    return gradioApp().querySelector('.tabs button:not(.border-transparent)')7}8 9uiUpdateCallbacks = []10uiTabChangeCallbacks = []11let uiCurrentTab = null12 13function onUiUpdate(callback){14    uiUpdateCallbacks.push(callback)15}16function onUiTabChange(callback){17    uiTabChangeCallbacks.push(callback)18}19 20function runCallback(x){21    try {22        x()23    } catch (e) {24        (console.error || console.log).call(console, e.message, e);25    }26}27function executeCallbacks(queue) {28    queue.forEach(runCallback)29}30 31document.addEventListener("DOMContentLoaded", function() {32    var mutationObserver = new MutationObserver(function(m){33        executeCallbacks(uiUpdateCallbacks);34        const newTab = get_uiCurrentTab();35        if ( newTab && ( newTab !== uiCurrentTab ) ) {36            uiCurrentTab = newTab;37            executeCallbacks(uiTabChangeCallbacks);38        }39    });40    mutationObserver.observe( gradioApp(), { childList:true, subtree:true })41});42 43/**44 * checks that a UI element is not in another hidden element or tab content45 */46function uiElementIsVisible(el) {47    let isVisible = !el.closest('.\\!hidden');48    if ( ! isVisible ) {49        return false;50    }51 52    while( isVisible = el.closest('.tabitem')?.style.display !== 'none' ) {53        if ( ! isVisible ) {54            return false;55        } else if ( el.parentElement ) {56            el = el.parentElement57        } else {58            break;59        }60    }61    return isVisible;62}