Skip to content

Instantly share code, notes, and snippets.

@walpolea
Created April 5, 2024 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walpolea/e56804f7a7bcefffb384a1858fa15e02 to your computer and use it in GitHub Desktop.
Save walpolea/e56804f7a7bcefffb384a1858fa15e02 to your computer and use it in GitHub Desktop.
Color Picker Bookmarklet
const cp = document.querySelector('.colorpickerbookmarklet');
if(cp) {
cp.parentElement.removeChild(cp);
} else {
const cpc = document.createElement('div');
cpc.innerHTML = `<input class="colorpickerbookmarklet" type="color" style="z-index:999999;position:fixed;right:2px;bottom:2px;">`;
cpc.firstChild.addEventListener("change", watchColorPicker, false);
function watchColorPicker(event) {
const el = document.createElement('textarea');
el.value = event.target.value;
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
}
document.body.appendChild(cpc.firstChild);
}
/***
javascript:(function()%7Bconst%20cp%20%3D%20document.querySelector('.colorpickerbookmarklet')%3B%0Aif(cp)%20%7B%0A%20cp.parentElement.removeChild(cp)%3B%0A%7D%20else%20%7B%0Aconst%20cpc%20%3D%20document.createElement('div')%3B%0Acpc.innerHTML%20%3D%20%60%3Cinput%20class%3D%22colorpickerbookmarklet%22%20type%3D%22color%22%20style%3D%22z-index%3A999999%3Bposition%3Afixed%3Bright%3A2px%3Bbottom%3A2px%3B%22%3E%60%3B%0Acpc.firstChild.addEventListener(%22change%22%2C%20watchColorPicker%2C%20false)%3B%0Afunction%20watchColorPicker(event)%20%7B%0A%20%20const%20el%20%3D%20document.createElement('textarea')%3B%0A%20%20el.value%20%3D%20event.target.value%3B%0A%20%20document.body.appendChild(el)%3B%0A%20%20el.select()%3B%0A%20%20document.execCommand('copy')%3B%0A%20%20document.body.removeChild(el)%3B%0A%7D%0Adocument.body.appendChild(cpc.firstChild)%3B%0A%7D%7D)()%3B
***/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment