diff --git a/resources/js/tryitout.js b/resources/js/tryitout.js index 4a55df1f..d12118fd 100644 --- a/resources/js/tryitout.js +++ b/resources/js/tryitout.js @@ -1,5 +1,26 @@ window.abortControllers = {}; +function cacheAuthValue() { + // Whenever the auth header is set for one endpoint, cache it for the others + window.lastAuthValue = ''; + document.querySelectorAll(`label[id^=auth-] > input`) + .forEach(el => { + el.addEventListener('change', (event) => { + window.lastAuthValue = event.target.value; + document.querySelectorAll(`label[id^=auth-] > input`) + .forEach(otherInput => { + if (otherInput === el) return; + // Don't block the main thread + setTimeout(() => { + otherInput.value = window.lastAuthValue; + }, 0); + }); + }); + }); +} + +window.addEventListener('DOMContentLoaded', cacheAuthValue); + function getCookie(name) { if (!document.cookie) { return null;