Last active
June 27, 2025 01:45
-
-
Save cr0wg4n/d4895e885694ace50c34910631c2cba1 to your computer and use it in GitHub Desktop.
EyeDropper API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Eyedropper Tool</title> | |
<style> | |
body { | |
font-family: Arial, sans-serif; | |
padding: 20px; | |
} | |
#colorBox { | |
width: 100px; | |
height: 100px; | |
border: 1px solid #ccc; | |
margin-top: 20px; | |
background-color: white; | |
} | |
</style> | |
</head> | |
<body> | |
<h2>Pick a Color from the Screen</h2> | |
<button id="pickColorBtn">🎨 Pick Color</button> | |
<div id="colorBox"></div> | |
<p>Hex Code: <span id="colorValue">None</span></p> | |
<script> | |
const pickColorBtn = document.getElementById('pickColorBtn'); | |
const colorBox = document.getElementById('colorBox'); | |
const colorValue = document.getElementById('colorValue'); | |
pickColorBtn.addEventListener('click', async () => { | |
if (!window.EyeDropper) { | |
alert('EyeDropper API is not supported in this browser.'); | |
return; | |
} | |
try { | |
const eyeDropper = new EyeDropper(); | |
const result = await eyeDropper.open(); | |
colorBox.style.backgroundColor = result.sRGBHex; | |
colorValue.textContent = result.sRGBHex; | |
} catch (err) { | |
console.error(err); | |
} | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment