I'm not sure if this is possible with a single bookmarklet, because you need your Javascript to run in two separate environments.
Another issue is that https://vidconverter.co/ looks to use a 302 redirect when a query string is used - eg, you couldn't just set the location to 'https://vidconverter.co' + encodeURIComponent(window.location.href)
, because the forced redirect will remove the required data.
However, if you don't use an extension like Referrer Control to obfuscate your referrer, you can identify the origin site by checking document.referrer
on vidconverter.co
, after a redirect via window.location.href =
. So, to do this with two bookmarklets:
(1) When clicking the first bookmarklet, run:
window.location.href = 'https://vidconverter.co'
(2) Now that you've redirected, click the second bookmarklet to grab the query string appended by the first bookmarklet, and then fill in the field and convert:
document.querySelector('#url').value = document.referrer;
document.querySelector('#send2').click();
To run any code that isn't absolutely trivial, you might consider using a userscript manager like Tampermonkey instead - userscripts are far more versatile and manageable than bookmarklets, and can run automatically. Userscripts also allow you to save data across different origins with GM_setValue
/ GM.setValue
(which is more reliable and flexible than the referrer trick above).
Another way to transfer the data from one domain to another would be to use window.open
so that the first window has a reference to the second, and then the second window can listen for messages from the first, and then the first can use postMessage
to send its data to the second.