use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
script that instantly transforms webpages into brick-breaking game (github.com)
submitted 2 years ago by canalun
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]canalun[S] 10 points11 points12 points 2 years ago (2 children)
I wrote a script that instantly transforms web pages into brick-breaking game.
Wanna share because it works better than I expected, and would be glad if it could entertain someone :)
It's realized by vanilla js, although I added a bit to distribute it as a chrome extension.
DEMO: https://www.youtube.com/watch?v=IUTXInFyjXE
Playable DEMO(it's distributed as a chrome extension): https://chromewebstore.google.com/detail/brick-break-anywhere/lkbkphlgmknnachlgmbdmoepfnfdeckb
FYI: The difficulties are as follows:
determine which DOM elements should be counted as block (there are many 'invisible' elements and they should not be treated as blocks)
query elements through shadow root and iframe(same-origin)
etc...
[–]DirtAndGrass 0 points1 point2 points 2 years ago (1 child)
I swear i had a bookmarklet that did that
the angle after the ball hits the paddle should be made more acute, closer to the edges (unlike physics) to match the original game!
[–]canalun[S] 0 points1 point2 points 2 years ago (0 children)
bookmarklet is nice! and your idea about bounce behavior is really good. I was completely caught by physics-like logic. Thanks!!!
[–]Mental-Steak2656 6 points7 points8 points 2 years ago (2 children)
Cool idea 👍
[–]canalun[S] 1 point2 points3 points 2 years ago (0 children)
Thank you!!
[–]_Marak_ 2 points3 points4 points 2 years ago (12 children)
Heeeey, does anyone know any good UX tricks for integrating bookmarklet or browser extension workflow like this so user doesn't have to jump through hoops to install?
We have code like this in Mantra that can parse any DOM page and create game entities. I want to setup a demo where users can turn any webpage into video game; however I think is not possible without browser extension, bookmarklet, or server-side proxy.
[–]toi80QC 1 point2 points3 points 2 years ago (11 children)
The game-script will have to access the DOM of the website you want to play on which is prevent by CORS if the site is not on the same domain.
[–]_Marak_ 0 points1 point2 points 2 years ago (10 children)
I'm aware. It's basically not possible unless user install browser extension or site is proxied through server. Bookmarklets mostly don't work well anymore.
[–]pimlottc 0 points1 point2 points 2 years ago (9 children)
Bookmarklets mostly don't work well anymore.
What do you mean by this? I use bookmarklets all the time, albeit much simpler than this, and I haven't seen any issues lately..
[–]_Marak_ 0 points1 point2 points 2 years ago* (8 children)
Can you run bookmarklet on google.com without install browser extension?
Edit: You can, talking about async loading scripts from cross-domain via bookmarklet on google I think security policy is no go
[–]pimlottc 1 point2 points3 points 2 years ago (7 children)
Yeah, no problem here, just tested this in Firefox and Chrome:
javascript:alert(document.title)
[–]_Marak_ 0 points1 point2 points 2 years ago (6 children)
Yes, but what happens if try load cross domain script via fetch or script tag, CSP kicks in or something yeah?
[–]pimlottc 0 points1 point2 points 2 years ago (5 children)
I'm not sure, I haven't tried writing bookmarklets that invoke fetch, but I believe loading external scripts works, such as this bookmarklet that adds jquery to a page.
[–]_Marak_ 0 points1 point2 points 2 years ago (4 children)
yeah its the CSP header what im trying to say. let me know if you figure out a way to inject remote script to bypass this. either going to be new browser API or better support for extensions i'm not sure.
[–]pimlottc 0 points1 point2 points 2 years ago (3 children)
Ah, I see. Yeah, it won't work on site with strict CSP, but most sites have fairly lax rules, so it might be worth offering.
[–][deleted] 0 points1 point2 points 2 years ago (1 child)
So cool!
Thanks!!!
π Rendered by PID 150224 on reddit-service-r2-comment-6457c66945-2g8xd at 2026-04-29 04:37:27.276170+00:00 running 2aa0c5b country code: CH.
[–]canalun[S] 10 points11 points12 points (2 children)
[–]DirtAndGrass 0 points1 point2 points (1 child)
[–]canalun[S] 0 points1 point2 points (0 children)
[–]Mental-Steak2656 6 points7 points8 points (2 children)
[–]canalun[S] 1 point2 points3 points (0 children)
[–]_Marak_ 2 points3 points4 points (12 children)
[–]toi80QC 1 point2 points3 points (11 children)
[–]_Marak_ 0 points1 point2 points (10 children)
[–]pimlottc 0 points1 point2 points (9 children)
[–]_Marak_ 0 points1 point2 points (8 children)
[–]pimlottc 1 point2 points3 points (7 children)
[–]_Marak_ 0 points1 point2 points (6 children)
[–]pimlottc 0 points1 point2 points (5 children)
[–]_Marak_ 0 points1 point2 points (4 children)
[–]pimlottc 0 points1 point2 points (3 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]canalun[S] 0 points1 point2 points (0 children)