This is a KIND 5391 event created on 2023-11-03 04:31:38 (1 year ago). Debug this event chain.
{ "id": "4ecf8b743788fc9cee70a8a17e26dbe6b41ce6b4dfb7f37f64439d07b0fb368e", "pubkey": "e8ed3798c6ffebffa08501ac39e271662bfd160f688f94c45d692d8767dd345a", "created_at": 1698985898, "kind": "5391", "tags": [ [ "e", "7c90faab92915b934eaeac038f4d0d188fbe66569268d3acfe47add69bc9c638", "wss://dashglow-test.nostr1.com", "root" ], [ "m", "text/javascript" ], [ "alt", "This is a binary chunk of a web-based video game. Play the full game at https://crashglow.com/game/nevent1qqs8ey864wffzkunf6h2cqu0f5x33ra7vetfy6xn4nly0twkn0yuvwqpremhxue69uhkgctndpnkcmmh946x2um59ehx7um5wgcjucm0d5q3vamnwvaz7tmjv4kxz7fwwpexjmtpdshxuet5qy28wumn8ghj7un9d3shjtnyv9kh2uewd9hszymhwden5te0wfjkcctev93xcefwdaexwqg5waehxw309aex2mrp0yhxummnw3ezumt9qyxhwumn8ghj7mn0wvhxcmmvqyt8wumn8ghj7un9d3shjtnwdaehgu3wvfskueqzyr5w6duccml7hlaqs5q6cw0zw9nzhlgkpa5gl9xyt45jmpm8m5695qcyqqqqqqgk7zq5g" ], [ "index", "5" ], [ "x", "7c8a57a48656f34ac9a8dd31ca419e155b5ed28df1bd279c74ccdb220579e243" ] ], "content": "ZTogZnVuY3Rpb24oKSB7DQogICBCcm93c2VyLm1haW5Mb29wLnNjaGVkdWxlciA9IG51bGw7DQogICBCcm93c2VyLm1haW5Mb29wLmN1cnJlbnRseVJ1bm5pbmdNYWlubG9vcCsrOw0KICB9LA0KICByZXN1bWU6IGZ1bmN0aW9uKCkgew0KICAgQnJvd3Nlci5tYWluTG9vcC5jdXJyZW50bHlSdW5uaW5nTWFpbmxvb3ArKzsNCiAgIHZhciB0aW1pbmdNb2RlID0gQnJvd3Nlci5tYWluTG9vcC50aW1pbmdNb2RlOw0KICAgdmFyIHRpbWluZ1ZhbHVlID0gQnJvd3Nlci5tYWluT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AibW91c2Vkb3duIikgew0KICAgIFNETC5ET01CdXR0b25zW2V2ZW50LmJ1dHRvbl0gPSAxOw0KICAgIFNETC5ldmVudHMucHVzaCh7DQogICAgIHR5cGU6ICJ0b3VjaHN0YXJ0IiwNCiAgICAgdG91Y2g6IHsNCiAgICAgIGlkZW50aWZpZXI6IDAsDQogICAgICBkZXZpY2VJRDogLTEsDQogICAgICBwYWdlWDogZXZlbnQucGFnZVgsDQogICAgICBwYWdlWTogZXZlbnQucGFnZVkNCiAgICAgfQ0KICAgIH0pOw0KICAgfSBlbHNlIGlmIChldmVudC50eXBlID09ICJtb3VzZXVwIikgew0KICAgIGlmICghU0RMLkRPTUJ1dHRvbnNbZXZlbnQuYnV0dG9uXSkgew0KICAgICByZXR1cm47DQogICAgfQ0KICAgIFNETC5ldmVudHMucHVzaCh7DQogICAgIHR5cGU6ICJ0b3VjaGVuZCIsDQogICAgIHRvdWNoOiB7DQogICAgICBpZGVudGlmaWVyOiAwLA0KICAgICAgZGV2aWNlSUQ6IC0xLA0KICAgICAgcGFnZVg6IGV2ZW50LnBhZ2VYLA0KICAgICAgcGFnZVk6IGV2ZW50LnBhZ2VZDQogICAgIH0NCiAgICB9KTsNCiAgICBTREwuRE9NQnV0dG9uc1tldmVudC5idXR0b25dID0gMDsNCiAgIH0NCiAgIGlmIChldmVudC50eXBlID09PSAia2V5ZG93biIgfHwgZXZlbnQudHlwZSA9PT0gIm1vdXNlZG93biIpIHsNCiAgICBTREwuY2FuUmVxdWVzdEZ1bGxzY3JlZW4gPSB0cnVlOw0KICAgfSBlbHNlIGlmIChldmVudC50eXBlID09PSAia2V5dXAiIHx8IGV2ZW50LnR5cGUgPT09ICJtb3VzZXVwIikgew0KICAgIGlmIChTREwuaXNSZXF1ZXN0aW5nRnVsbHNjcmVlbikgew0KICAgICBNb2R1bGVbInJlcXVlc3RGdWxsc2NyZWVuIl0oZmFsc2UsIHRydWUpOw0KICAgICBTREwuaXNSZXF1ZXN0aW5nRnVsbHNjc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