enhance the query parser
This commit is contained in:
+17
-17
@@ -19,7 +19,7 @@
|
|||||||
['r', 'Reddit', 'https://www.reddit.com', '/search?q={}'],
|
['r', 'Reddit', 'https://www.reddit.com', '/search?q={}'],
|
||||||
['s', 'SoundCloud', 'https://soundcloud.com/discover', '/search?q={}'],
|
['s', 'SoundCloud', 'https://soundcloud.com/discover', '/search?q={}'],
|
||||||
['T', 'TPB', 'https://thepiratebay.org', '/search/{}'],
|
['T', 'TPB', 'https://thepiratebay.org', '/search/{}'],
|
||||||
['w', 'Twitch', 'https://www.twitch.tv/directory/following', false],
|
['w', 'Twitch', 'https://www.twitch.tv/directory/following', null],
|
||||||
['t', 'Twitter', 'https://twitter.com', '/search?q={}'],
|
['t', 'Twitter', 'https://twitter.com', '/search?q={}'],
|
||||||
['Y', 'YIFY', 'https://yts.ag/browse-movies/0/1080p/all/7/latest', '/browse-movies/{}/1080p/all/0/rating'],
|
['Y', 'YIFY', 'https://yts.ag/browse-movies/0/1080p/all/7/latest', '/browse-movies/{}/1080p/all/0/rating'],
|
||||||
['y', 'YouTube', 'https://youtube.com/feed/subscriptions', '/results?search_query={}'],
|
['y', 'YouTube', 'https://youtube.com/feed/subscriptions', '/results?search_query={}'],
|
||||||
@@ -123,8 +123,10 @@
|
|||||||
list-style: none;
|
list-style: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
a {
|
a,
|
||||||
|
a:focus {
|
||||||
color: inherit;
|
color: inherit;
|
||||||
|
outline: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#clock {
|
#clock {
|
||||||
@@ -134,6 +136,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
#search-form {
|
#search-form {
|
||||||
|
transition: background .2s;
|
||||||
background: #111;
|
background: #111;
|
||||||
z-index: 2;
|
z-index: 2;
|
||||||
}
|
}
|
||||||
@@ -236,7 +239,8 @@
|
|||||||
opacity: 0;
|
opacity: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.command:hover .command-name::after {
|
.command a:hover .command-name::after,
|
||||||
|
.command a:focus .command-name::after {
|
||||||
transform: translateX(0);
|
transform: translateX(0);
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
@@ -249,7 +253,6 @@
|
|||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
transition: opacity .3s;
|
|
||||||
visibility: hidden;
|
visibility: hidden;
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
}
|
}
|
||||||
@@ -707,12 +710,12 @@
|
|||||||
this._urlRegex = /^(?:(http|https)?:\/\/)?(?:[\w-]+\.)+([a-z]|[A-Z]|[0-9]){2,6}/i;
|
this._urlRegex = /^(?:(http|https)?:\/\/)?(?:[\w-]+\.)+([a-z]|[A-Z]|[0-9]){2,6}/i;
|
||||||
}
|
}
|
||||||
|
|
||||||
generateRedirect(query) {
|
parse(query) {
|
||||||
let redirectUrl;
|
const res = { query: query };
|
||||||
|
|
||||||
if (query.match(this._urlRegex)) {
|
if (query.match(this._urlRegex)) {
|
||||||
const hasProtocol = query.match(this._protocolRegex);
|
const hasProtocol = query.match(this._protocolRegex);
|
||||||
redirectUrl = hasProtocol ? query : 'http://' + query;
|
res.redirect = hasProtocol ? query : 'http://' + query;
|
||||||
} else {
|
} else {
|
||||||
const splitSearch = query.split(this._searchDelimiter);
|
const splitSearch = query.split(this._searchDelimiter);
|
||||||
const splitPath = query.split(this._pathDelimiter);
|
const splitPath = query.split(this._pathDelimiter);
|
||||||
@@ -723,23 +726,24 @@
|
|||||||
|
|
||||||
if (isSearch || isPath) {
|
if (isSearch || isPath) {
|
||||||
if (splitSearch[1] && searchPath) {
|
if (splitSearch[1] && searchPath) {
|
||||||
redirectUrl = this._prepSearch(url, searchPath, splitSearch);
|
res.query = this._shiftAndTrim(splitSearch, this._searchDelimiter);
|
||||||
|
res.redirect = this._prepSearch(url, searchPath, res.query);
|
||||||
} else if (splitPath[1]) {
|
} else if (splitPath[1]) {
|
||||||
redirectUrl = this._prepPath(url, splitPath);
|
res.redirect = this._prepPath(url, splitPath);
|
||||||
} else {
|
} else {
|
||||||
redirectUrl = url;
|
res.redirect = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key === '*') {
|
if (key === '*') {
|
||||||
redirectUrl = this._prepSearch(url, searchPath, query);
|
res.redirect = this._prepSearch(url, searchPath, query);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirectUrl;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
instantRedirect(query, callback) {
|
instantRedirect(query, callback) {
|
||||||
@@ -763,10 +767,6 @@
|
|||||||
_prepSearch(url, searchPath, query) {
|
_prepSearch(url, searchPath, query) {
|
||||||
if (!searchPath) return url;
|
if (!searchPath) return url;
|
||||||
const baseUrl = this._stripUrlPath(url);
|
const baseUrl = this._stripUrlPath(url);
|
||||||
|
|
||||||
query = query.constructor !== Array ? query.trim()
|
|
||||||
: this._shiftAndTrim(query, this._searchDelimiter);
|
|
||||||
|
|
||||||
const urlQuery = encodeURIComponent(query);
|
const urlQuery = encodeURIComponent(query);
|
||||||
searchPath = searchPath.replace('{}', urlQuery);
|
searchPath = searchPath.replace('{}', urlQuery);
|
||||||
return baseUrl + searchPath;
|
return baseUrl + searchPath;
|
||||||
@@ -897,7 +897,7 @@
|
|||||||
const query = this._inputEl.value.trim();
|
const query = this._inputEl.value.trim();
|
||||||
this._clearInput();
|
this._clearInput();
|
||||||
this._suggester.success(query);
|
this._suggester.success(query);
|
||||||
this._redirect(this._queryParser.generateRedirect(query));
|
this._redirect(this._queryParser.parse(query).redirect);
|
||||||
}
|
}
|
||||||
|
|
||||||
_submitWithValue(value) {
|
_submitWithValue(value) {
|
||||||
|
|||||||
Reference in New Issue
Block a user