userscript icon indicating copy to clipboard operation
userscript copied to clipboard

[Feature request] Add the option to play video with mpv for the YouTube homepage

Open skygate2012 opened this issue 2 years ago • 7 comments

Basically adding an event listener to the homepage and transform the YouTube watch url to mpv url protocol, or convert all thumbnail hrefs to mpv://, so that when a video is clicked it is played with mpv. This is what I was thinking when I come up with the idea to use url protocol for mpv. So I found this project, but not this feature. In addition, perhaps, add a modifier hotkey like Ctrl to activate it, so that the user can go to the video page normally.

skygate2012 avatar Feb 10 '23 01:02 skygate2012

Basically adding an event listener to the homepage and transform the YouTube watch url to mpv url protocol, or convert all thumbnail hrefs to mpv://, so that when a video is clicked it is played with mpv.

It's a good idea, but it's hard to implement. Because we need to adapt different websites, this is a lot of work and may require frequent updates.

In addition, perhaps, add a modifier hotkey like Ctrl to activate it, so that the user can go to the video page normally.

This method sounds better than the previous one. But most browsers already occupy the modifier keys "Ctrl", "Alt" and "Shift", we should find another modifier key.

akiirui avatar Feb 10 '23 09:02 akiirui

Unfortunately, clicking the link on YouTube will still redirect you to the original destination, even after changing the href.

So, if we want to implement this feature, it will break the original functionality (remove all click event listener).

akiirui avatar Feb 10 '23 10:02 akiirui

We can prevent the default action, for example:

document.querySelector('#contents').addEventListener("click", (event) => {
	if (event.ctrlKey) {
		event.preventDefault();
		window.open('mpv://play/'+btoa(event.target.closest('a').href).replace(/\//g, "_").replace(/\+/g, "-"))
	}
});

skygate2012 avatar Feb 10 '23 13:02 skygate2012

Done. hold Alt key and click on any link to play the link directly.

Thanks for your example.

akiirui avatar Feb 10 '23 16:02 akiirui

Well, it looks like the modifier key Alt doesn't work properly on Microsoft Edge. But I think Ctrl or Shift are useful (for most browsers, to open in a new tab or a new window)

I will revert these changes, until we find a modifier key that does not interfere with other functions working properly.

akiirui avatar Feb 11 '23 08:02 akiirui

Well, I think playing with mpv is already equivalent to open in new tab/window. We can make this optional, so the user can choose whether to replace open in new tab with mpv, and/or make the modifier hotkey customizable, so that the user can set it to whatever they want, even like Ctrl+Shift.

skygate2012 avatar Feb 11 '23 09:02 skygate2012

These key combinations are usually used, even Ctrl+Shift (for Chrome, this is "Open a link, and jump to it").

Ref: https://support.google.com/chrome/answer/157179#zippy=%2Cmouse-shortcuts

akiirui avatar Feb 11 '23 11:02 akiirui