I need help with my yt-dlp/mpv redirection userscript. (I am a JS beginner)
The userscript should take the current URL (location.href), replace https:// with ytdl://, and close the tab. I made it load only on URLs matching specific regex, 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.
edit : detecting a first-time execution on specific sites would work too, just need to automate disabling window.close on these specific cases.
#Javascript #Userscript #DuckDuckFedi #WebDev #TechSupport #AskFedi



