add ability to go directly to a path
This commit is contained in:
+24
-5
@@ -219,6 +219,10 @@
|
|||||||
// e.g. to search GitHub for potatoes you'd type "g:potatoes".
|
// e.g. to search GitHub for potatoes you'd type "g:potatoes".
|
||||||
searchDelimiter: ':',
|
searchDelimiter: ':',
|
||||||
|
|
||||||
|
// the delimiter between the key and a path.
|
||||||
|
// e.g. type "r/r/unixporn" to go to "reddit.com/r/unixporn".
|
||||||
|
pathDelimiter: '/',
|
||||||
|
|
||||||
// set to true to instantly redirect when a key is matched.
|
// set to true to instantly redirect when a key is matched.
|
||||||
// you'll have to put a space before any search queries to
|
// you'll have to put a space before any search queries to
|
||||||
// prevent unwanted redirects.
|
// prevent unwanted redirects.
|
||||||
@@ -329,7 +333,8 @@
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var qSplit = q.split(config.searchDelimiter);
|
var qSplitSearch = q.split(config.searchDelimiter);
|
||||||
|
var qSplitPath = q.split(config.pathDelimiter);
|
||||||
var qIsUrl = q.match(config.urlRegex);
|
var qIsUrl = q.match(config.urlRegex);
|
||||||
var qHasProtocol = q.match(config.protocolRegex);
|
var qHasProtocol = q.match(config.protocolRegex);
|
||||||
var redirect = '';
|
var redirect = '';
|
||||||
@@ -337,18 +342,32 @@
|
|||||||
if (qIsUrl) redirect = qHasProtocol ? q : 'http://' + q;
|
if (qIsUrl) redirect = qHasProtocol ? q : 'http://' + q;
|
||||||
else redirect = config.defaultSearch + encodeURIComponent(q);
|
else redirect = config.defaultSearch + encodeURIComponent(q);
|
||||||
|
|
||||||
|
var breakLoop = false;
|
||||||
|
|
||||||
config.categories.forEach(function(category) {
|
config.categories.forEach(function(category) {
|
||||||
category.commands.forEach(function(command) {
|
category.commands.forEach(function(command) {
|
||||||
if (qSplit[0] === command.key) {
|
var isSearch = qSplitSearch[0] === command.key;
|
||||||
if (qSplit[1] && command.search) {
|
var isPath = qSplitPath[0] === command.key;
|
||||||
qSplit.shift();
|
|
||||||
var search = encodeURIComponent(qSplit[0].trim());
|
if (isSearch || isPath) {
|
||||||
|
if (qSplitSearch[1] && command.search) {
|
||||||
|
qSplitSearch.shift();
|
||||||
|
var search = encodeURIComponent(qSplitSearch.join(config.searchDelimiter).trim());
|
||||||
redirect = command.url + command.search + search;
|
redirect = command.url + command.search + search;
|
||||||
|
} else if (qSplitPath[1]) {
|
||||||
|
qSplitPath.shift();
|
||||||
|
var path = qSplitPath.join(config.pathDelimiter).trim();
|
||||||
|
redirect = command.url + '/' + path;
|
||||||
} else {
|
} else {
|
||||||
redirect = command.url;
|
redirect = command.url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
breakLoop = true;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (breakLoop) return;
|
||||||
});
|
});
|
||||||
|
|
||||||
window.location.href = redirect;
|
window.location.href = redirect;
|
||||||
|
|||||||
Reference in New Issue
Block a user