(function () { var root = document.documentElement; var button = document.getElementById('theme-toggle'); if (button) { button.addEventListener('click', function () { var next = root.getAttribute('data-theme') === 'light' ? 'dark' : 'light'; root.setAttribute('data-theme', next); try { localStorage.setItem('tinyauth-web-theme', next); } catch (e) {} }); } var filter = document.getElementById('key-filter'); var table = document.getElementById('key-table'); if (filter && table) { filter.addEventListener('input', function () { var term = filter.value.toLowerCase(); Array.prototype.forEach.call(table.tBodies[0].rows, function (row) { row.style.display = row.textContent.toLowerCase().indexOf(term) === -1 ? 'none' : ''; }); }); } document.querySelectorAll('dialog[data-autoopen]').forEach(function (dialog) { if (typeof dialog.showModal === 'function') { dialog.showModal(); } }); document.querySelectorAll('[data-close]').forEach(function (btn) { btn.addEventListener('click', function () { var dialog = btn.closest('dialog'); if (dialog) { dialog.close(); } }); }); var float = document.createElement('div'); float.className = 'tip-float'; document.body.appendChild(float); function place(icon) { var rect = icon.getBoundingClientRect(); float.style.display = 'block'; var left = Math.min(rect.left, window.innerWidth - float.offsetWidth - 12); float.style.left = Math.max(12, left) + 'px'; var top = rect.bottom + 8; if (top + float.offsetHeight > window.innerHeight - 12) { top = Math.max(12, rect.top - float.offsetHeight - 8); } float.style.top = top + 'px'; } function show(icon) { var tip = icon.querySelector('.tip'); if (!tip) { return; } float.innerHTML = tip.innerHTML; place(icon); } function hide() { float.style.display = 'none'; } document.querySelectorAll('.help').forEach(function (icon) { icon.addEventListener('mouseenter', function () { show(icon); }); icon.addEventListener('mouseleave', hide); icon.addEventListener('focus', function () { show(icon); }); icon.addEventListener('blur', hide); }); })();