ruby rework with contact form
This commit is contained in:
parent
90402ae14a
commit
1ab09043ee
26 changed files with 932 additions and 221 deletions
41
public/copyPGP.js
Normal file
41
public/copyPGP.js
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
// Get the <pre> element
|
||||
const PGP = document.getElementById("myPGP");
|
||||
|
||||
//Create a copy button element
|
||||
const copyButton = document.createElement("span");
|
||||
copyButton.innerText = "Copy";
|
||||
copyButton.classList.add("copy-button");
|
||||
|
||||
// Append the copy button to the <pre> tag
|
||||
PGP.appendChild(copyButton);
|
||||
|
||||
// Add click event listener to the copy button
|
||||
copyButton.addEventListener("click", () => {
|
||||
// Hide the copy button temporarily
|
||||
copyButton.style.display = "none";
|
||||
|
||||
// Create a range and select the text inside the <pre> tag
|
||||
const range = document.createRange();
|
||||
range.selectNode(PGP);
|
||||
window.getSelection().removeAllRanges();
|
||||
window.getSelection().addRange(range);
|
||||
|
||||
try {
|
||||
// Copy the selected text to the clipboard
|
||||
document.execCommand("copy");
|
||||
|
||||
// Alert the user that the text has been copied
|
||||
copyButton.innerText = "Copied!";
|
||||
setTimeout(function(){
|
||||
copyButton.innerText = "Copy";
|
||||
}, 2000);
|
||||
} catch (err) {
|
||||
console.error("Unable to copy text:", err);
|
||||
} finally {
|
||||
// Show the copy button again
|
||||
copyButton.style.display = "inline";
|
||||
|
||||
// Deselect the text
|
||||
window.getSelection().removeAllRanges();
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue