Skip to content

Instantly share code, notes, and snippets.

@iamandrewluca
Last active April 3, 2023 16:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save iamandrewluca/22a9062c5ba3989342718249eb45f408 to your computer and use it in GitHub Desktop.
Save iamandrewluca/22a9062c5ba3989342718249eb45f408 to your computer and use it in GitHub Desktop.
Open any URL with origin as localhost:3000 #bookmarklet
javascript: void((function () {
/* More bookmarklets at https://gist.github.com/iamandrewluca/61feacf07bc4f2f50e70f986c2e9b2d2 */
/**
* Add your own mappers, first found will be used
* @type {{host: string, startsWith: string}[]}
*/
const hostMapper = [
{ startsWith: 'https://example.org', host: 'localhost:3000' },
{ startsWith: 'https://example.org/admin', host: 'localhost:3001' },
];
/** @type {string} */
const href = window.location.href;
const mapper = hostMapper.find(m => href.startsWith(m.startsWith));
const a = document.createElement('a');
a.href = href;
a.protocol = 'http:';
a.target = '_blank';
a.host = mapper ? mapper.host : 'localhost:3000';
window.document.body.appendChild(a);
a.click();
a.remove();
})());
@Doob123123
Copy link

What does this do?

@iamandrewluca
Copy link
Author

iamandrewluca commented May 24, 2022

@Doob123123 let's say you have a production website at https://my-website.com. And you also have locally started the development server on http://localhost:3000

if you go on https://my-website.com/some-url-here page and click the bookmarklet, will open http://localhost:3000/some-url-here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment