Skip to content

Instantly share code, notes, and snippets.

@tikurahul
Created August 7, 2013 23:13
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 tikurahul/6179854 to your computer and use it in GitHub Desktop.
Save tikurahul/6179854 to your computer and use it in GitHub Desktop.
A technique to supercharge Chome's "Manage Search Engines" feature. Map this JavaScript URL to a Search Engine (e.g super), and then you can do something like: super [TAB] "code packageName branchName" which will get mapped to "https://code.amazon.com/packages/packageName/trees/branchName/"
javascript:
var patterns = {
'vs': 'https://devcentral.amazon.com/ac/brazil/directory/version-set/packages/{0}/{1}',
'code': 'https://code.amazon.com/packages/{0}/trees/{1}/'
};
var pattern = decodeURIComponent('%s');
var keys = pattern.split(' ');
var base = keys ? keys[0] : '';
var args = keys ? keys.slice(1) : [];
var url = patterns[base] || '';
if (url) {
url = url.replace(/\{(\d+)\}/g, function(match, param) {
return (typeof args[param] != 'undefined' ? args[param] : match);
});
location.assign(url);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment