fix secrets tab functionalitty

This commit is contained in:
2025-04-09 05:29:38 +03:00
parent 7af97e56a2
commit 882cd26caa
3 changed files with 74 additions and 36 deletions

View File

@@ -2,16 +2,53 @@
document.addEventListener('click', function(e) {
if (e.target && e.target.classList.contains('copy-btn')) {
const text = e.target.getAttribute('data-clipboard');
navigator.clipboard.writeText(text).then(function() {
const originalText = e.target.innerText;
e.target.innerText = "copied!";
setTimeout(() => {
e.target.innerText = originalText;
}, 1000);
});
// Check for clipboard API support
if (navigator.clipboard) {
navigator.clipboard.writeText(text)
.then(function() {
const originalText = e.target.innerText;
e.target.innerText = "copied!";
setTimeout(() => {
e.target.innerText = originalText;
}, 1000);
})
.catch(function(err) {
console.error('Failed to copy: ', err);
// Fallback method
fallbackCopyTextToClipboard(text, e.target);
});
} else {
// Fallback for browsers without clipboard API
fallbackCopyTextToClipboard(text, e.target);
}
}
});
// Fallback copy method for older browsers
function fallbackCopyTextToClipboard(text, button) {
const textArea = document.createElement("textarea");
textArea.value = text;
textArea.style.position = "fixed"; // Avoid scrolling to bottom
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
try {
const successful = document.execCommand('copy');
if (successful) {
const originalText = button.innerText;
button.innerText = "copied!";
setTimeout(() => {
button.innerText = originalText;
}, 1000);
}
} catch (err) {
console.error('Fallback: Unable to copy', err);
}
document.body.removeChild(textArea);
}
// Search functionality
function setupSearch(inputId, itemsSelector) {
const searchInput = document.getElementById(inputId);