Untitled

 avatar
unknown
plain_text
20 days ago
847 B
3
Indexable
// Retrieve the value from localStorage
const usernameColor = localStorage.getItem('chatUsernameColor');

// Check if the key exists and has a value
if (usernameColor !== null) {
  // Display the value using an alert
  alert(`Username Color: ${usernameColor}`);
  
  // Copy the color value to the clipboard
  navigator.clipboard.writeText(usernameColor)
    .then(() => {
      console.log('Color copied to clipboard!');
      // Optionally, you can inform the user that it's copied
      alert('The color value has been copied to your clipboard.');
    })
    .catch(err => {
      console.error('Failed to copy to clipboard:', err);
      alert('Could not copy the color to clipboard.');
    });
} else {
  // Key is not found; inform the user or handle accordingly
  alert('No username color found in localStorage.');
}
Editor is loading...
Leave a Comment