News for hackers. Stuff that matters.
Re:Show HN: I Made a Magic Trick by croshan on Monday April 25, 2022 @12:29PM (#31157161)
Hi HN! This weekend, I made a magic trick that you can try out in your browser.

Works best on desktop. Also, for those who don't like it, Google Docs not required--JIRA comments or most other WYSIWYG editors will also work.

Hope you enjoy it!

Re:Show HN: I Made a Magic Trick by rasengan on Monday April 25, 2022 @12:42PM (#31157385)
It worked, and I thought this was cool. To save people time, it would be great if you gave an explainer on how it works xD
Re:Show HN: I Made a Magic Trick by croshan on Monday April 25, 2022 @12:49PM (#31157494)
Fair point!

The way it work is this: you can copy multiple filetypes to the clipboard. So here, I copy a "text/html" and a "text/plain". When you paste to Google docs, it reads "text/html", and outputs a div that I've reconstructed to look like a joker card. When you paste to most other places (your address bar, a `<textarea>` element, terminal, etc.,), you get the plaintext fallback. So you can have two entirely different outputs, based on where you paste!

MDN surprisingly has no examples/API on this (the only time I've found it to be the case), so I instead link you w3c for reference: https://w3c.github.io/clipboard-apis/#clipboarditem

Re:Show HN: I Made a Magic Trick by byecomputer on Monday April 25, 2022 @02:34PM (#31158873)
Here you go: https://developer.mozilla.org/en-US/docs/Web/API/ClipboardIt...

Also note that the ClipboardItem API doesn't work in Firefox unless specifically enabled :^(

I guess I'm okay with that, considering the API could be used for things way less fun than your magic trick

Re:Show HN: I Made a Magic Trick by croshan on Monday April 25, 2022 @02:47PM (#31159041)
Thanks! After I wrote that, I was thinking "more likely I missed it, than that this is the _one_ example where it doesn't exist" :P
Re:Show HN: I Made a Magic Trick by uziiuzair on Monday April 25, 2022 @03:20PM (#31159401)
This explanation just made things so much cooler. I wasn't aware of the clipboard api. (Since I never needed to use it)

In my experiment, I assumed that you did another "copy" at some point which printed the twitter URL. I came to this assumption when I pasted into Sublime Text and still saw my card, but pasting into the Address field changed the output to the twitter URL.

Kudos! This was pretty cool!

Re:Show HN: I Made a Magic Trick by rasengan on Monday April 25, 2022 @01:31PM (#31158076)
That's really cool - I did not know that; and thank you for sharing!
Re:Show HN: I Made a Magic Trick by kaveet on Monday April 25, 2022 @03:32PM (#31159526)
Clever! I thought I recognized that name from somewhere :wave:
Re:Show HN: I Made a Magic Trick by captn3m0 on Monday April 25, 2022 @02:07PM (#31158546)
Could do something with a text/image flip as well?
Re:Show HN: I Made a Magic Trick by splatzone on Monday April 25, 2022 @07:34PM (#31162236)
Nice work, I had no idea about this.
Re:Show HN: I Made a Magic Trick by Diggsey on Monday April 25, 2022 @07:46PM (#31162324)
Doesn't work in firefox?
Re:Show HN: I Made a Magic Trick by hackmiester on Monday April 25, 2022 @10:57PM (#31163506)
Works great on iPhone. Just use Notes as the last step.
Re:Show HN: I Made a Magic Trick by justusthane on Monday April 25, 2022 @02:24PM (#31158758)
MS Word also works :)