Javascript question
konstruct @konstruct@woof.tech
Content warning: Javascript question
I need help with my yt-dlp/mpv redirection userscript. (I am a JS beginner)
The userscript should take the current URL (location.href), replaces https:// with ytdl://, and closes the tab. I made it load only on URLs that contain videos which I want to open in mpv, such as https://www.youtube.com/watch?v=fBXY_AyA0bo.
My problem is that ytdl:// URIs are instantly handed off to mpv, and do not show up in the URL bar. I need a way to detect that handoff, and this prevents me from simply running :
```
if (/^ytdl/.test(window.location.href))
window.close;
```
Closing regardless of handoff success creates a bug : It closes the tab when the browser pops a dialog asking "allow this site open this link in mpv?", not giving the user time to click or read anything.
Currently, I am forced to comment out the window.close line for every new site I want to "always allow", then re-enable it.
Is there an event signal, or visibility change, anything my userscript can detect? Either detect the successful handoff, or detect the browser 'allow this site" dialog. The former would be "yes you can close.window" and the latter "no you can't close.window". Either would work for me.
#Javascript #Userscript #DuckDuckFedi #WebDev #TechSupport #AskFedi