Skip to content

Instantly share code, notes, and snippets.

@jareha
Last active September 19, 2022 03:18
Show Gist options
  • Save jareha/f61e02ee4d3c039476c37a5ea124aff0 to your computer and use it in GitHub Desktop.
Save jareha/f61e02ee4d3c039476c37a5ea124aff0 to your computer and use it in GitHub Desktop.
Bookmarklet to toggle between `localhost` and production
/* jshint esversion: 8 */
(function () {
const domain = "https://example.com";
const isLocalhost = window.location.href.indexOf("localhost") >= 0;
const localhost = "http://localhost:8080";
const pathname = window.location.pathname;
const url = isLocalhost ? (domain + pathname) : (localhost + pathname);
window.location = url;
})();
// javascript:(function(){const domain="https://example.com";const isLocalhost=window.location.href.indexOf("localhost")>=0;const localhost="http://localhost:8080";const pathname=window.location.pathname;const url=isLocalhost?(domain+pathname):(localhost+pathname);window.location=url})();
// Minified at https://duckduckgo.com/?q=javascript+minifier
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment