From ef7de1e752ea47a94714bdde5b6c630006f34f63 Mon Sep 17 00:00:00 2001 From: JD <156010594+5u6r054@users.noreply.github.com> Date: Wed, 31 Jul 2024 16:15:10 -0700 Subject: [PATCH] correctly autoselect http/s Signed-off-by: JD <156010594+5u6r054@users.noreply.github.com> --- pkg/api/templates/swagger.html | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/pkg/api/templates/swagger.html b/pkg/api/templates/swagger.html index 27a9634a..eebb7ded 100644 --- a/pkg/api/templates/swagger.html +++ b/pkg/api/templates/swagger.html @@ -31,12 +31,29 @@ ], layout: "StandaloneLayout", onComplete: function() { - const currentScheme = window.location.protocol.slice(0, -1); - const schemeSelect = document.querySelector('.scheme-container select'); - if (schemeSelect) { - schemeSelect.value = currentScheme; - schemeSelect.dispatchEvent(new Event('change')); - } + setTimeout(function() { + const currentScheme = window.location.protocol.slice(0, -1); + const schemeSelect = document.querySelector('.scheme-container select'); + if (schemeSelect) { + schemeSelect.value = currentScheme; + schemeSelect.dispatchEvent(new Event('change')); + } + }, 100); // Small delay to ensure UI is fully rendered + + // Add this after the setTimeout in the onComplete function + const observer = new MutationObserver(function(mutations) { + mutations.forEach(function(mutation) { + if (mutation.type === 'childList' && mutation.addedNodes.length > 0) { + const schemeSelect = document.querySelector('.scheme-container select'); + if (schemeSelect && schemeSelect.value !== currentScheme) { + schemeSelect.value = currentScheme; + schemeSelect.dispatchEvent(new Event('change')); + } + } + }); + }); + + observer.observe(document.body, { childList: true, subtree: true }); } }); }