Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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