Last active
April 3, 2023 16:21
-
-
Save iamandrewluca/22a9062c5ba3989342718249eb45f408 to your computer and use it in GitHub Desktop.
Open any URL with origin as localhost:3000 #bookmarklet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 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
What does this do?