Skip to content
This repository has been archived by the owner on Jul 19, 2024. It is now read-only.

Commit

Permalink
index.html updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdelrahmanthecoder authored Nov 11, 2023
1 parent 4159cbe commit 0756dcd
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@
color: #ffffff;
text-align: center;
}

.copy-icon {
display: inline-block;
vertical-align: middle;
cursor: pointer;
margin-left: 5px;
}
</style>
</head>
<body>
Expand All @@ -69,6 +76,8 @@
<div class="message" id="welcomeMessage">Type "joke" to obviously hear a joke</div>
<div class="message" id="welcomeMessage">Type "fact" to get back a random interesting fun fact</div>
<div id="separator" style="height: 2px; background-color: #636363; margin: 10px 0;"></div>
<div class="message" id="welcomeMessage">Donate ETH/MATIC to crypto address: 0x77f474B3E568329EBb2eDcBD90aC7a94385fB8F2</div>
<div id="separator" style="height: 2px; background-color: #636363; margin: 10px 0;"></div>
</div>
<input type="text" id="userInput" placeholder="Enter a prompt...">
<button onclick="sendMessage()">Send</button>
Expand Down Expand Up @@ -493,6 +502,56 @@
// Process the user's command
processCommand(userInput);
}

// Function to copy text to the clipboard
function copyTextToClipboard(text) {
const textArea = document.createElement('textarea');
textArea.value = text;
document.body.appendChild(textArea);
textArea.select();
document.execCommand('copy');
document.body.removeChild(textArea);
}

// Modify the typeMessage function to include a copy icon
async function typeMessage(sender, message) {
const chatbox = document.getElementById("chatbox");
const messageDiv = document.createElement("div");
messageDiv.classList.add("message");
messageDiv.innerHTML = `<strong>${sender}:</strong> `;
chatbox.appendChild(messageDiv);

const messageSpan = document.createElement("span");
messageDiv.appendChild(messageSpan);

let i = 0;
const typingEffect = setInterval(() => {
if (i < message.length) {
messageSpan.textContent += message.charAt(i);
i++;
} else {
clearInterval(typingEffect);

// Add a copy icon to the message
const copyIcon = document.createElement("span");
copyIcon.classList.add("copy-icon");
copyIcon.textContent = "📋";
copyIcon.title = "Copy to clipboard";
copyIcon.onclick = function () {
copyTextToClipboard(message);
};
messageDiv.appendChild(copyIcon);
}
}, 20);

}

// Add an event listener for the Enter key to trigger sendMessage
document.getElementById("userInput").addEventListener("keyup", function(event) {
if (event.key === "Enter") {
sendMessage();
}
});
</script>
</body>
</html>

0 comments on commit 0756dcd

Please sign in to comment.