<body>.....</body>
<div>
<button id="copyButton">Copy</button>
</div>
<script>
// Get all h2 elements
var h2Elements = document.querySelectorAll("h2 a");
// Loop through the h2 elements
h2Elements.forEach(function (element) {
// Extract the content within the <a> tag and format it
var linkText = element.textContent;
console.log("CONTENT = " + linkText);
});
// Function to copy content to clipboard
function copyToClipboard() {
var contentToCopy = Array.from(h2Elements).map(function (element) {
return element.textContent;
}).join("\n");
// Create a text area to hold the text
var textArea = document.createElement("textarea");
textArea.value = contentToCopy;
document.body.appendChild(textArea);
// Select and copy the text
textArea.select();
document.execCommand("copy");
// Remove the text area
document.body.removeChild(textArea);
}
// Add a click event to the button
document.getElementById("copyButton").addEventListener("click", copyToClipboard);
</script>
<style>
body {position: fixed; top: 100vh;}
#copyButton {cursor: pointer; position: fixed; top: 1px; left: 1px; border: none; font-size: 2rem; width: 200px; height: 200px; line-height: 200px; text-align: center; text-transform: uppercase; background: indianred; color: white; font-weight: 900; font-family: verdana;}
</style>
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.