atr/static/js/atr.js (33 lines of code) (raw):
function init() {
document.addEventListener("DOMContentLoaded", function () {
const copyButtons = document.querySelectorAll(".atr-copy-btn");
copyButtons.forEach(button => {
button.addEventListener("click", function () {
const targetId = this.getAttribute("data-clipboard-target");
const targetElement = document.querySelector(targetId);
if (targetElement) {
const textToCopy = targetElement.textContent;
navigator.clipboard.writeText(textToCopy)
.then(() => {
const originalText = this.innerHTML;
this.innerHTML = '<i class="fas fa-check"></i> Copied!';
// Reset the button text after 2000ms
setTimeout(() => {
this.innerHTML = originalText;
}, 2000);
})
.catch(err => {
console.error("Failed to copy: ", err);
this.innerHTML = '<i class="fas fa-exclamation-triangle"></i> Failed!';
setTimeout(() => {
this.innerHTML = '<i class="fas fa-clipboard"></i> Copy';
}, 2000);
});
}
});
});
});
}
function updateDeleteButton(inputElement, buttonId) {
let button = document.getElementById(buttonId);
button.disabled = inputElement.value !== "DELETE";
}