Re:Show HN: A Stargate in 140 chars of JavaScript
by knodi123 on Friday November 13, 2020 @08:00PM
(#25089342)
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.gstatic.com/recaptcha/ https://cdnjs.cloudflare.com/".
[ Parent
| on HN ]
Re:Show HN: A Stargate in 140 chars of JavaScript
by tomxor on Friday November 13, 2020 @08:10PM
(#25089394)
Dwitter 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 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.
Re:Show HN: A Stargate in 140 chars of JavaScript
by gregsadetsky on Friday November 13, 2020 @08:18PM
(#25089434)
What @tomxor said! To try it out, go to 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. :-)
Re:Show HN: A Stargate in 140 chars of JavaScript
by girvo on Friday November 13, 2020 @11:32PM
(#25090314)
You 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)
Re:Show HN: A Stargate in 140 chars of JavaScript
by gregsadetsky on Saturday November 14, 2020 @05:57PM
(#25096467)
Just tried, that works too! Thanks