Created
February 3, 2013 14:10
-
-
Save janmoesen/4701941 to your computer and use it in GitHub Desktop.
New way to "parametrise" my bookmarklets now that E4X is dead everywhere.
This file contains hidden or 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
/** | |
* Search Google Maps for a bicycle route. | |
* | |
* @title Google Maps (for cyclists) | |
*/ | |
(function ride() { | |
/* Try to get the parameter string from the bookmarklet/search query. */ | |
/* Fall back to the current text selection, if any. If those options | |
/* both fail, prompt the user. */ | |
var s = (function () { /*%s*/ }).toString() | |
.replace(/^function\s*\(\s*\)\s*\{\s*\/\*/, '') | |
.replace(/\*\/\s*\;?\s*\}\s*$/, '') | |
.replace(/\u0025s/, ''); | |
if (s === '') { | |
s = getSelection() + '' || prompt('Please enter your URL:', location); | |
} | |
if (s) { | |
if (s.match(/\sto[\s:]/) && !s.match(/^\s*from[\s:]/)) { | |
s = 'from:' + s; | |
} | |
s = s.replace(/^\s*from\s+/g, 'from:'); | |
s = s.replace(/\s+to\s+/g, ' to:'); | |
location = 'https://maps.google.com/?dirflg=b&q=' + encodeURIComponent(s); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment