[Feature request] Add the option to play video with mpv for the YouTube homepage
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.
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.
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).
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, "-"))
}
});
Done. hold Alt key and click on any link to play the link directly.
Thanks for your example.
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.
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.
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