3 ms·
how can a person actually run this? If I paste it into my JS console, I just see Uncaught EvalError: Refused to evaluate a string as JavaScript because 'unsaf
by knodi123 6y ago
how can a person actually run this? If I paste it into my JS console, I just see Uncaught EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'self' 'unsafe-inline' https://www.google.com/recaptcha/ https://www.google.com/recaptcha/ https://www.gstatic.com/recaptcha/ https://www.gstatic.com/recaptcha/ https://cdnjs.cloudflare.com/ https://cdnjs.cloudflare.com/".
- tomxor 6y agoDwitter sets up a minimal shim with a canvas `c` and 2d context `x`, and some shortcuts to math functions sin `S`, cos `C`, tan `T`, and then runs a 60 FPS loop with time `t`. The code is run in this loop with those variables in non-strict mode to allow various hacky things e.g `with()` that are invaluable for code golfing. The eval escape unescape trick extracts two chars in the ASCII space from each UTF16 character. Here's the encoder: https://www.dwitter.net/d/11852 https://www.dwitter.net/d/11852 You can see the content by removing the eval and just outputting the string... alternatively replace 'eval' with 'throw' on dwitter and it will print the source bellow the dweet.
- gregsadetsky 6y agoWhat @tomxor said! To try it out, go to https://example.com https://example.com and run the following setup code first: c = document.createElement('canvas'); document.body.appendChild(c); x = c.getContext('2d'); S = Math.sin; T = Math.tan; C = Math.cos; t = 0; You will then be able to paste the tweet code `eval(unescape(...` into the console and see one frame rendered. :-)
- girvo 6y agoYou can also go to data:text/html,<body> instead of example.com (if I got the syntax right for the data URI, I’m on mobile)
- gregsadetsky 6y agoJust tried, that works too! Thanks
- girvo 6y agoYou can do all sorts of next hacks with the data URI syntax :)