non blocking suggestions + command updates

This commit is contained in:
Cade Scroggins 2018-06-30 20:49:10 -07:00
parent dfce78f3ff
commit 332303203d

View file

@ -7,53 +7,56 @@
// if none of the specified keys are matched, the '*' key is used
commands: [
[null, 'Google', '*', 'https://encrypted.google.com', '/search?q={}', '#111'],
['Work', 'Analytics', 'a', 'https://analytics.google.com', null, '#ff6d00'],
['Work', 'Drive', 'd', 'https://drive.google.com', '/drive/search?q={}', '#4285f4'],
['Work', 'GitHub', 'g', 'https://github.com', '/search?q={}', '#333'],
['Work', 'Inbox', 'I', 'https://inbox.google.com', '/search/{}', '#4285f4'],
['Work', 'Inbox', 'i', 'https://inbox.google.com', '/search/{}', '#4285f4'],
['Work', 'Keep', 'k', 'https://keep.google.com', '/#search/text={}', '#fb0'],
['Look', 'Codrops', 'C', 'https://tympanus.net/codrops', '?search-type=posts&s={}', '#0099cc'],
['Look', 'Hunt', 'H', 'https://www.producthunt.com', '/search?q={}', '#da552f'],
['Look', 'Photos', 'P', 'https://photos.google.com', '/search/{}', '#34a853'],
['Look', 'Unsplash', 'u', 'https://unsplash.com/new', '/search/{}', '#000'],
['Lurk', 'Facebook', 'f', 'https://www.facebook.com', '/search/top/?q={}', '#3b5998'],
['Lurk', 'Instagram', 'i', 'https://www.instagram.com', null, '#833ab4'],
['Lurk', 'Hunt', 'H', 'https://www.producthunt.com', '/search?q={}', '#da552f'],
['Lurk', 'Photos', 'p', 'https://photos.google.com', '/search/{}', '#34a853'],
['Lurk', 'Reddit', 'r', 'https://www.reddit.com', '/search?q={}', '#5f99cf'],
['Lurk', 'Twitter', 't', 'https://twitter.com', '/search?q={}', '#1da1f2'],
['Lurk', 'Unsplash', 'u', 'https://unsplash.com/new', '/search/{}', '#000'],
['Listen', 'Hypem', 'h', 'https://hypem.com/popular', '/search/{}', '#83c441'],
['Listen', 'Line Radio', 'l', 'https://linerad.io', '/#{}', '#39CCCC'],
['Listen', 'Pandora', 'p', 'https://www.pandora.com', '/artist/{}', '#005483'],
['Listen', 'Play Music', 'm', 'https://play.google.com/music/listen#/all', '/music/listen#/sr/{}', '#FF4C20'],
['Listen', 'SoundCloud', 's', 'https://soundcloud.com/discover', '/search?q={}', '#ff8800'],
['Watch', 'Academy', 'A', 'https://www.khanacademy.org/', '/search?page_search_query={}', '#9cb443'],
['Watch', 'Netflix', 'n', 'https://www.netflix.com/browse', '/search?q={}', '#e50914'],
['Watch', 'Twitch', 'T', 'https://www.twitch.tv/directory/following', null, '#6441a5'],
['Watch', 'Twitch', 't', 'https://www.twitch.tv/directory/following', null, '#6441a5'],
['Watch', 'YouTube', 'y', 'https://youtube.com/feed/subscriptions', '/results?search_query={}', '#cd201f'],
['Learn', 'Academy', 'a', 'https://www.khanacademy.org', '/search?page_search_query={}', '#9cb443'],
['Learn', 'Coursera', 'c', 'https://www.coursera.org', '/courses?query={}', '#407ED7'],
['Learn', 'Egghead', 'e', 'https://egghead.io', '/search?q={}', '#171C23'],
['Download', '7digital', '7', 'https://us.7digital.com', '/search?q={}', '#07606e'],
['Download', 'RARBG', 'R', 'https://rarbg.to', '/torrents.php?search={}', '#00d1b2'],
['Download', 'Pirate Bay', 'b', 'https://thepiratebay.org', '/search/{}', '#4c4132'],
['Download', 'YTS', 'Y', 'https://yts.gs/browse-movies/all/1080p/all/7/latest', '/browse-movies/{}', '#2f2f2f'],
['Download', 'YTS', 'Y', 'https://yts.am/browse-movies/all/1080p/all/7/latest', '/browse-movies/{}', '#2f2f2f'],
],
// give suggestions as you type
suggestions: true,
// max amount of suggestions that will ever be displayed
suggestionsLimit: 5,
suggestionsLimit: 4,
// the order and limit for each suggestion influencer
// "Default" suggestions come from CONFIG.defaultSuggestions
// "DuckDuckGo" suggestions come from the duck duck go search api
// "History" suggestions come from your previously entered queries
influencers: [
{ name: 'Default', limit: 5 },
{ name: 'History', limit: 2 },
{ name: 'DuckDuckGo', limit: 5 },
{ name: 'Default', limit: 4 },
{ name: 'History', limit: 1 },
{ name: 'DuckDuckGo', limit: 4 },
],
// default search suggestions for the specified queries
defaultSuggestions: {
'g': ['g/issues', 'g/pulls', 'gist.github.com', 'g/cadejscroggins', 'g/cadejscroggins/tilde'],
'l': ['l:electronic', 'l:chill', 'l:focus', 'l:sleep', 'l:ambient'],
'r': ['r/r/unixporn', 'r/r/startpages', 'r/r/webdev', 'r/r/technology', 'r/r/portland'],
'd': ['d/u/1'],
'g': ['g/issues', 'g/pulls', 'gist.github.com', 'g/cadejscroggins'],
'i': ['i/u/1'],
'k': ['k/u/1'],
'l': ['l/#electronic+chill', 'l/#synthwave+chillwave', 'l/#focus+instrumental', 'l/#piano+sleep'],
'm': ['m/music/listen?u=1#/all'],
'p': ['p/u/1'],
'r': ['r/r/unixporn', 'r/r/startpages', 'r/r/webdev', 'r/r/technology'],
's': ['s/you/likes', 's/discover/the-upload'],
},
@ -373,7 +376,6 @@
<script>
const $ = {
bodyClassAdd: c => $.el('body').classList.add(c),
bodyClassHas: c => $.el('body').classList.contains(c),
bodyClassRemove: c => $.el('body').classList.remove(c),
el: s => document.querySelector(s),
els: s => [].slice.call(document.querySelectorAll(s) || []),
@ -664,17 +666,20 @@
suggest(input) {
input = input.trim();
if (input === '') this._clearSuggestions();
let suggestions = [];
Promise.all(this._getInfluencerPromises(input)).then(res => {
const suggestions = this._flattenAndUnique(res);
this._clearSuggestions();
for (const influencer of this._getInfluencerPromises(input)) {
influencer.then(res => {
suggestions = this._flattenAndUnique([...suggestions, ...res]);
this._clearSuggestions();
if (suggestions.length) {
this._appendSuggestions(suggestions, input);
this._registerSuggestionEvents();
$.bodyClassAdd('suggestions');
}
});
if (suggestions.length) {
this._appendSuggestions(suggestions, input);
this._registerSuggestionEvents();
$.bodyClassAdd('suggestions');
}
});
}
}
_appendSuggestions(suggestions, input) {
@ -899,7 +904,7 @@
}
hide() {
$.bodyClassRemove('form')
$.bodyClassRemove('form');
this._inputEl.value = '';
this._inputElVal = '';
}