mkasberg / script-seed

🌱 Seed scripts for popular (& unpopular) scripting languages.
https://mkasberg.github.io/script-seed/
MIT License
11 stars 23 forks source link

Replace document.execCommand("copy") with clipboard API #85

Closed mkasberg closed 2 years ago

mkasberg commented 2 years ago

We're currently copying text to the clipboard like this:

https://github.com/mkasberg/script-seed/blob/f8fc60cfa72a9b666fbbcc80cc96c500a9bcb0c1/main.js#L111-L130

However, the execCommand API is deprecated.

We should replace it with Clipboard.writeText.

I'm not 100% sure, but this might be difficult to test locally if the clipboard API requires HTTPS...

Also, note that we might be able to remove some code that selects the text before executing copy since with the new API we can just get the inner text and write it directly to the clipboard.

AloyBranCheung commented 2 years ago

Hey @mkasberg , I just wanted to clarify for this issue, is the goal to change the document.exeCommand("copy") in copyToClipboard() so that the user can copy to clipboard the seed script using Clipboard.writeText instead?

mkasberg commented 2 years ago

Yes, and it is likely that most of the copyToClipboard() function will need to be re-written (and might be significantly shorter since we might not need to highlight the text anymore to perform the copy). We want to copy the inner text of document.getElementById("seedScript").

AloyBranCheung commented 2 years ago

I'd like to give it a shot if that's alright.

mkasberg commented 2 years ago

Sure, that would be great!

AloyBranCheung commented 2 years ago

Thanks! Do you mind assigning me this?