Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

functions.js click handler catch html5-video-container #2177

Merged
merged 2 commits into from
May 3, 2024
Merged

functions.js click handler catch html5-video-container #2177

merged 2 commits into from
May 3, 2024

Conversation

raszpl
Copy link
Contributor

@raszpl raszpl commented Apr 10, 2024

html5-video-container instead of html5-main-video. Fixes vertical video click handler

#2042

@ImprovedTube
Copy link
Member

Should be optional(? some users might be used to the current way)

@raszpl
Copy link
Contributor Author

raszpl commented Apr 11, 2024

Should be optional(? some users might be used to the current way)

used to how? :-) this is for setting invisible flag for disabling autoplay. Current code is bad as described #2042 (comment)

@raszpl
Copy link
Contributor Author

raszpl commented Apr 11, 2024

in fact its still too much code in the handler, this

if (ImprovedTube.elements.player && ImprovedTube.elements.player.classList.contains('ad-showing') === false) {

is redundant, we already check for ad-showing in
if (!this.user_interacted && video.classList.contains('ad-showing') === false &&

@ImprovedTube
Copy link
Member

ImprovedTube commented Apr 11, 2024

Currently clicking on the player or play will bypass autoplay-off, while clicking anywhere else wont.
Since we have many users, we cant change any daily behavior, without many people wondering.
Just saying.

@raszpl
Copy link
Contributor Author

raszpl commented Apr 11, 2024

Currently clicking on the player or play will bypass autoplay

"current way" is broken autoplayDisable with extension still autoplaying videos despite autoplayDisable being set to On.

&& (path[i].className.indexOf('html5-main-video') !== -1
|| path[i].className.indexOf('ytp-play-button') !== -1)) {

is broken on vertical videos, have to click on the vertical strip with video, meanwhile YT player listens on whole Video element, and finally reading below its broken because things are being initialized too late making it possible for user to click before Extension loaded completely :(

All in all those two handlers (keyboard and mouse) are only used to disable autoplayDisable aka let user play video with with "Force Autoplay Off" option enabled. The only thing users should notice changing is autoplayDisable working correctly :)


YT sometimes actually tries to autoPlay video 2-3 times in a row when loading/refreshing page :o This is why every time autoplayDisable fails to properly pause video you can see couple console.log("autoplay:off - should we pause here again?").

Our mousedown

ImprovedTube.onmousedown = function (event) {
is somehow being loaded and run too late and doesnt catch user clicking Play immediately when page loads. This all stems from Extension being broken into multitude of .js files. It should really be all combined into one .js and one .css file in a build process.

Now Im scratching my head how

extension.inject([
'/js&css/web-accessible/core.js',
'/js&css/web-accessible/functions.js',
'/js&css/web-accessible/www.youtube.com/appearance.js',
'/js&css/web-accessible/www.youtube.com/themes.js',
'/js&css/web-accessible/www.youtube.com/player.js',

autoplayDisable from player.js can be working earlier than mousedown from functions.js hmmm, ah here we go:

autoplayDisable is initialized in

this.playerOnPlay();

and mousedown lower here
this.onmousedown();

wrong order, but even switching order doesnt work for me, listener is unable to catch any clicks while while page is loading
and thats because ImprovedTube.elements.player is not initialized yet by

} else if (id === 'movie_player') {
if (!this.elements.player) {
ImprovedTube.elements.player = node;

its timing problems all the way down :/

@ImprovedTube
Copy link
Member

YT sometimes actually tries to autoPlay video 2-3 times in a row when loading/refreshing page :o This is why every time autoplayDisable fails to properly pause video you can see couple console.log("autoplay:off - should we pause here again?").

Sounds like you found proof why to undo that! ❤️

It should really be all combined into one .js and one .css file in a build process.

Yes! if it helps.

(Nor sure single files help [this] open development,
since it can also be more engaging and more efficient to work with a long one)

broken on vertical videos, have to click on the vertical strip with video, meanwhile YT player listens on whole Video element.

So we can include the whole/same area.
So that will pause despite a click? ( "#2042 #1809").

( We could call the current autoplayDisabled and a this new one: autoplayDisabled, unless i happen to clicking around anywhere on the page already (which is simpler and will keep working even if the DOM / player changes in future)
)

@raszpl
Copy link
Contributor Author

raszpl commented Apr 20, 2024

&& (path[i].className.indexOf('html5-main-video') !== -1
|| path[i].className.indexOf('ytp-play-button') !== -1)) {

is broken on vertical videos

found it, should be html5-video-container instead of html5-main-video, modified the patch. Fixes vertical video click handler, example vertical video https://www.youtube.com/watch?v=brNOkLwYBXc

Sounds like you found proof why to undo that! ❤️

Were there any other cases of people having problem with clicking Play and extension overriding it? having to press Play several times to get video to play?

It should really be all combined into one .js and one .css file in a build process.

Yes! if it helps.

(Nor sure single files help [this] open development, since it can also be more engaging and more efficient to work with a long one)

in Build process - same source files as now in the github repo, but automagically combined into one by build script packaging extension for the release

broken on vertical videos, have to click on the vertical strip with video, meanwhile YT player listens on whole Video element.

So we can include the whole/same area. So that will pause despite a click? #1809

people in that thread describe specifically clicking Play Button and that should have been handled with current code.
Also I dont know if all those people had "autoplay:off" setting activated. It would be really handy to ask people to dump their [HTML] element attributes when reporting bugs, as that contains all the settings already and is somewhat easy for a user to grab. Ideally we would have dedicated button to get settings that is quicker and easier to find than "Export settings" menu, something to push settings into clipboard would be ideal, or something popping a window with all settings in text form to copy.

#1809 (comment):
"So basically: Any testing for this issue will need to cover each of the different "page loading conditions", since the DOM structure differs between them."

This might be right on the money. It can be a case of ImprovedTube.elements.player not being initialized properly in some situations. Maybe its better to use document.querySelector('.html5-video-container') directly in click handlers as a fallback? something like

document.querySelector('.html5-video-container')
		if ((ImprovedTube.elements.player || document.querySelector('.html5-video-container')) && ImprovedTube.elements.player.classList.contains('ad-showing') === false) {

@raszpl raszpl changed the title Update functions.js any user click, not just precise click on the pla… functions.js click handler catch html5-video-container Apr 20, 2024
@ImprovedTube ImprovedTube force-pushed the master branch 2 times, most recently from 62a36d2 to 40aedd4 Compare April 27, 2024 17:02
@ImprovedTube ImprovedTube merged commit 9266d8d into code-charity:master May 3, 2024
@ImprovedTube
Copy link
Member

thanks @raszpl

fallback

please. guess we cant have enough fallbacks when selecting the video.

Were there any other cases of people having problem with clicking Play and extension overriding it? having to press Play several times to get video to play?

maybe not, just #1809

in Build process

(yes, i just also enjoy big files. Not sure who else.)

@raszpl raszpl deleted the patch-1 branch May 4, 2024 15:27
ImprovedTube added a commit that referenced this pull request May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants