Skip to content

Instantly share code, notes, and snippets.

@erhaem
Created August 28, 2024 02:50
Show Gist options
  • Select an option

  • Save erhaem/9970053002534e3ceea1dec7a1328ae4 to your computer and use it in GitHub Desktop.

Select an option

Save erhaem/9970053002534e3ceea1dec7a1328ae4 to your computer and use it in GitHub Desktop.
Copy text to clipboard using Bookmarklet
javascript:void(function(){
  const copyListener = event => {
    document.removeEventListener("copy", copyListener, true);
    event.preventDefault();
    let clipboardData = event.clipboardData;
    clipboardData.clearData();
    clipboardData.setData("text/plain", "<<TEXT TO COPY>>");
  };
document.addEventListener("copy", copyListener, true);
document.execCommand("copy");
document.body.lastElementChild.setAttribute("hidden", "hidden");
document.preventDefault;
})()

Source

https://gist.github.com/stefanmaric/2abf96c740191cda3bc7a8b0fc905a7d?permalink_comment_id=3788587#gistcomment-3788587

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment