I want to make a bookmarklet to a site where you can watch videos with any subtitle .srt file. The intent is that I can directly click it from a YouTube (or DailyMotion, or ...) video page, and instantly be transported to https://tubecc.herokuapp.com/, with the desired video url already filled in.
My current attempt is:
javascript:{vidurl=document.location.href;document.location.href=('https://tubecc.herokuapp.com');document.getElementById("url").value=vidurl;void(0);}
However, all this does is navigate to the website - it does not fill in the url in the box.
When I try to fill in the url box with some nonsense text as a separate operation - i.e. I'm already on https://tubecc.herokuapp.com/ and just run document.getElementById("url").value="foobar"
from the console, or make a separate bookmarklet which only includes javascript:{document.getElementById("url").value="foobar";void(0);}
, it does work - 'foobar' appears in the text box, as expected.
It only seems to fail when combined with a larger bookmarklet which navigates to the page first. At one point I suspected it had something to do with asynchronicity so I added a delay for the fill in (javascript:{vidurl=document.location.href;document.location.href('https://tubecc.herokuapp.com');setTimeout(() => { document.getElementById("url").value="foobar"; }, 2000);void(0);}
), but that didn't seem to help either.
PS: not a duplicate of this question - the basic principle is described there, and I am applying it. My question is about why it goes wrong in this specific situation.