-1

I trying do a bookmark javascript

javascript:(function()  ..... etc.

that do this:

  • i click to script in bookmark
  • script grab A SITE what I am in actually and open B SITE in where fill VALUE with url of A SITE
  • and if is possible send it with button

Example:

Thank you very much for all help. Maybe is easy, but i am lost.

kofola
  • 11
  • if browsers would have allowed that don't you think all websites could steal your data? The sensible choice would be to have a common backend to process just like how re tagging services work. Your server can set domain1 and domain2 common cookies – joyBlanks Oct 12 '19 at 21:41
  • you will have to create a browser extension – Dhananjai Pai Oct 12 '19 at 21:46
  • @joyBlanks No need for cookies. On most websites, a query string would work, but not on this one - but, you *can* use `document.referrer` – CertainPerformance Oct 12 '19 at 21:47

1 Answers1

0

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.

CertainPerformance
  • 356,069
  • 52
  • 309
  • 320
  • Uh well... Maybe one click be best option. But i try.Can you tell me completly code? – kofola Oct 13 '19 at 00:19
  • That *is* the complete code. The first bookmarklet needs to assign to `window.location.href`, the second bookmarket needs to populate the `#url` with the referrer, and then click the button. – CertainPerformance Oct 13 '19 at 00:22