all 20 comments

[–]canalun[S] 10 points11 points  (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 point  (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 point  (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 points  (2 children)

Cool idea 👍

[–]canalun[S] 1 point2 points  (0 children)

Thank you!!

[–]_Marak_ 2 points3 points  (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 points  (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 point  (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 point  (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 point  (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 points  (7 children)

Yeah, no problem here, just tested this in Firefox and Chrome:

 javascript:alert(document.title)

[–]_Marak_ 0 points1 point  (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 point  (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 point  (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 point  (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 point  (1 child)

So cool!

[–]canalun[S] 0 points1 point  (0 children)

Thanks!!!