Skip to content

Commit

Permalink
enhance the query parser
Browse files Browse the repository at this point in the history
Cade Scroggins committed Jul 17, 2017
1 parent 365b56c commit 20ab49c
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions index.html
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@
['r', 'Reddit', 'https://www.reddit.com', '/search?q={}'],
['s', 'SoundCloud', 'https://soundcloud.com/discover', '/search?q={}'],
['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={}'],
['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={}'],
@@ -123,8 +123,10 @@
list-style: none;
}

a {
a,
a:focus {
color: inherit;
outline: 0;
}

#clock {
@@ -134,6 +136,7 @@
}

#search-form {
transition: background .2s;
background: #111;
z-index: 2;
}
@@ -236,7 +239,8 @@
opacity: 0;
}

.command:hover .command-name::after {
.command a:hover .command-name::after,
.command a:focus .command-name::after {
transform: translateX(0);
opacity: 1;
}
@@ -249,7 +253,6 @@
box-sizing: border-box;
width: 100%;
height: 100%;
transition: opacity .3s;
visibility: hidden;
opacity: 0;
}
@@ -707,12 +710,12 @@ <h2 class="category-name">${name}</h2>
this._urlRegex = /^(?:(http|https)?:\/\/)?(?:[\w-]+\.)+([a-z]|[A-Z]|[0-9]){2,6}/i;
}

generateRedirect(query) {
let redirectUrl;
parse(query) {
const res = { query: query };

if (query.match(this._urlRegex)) {
const hasProtocol = query.match(this._protocolRegex);
redirectUrl = hasProtocol ? query : 'http://' + query;
res.redirect = hasProtocol ? query : 'http://' + query;
} else {
const splitSearch = query.split(this._searchDelimiter);
const splitPath = query.split(this._pathDelimiter);
@@ -723,23 +726,24 @@ <h2 class="category-name">${name}</h2>

if (isSearch || isPath) {
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]) {
redirectUrl = this._prepPath(url, splitPath);
res.redirect = this._prepPath(url, splitPath);
} else {
redirectUrl = url;
res.redirect = url;
}

return true;
}

if (key === '*') {
redirectUrl = this._prepSearch(url, searchPath, query);
res.redirect = this._prepSearch(url, searchPath, query);
}
});
}

return redirectUrl;
return res;
}

instantRedirect(query, callback) {
@@ -763,10 +767,6 @@ <h2 class="category-name">${name}</h2>
_prepSearch(url, searchPath, query) {
if (!searchPath) return url;
const baseUrl = this._stripUrlPath(url);

query = query.constructor !== Array ? query.trim()
: this._shiftAndTrim(query, this._searchDelimiter);

const urlQuery = encodeURIComponent(query);
searchPath = searchPath.replace('{}', urlQuery);
return baseUrl + searchPath;
@@ -897,7 +897,7 @@ <h2 class="category-name">${name}</h2>
const query = this._inputEl.value.trim();
this._clearInput();
this._suggester.success(query);
this._redirect(this._queryParser.generateRedirect(query));
this._redirect(this._queryParser.parse(query).redirect);
}

_submitWithValue(value) {

0 comments on commit 20ab49c

Please sign in to comment.