cyfung1031 / userscript-supports

This is for the userscripts created on GreasyFork.org.
https://cyfung1031.github.io/userscript-supports/
MIT License
48 stars 3 forks source link

Documentation for "youtube-video-resize-fix" #19

Closed D-Rekk closed 10 months ago

D-Rekk commented 10 months ago

Hi @cyfung1031 👋 I'm a contributor to a YouTube extension (ImprovedTube) and some months ago I developed a feature to swap the comments and videos sections. May-27-2023 12-49-11

I encountered an annoying bug that made the video appear smaller than the player itself for whatever reason so I did a pretty rudimental code (Observers and inline width)

I'm now using your neat script instead of my temporary solution and I have to admit it's working well. I'm asking if you could add documentation of the script or a brief explanation. As far as I understand this allows the YouTube player to trigger resizeEvent by reading the values of the changed CSS instead of the native one. Also, if you don't mind, let's connect on Discord 🥹 (I'm D_Rekk there)

cyfung1031 commented 10 months ago

@D-Rekk I don't use Discord sorry.

There are two methods provided by the ytd-watch-flexy's controller.

They will give the sizes (width & height as a array) for the player element in normal mode and theater mode.

The resize event will finally trigger the onWindowResized_ method in the controller which is the entry point for the player to resize.

What this script does

Why it is necessary

cyfung1031 commented 10 months ago

You better check the js implementation in youtube/js&css/web-accessible/functions.js of ImprovedYouTube.

For example, calculateNormalPlayerSize_ = calculateCurrentPlayerSize_ shall be incorrect. calculateCurrentPlayerSize_ shall be always [NaN, NaN] for non-fullscreen.

It uses ImprovedTube.elements.player.offsetWidth but I am not sure ImprovedTube.elements.player refers to which layer of the player.

Besides, your implemented resizing might not trigger the onWindowResized_.

D-Rekk commented 10 months ago

Why it is necessary

  • If you just change the size of the player, by CSS or whatever, the progress control bar will not be sized correctly.

This is one of the problems I was dealing with. The video itself would resize automatically with some CSS, but the controlBar would not increase (or shrink) its size accordingly.

Thank you again for the explanation.