Skip to content

Instantly share code, notes, and snippets.

@idvorkin
Last active December 25, 2015 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save idvorkin/9c5a4032f713b1c2ccd2 to your computer and use it in GitHub Desktop.
Save idvorkin/9c5a4032f713b1c2ccd2 to your computer and use it in GitHub Desktop.
swap between github pages and local pretzel blog
function swapLocalRemoteBlog() {
/*
* Pretzel renders, but doesn't navigate the same as github pages (GHP).
* Thus use GHP to navigate, then use this bookmarklet to swap with local pretzel blog.
*/
var currentUrl = document.URL;
var errorMessage = "Only works on Igor's Blog";
var githubBlogURL = "http://idvorkin.github.io";
var localPretzelBlogUrl = "http://localhost:8080";
var newUrl = "";
if (currentUrl.startsWith(githubBlogURL)) {
newUrl = currentUrl.replace(githubBlogURL,localPretzelBlogUrl);
/*pretzel can't have a trailing slash - Issue 289, so remove it*/
newUrl = newUrl.substr(0, newUrl.length-1)
} else if (currentUrl.startsWith(localPretzelBlogUrl)) {
newUrl = currentUrl.replace(localPretzelBlogUrl,githubBlogURL);
} else {
alert(errorMessage);
return;
}
window.location = newUrl;
};
swapLocalRemoteBlog();
void(0);
@idvorkin
Copy link
Author

To convert to a bookmarklet - Join all lines into a single line and prepend the line with javascript:

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