(function() {
'use strict';
function copyCode(button) {
const codeBlock = button.closest('.code-block');
const code = codeBlock.querySelector('code').textContent;
navigator.clipboard.writeText(code).then(() => {
const originalText = button.textContent;
button.textContent = 'Copied!';
button.style.color = 'var(--success)';
setTimeout(() => {
button.textContent = originalText;
button.style.color = '';
}, 2000);
}).catch(() => {
button.textContent = 'Failed';
setTimeout(() => {
button.textContent = 'Copy';
}, 2000);
});
}
function setActiveNavLink() {
const path = window.location.pathname;
const links = document.querySelectorAll('.nav-links a');
links.forEach(link => {
link.classList.remove('active');
const href = link.getAttribute('href');
if (href === path || (href !== '/' && path.startsWith(href))) {
link.classList.add('active');
}
});
}
function initTabs() {
document.querySelectorAll('.tab').forEach(tab => {
tab.addEventListener('click', () => {
const tabGroup = tab.closest('.use-cases');
if (!tabGroup) return;
tabGroup.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
tabGroup.querySelectorAll('.tab-content').forEach(c => c.classList.remove('active'));
tab.classList.add('active');
const content = document.getElementById(tab.dataset.tab);
if (content) {
content.classList.add('active');
if (typeof hljs !== 'undefined') {
content.querySelectorAll('pre code').forEach(block => {
hljs.highlightElement(block);
});
}
}
});
});
}
document.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('.copy-btn').forEach(btn => {
btn.addEventListener('click', () => copyCode(btn));
});
setActiveNavLink();
initTabs();
if (typeof hljs !== 'undefined') {
hljs.highlightAll();
}
});
window.tsrunCopyCode = copyCode;
})();