2017-12-02 02:58:06 +00:00
/* global keys:true */
if ( typeof keys === "undefined" && typeof require === "function" ) {
2017-12-02 02:48:58 +00:00
keys = require ( "./conf.priv.js" ) // eslint-disable-line global-require
}
// ****** Helper Functions ****** //
function googleCxCallback ( response ) {
const res = JSON . parse ( response . text ) . items
Omnibar . listResults ( res , ( s ) => {
const li = $ ( "<li/>" ) . html ( `
< div >
< div class = "title" > < strong > $ { s . htmlTitle } < / s t r o n g > < / d i v >
< div > $ { s . htmlSnippet } < / d i v >
< / d i v >
` )
li . data ( "url" , s . link )
return li
} )
}
function googleCxURL ( alias ) {
const key = ` google_cx_ ${ alias } `
return ` https://www.googleapis.com/customsearch/v1?key= ${ keys . google _cs } &cx= ${ keys [ key ] } &q= `
}
function googleCxPublicURL ( alias ) {
const key = ` google_cx_ ${ alias } `
return ` https://cse.google.com/cse/publicurl?cx= ${ keys [ key ] } &q= `
}
function escape ( str ) {
return String ( str ) . replace ( /[&<>"'`=/]/g , s => ( {
"&" : "&" ,
"<" : "<" ,
">" : ">" ,
"\"" : """ ,
"'" : "'" ,
"/" : "/" ,
"`" : "`" ,
"=" : "=" ,
} [ s ] ) )
2017-10-31 05:39:21 +00:00
}
2017-10-31 05:55:59 +00:00
// This is a base64-encoded image used as a placeholder for
// the crunchbase Omnibar results if they don't have an image
2017-12-02 02:48:58 +00:00
const blank = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAAAAAByaaZbAAAAIGNIUk0AAHomAACAhAAA+gAAAIDoAAB1MAAA6mAAADqYAAAXcJy6UTwAAAACYktHRAD/h4/MvwAAAAlwSFlzAAAOwwAADsMBx2+oZAAAAAd0SU1FB+EICxEMErRVWUQAAABOdEVYdFJhdyBwcm9maWxlIHR5cGUgZXhpZgAKZXhpZgogICAgICAyMAo0NTc4Njk2NjAwMDA0OTQ5MmEwMDA4MDAwMDAwMDAwMDAwMDAwMDAwCnwMkD0AAAGXSURBVEjH1ZRvc4IwDMb7/T8dbVr/sEPlPJQd3g22GzJdmxVOHaQa8N2WN7wwvyZ5Eh/hngzxTwDr0If/TAK67POxbqxnpgCIx9dkrkEvswYnAFiutFSgtQapS4ejwFYqbXQXBmC+QxawuI/MJb0LiCq0DICNHoZRKQdYLKQZEhATcQmwDYD5GR8DDtfqaYAMActvTiVMaUvqhZPVYhYAK2SBAwGMTHngnc4wVmFPW9L6k1PJxbSCkfvhqolKSQhsWSClizNyxwAWdzIADixQRXRmdWSHthsg+TknaztFMZgC3vh/nG/qo68TLAKrCSrUg1ulp3cH+BpItBp3DZf0lFXVOIDnBdwKkLO4D5Q3QMO6HJ+hUb1NKNWMGJn3jf4ejPKn99CXOtsuyab95obGL/rpdZ7oIJK87iPiumG01drbdggoCZuq/f0XaB8/FbG62Ta5cD97XJwuZUT7ONbZTIK5m94hBuQs8535MsL5xxPw6ZoNj0DiyzhhcyMf9BJ0Jk1uRRpNyb4y0UaM9UI7E8+kt/EHgR/R6042JzmiwgAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAxNy0wOC0xMVQxNzoxMjoxOC0wNDowMLy29LgAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMTctMDgtMTFUMTc6MTI6MTgtMDQ6MDDN60wEAAAAAElFTkSuQmCC"
2017-10-31 05:55:59 +00:00
2017-12-02 02:48:58 +00:00
// ****** Completions ****** //
const completions = { }
2017-11-14 07:22:07 +00:00
2017-11-17 14:30:47 +00:00
// ****** Arch Linux ****** //
// Arch Linux official repos
2017-11-14 07:22:07 +00:00
completions . al = {
2017-12-02 02:48:58 +00:00
alias : "al" ,
name : "archlinux" ,
search : "https://www.archlinux.org/packages/?arch=x86_64&q=" ,
compl : googleCxURL ( "al" ) ,
callback : googleCxCallback ,
}
2017-11-14 07:22:07 +00:00
2017-11-17 14:30:47 +00:00
// Arch Linux AUR
2017-11-14 07:22:07 +00:00
completions . au = {
2017-12-02 02:48:58 +00:00
alias : "au" ,
name : "AUR" ,
search : "https://aur.archlinux.org/packages/?O=0&SeB=nd&outdated=&SB=v&SO=d&PP=100&do_Search=Go&K=" ,
compl : "https://aur.archlinux.org/rpc?type=suggest&arg=" ,
}
completions . au . callback = ( response ) => {
const res = JSON . parse ( response . text )
Omnibar . listResults ( res , s => Omnibar . createURLItem ( {
title : s ,
url : ` https://aur.archlinux.org/packages/ ${ s } ` ,
} ) )
}
2017-11-14 07:22:07 +00:00
2017-11-17 14:30:47 +00:00
// Arch Linux Wiki
2017-11-14 07:22:07 +00:00
completions . aw = {
2017-12-02 02:48:58 +00:00
alias : "aw" ,
name : "archwiki" ,
search : "https://wiki.archlinux.org/index.php?go=go&search=" ,
compl : "https://wiki.archlinux.org/api.php?action=opensearch&format=json&formatversion=2&namespace=0&limit=10&suggest=true&search=" ,
}
2017-11-14 07:22:07 +00:00
2017-12-02 02:48:58 +00:00
completions . aw . callback = ( response ) => {
Omnibar . listWords ( JSON . parse ( response . text ) [ 1 ] )
}
2017-11-14 07:22:07 +00:00
2017-11-17 14:30:47 +00:00
// Arch Linux Forums
completions . af = {
2017-12-02 02:48:58 +00:00
alias : "af" ,
name : "archforums" ,
search : googleCxPublicURL ( "af" ) ,
compl : googleCxURL ( "af" ) ,
callback : googleCxCallback ,
}
2017-11-17 14:30:47 +00:00
// ****** Technical Resources ****** //
// Chrome Webstore
completions . cs = {
2017-12-02 02:48:58 +00:00
alias : "cs" ,
name : "chromestore" ,
search : "https://chrome.google.com/webstore/search/" ,
compl : googleCxURL ( "cs" ) ,
callback : googleCxCallback ,
}
2017-11-17 14:30:47 +00:00
// OWASP Wiki
2017-11-14 07:22:07 +00:00
completions . ow = {
2017-12-02 02:48:58 +00:00
alias : "ow" ,
name : "owasp" ,
search : "https://www.owasp.org/index.php?go=go&search=" ,
compl : "https://www.owasp.org/api.php?action=opensearch&format=json&formatversion=2&namespace=0&limit=10&suggest=true&search=" ,
}
2017-11-14 07:22:07 +00:00
2017-12-02 02:48:58 +00:00
completions . ow . callback = ( response ) => {
Omnibar . listWords ( JSON . parse ( response . text ) [ 1 ] )
}
2017-11-14 07:22:07 +00:00
2017-11-17 14:30:47 +00:00
// StackOverflow
completions . so = {
2017-12-02 02:48:58 +00:00
alias : "so" ,
name : "stackoverflow" ,
search : "https://stackoverflow.com/search?q=" ,
compl : "https://api.stackexchange.com/2.2/search/advanced?pagesize=10&order=desc&sort=relevance&site=stackoverflow&q=" ,
}
completions . so . callback = ( response ) => {
const res = JSON . parse ( response . text ) . items
Omnibar . listResults ( res , s => Omnibar . createURLItem ( {
title : ` [ ${ s . score } ] ${ s . title } ` ,
url : s . link ,
} ) )
}
2017-11-17 14:30:47 +00:00
// DockerHub repo search
completions . dh = {
2017-12-02 02:48:58 +00:00
alias : "dh" ,
name : "dockerhub" ,
search : "https://hub.docker.com/search/?page=1&q=" ,
compl : "https://hub.docker.com/v2/search/repositories/?page_size=20&query=" ,
}
completions . dh . callback = ( response ) => {
const res = JSON . parse ( response . text )
Omnibar . listResults ( res . results , ( s ) => {
let meta = ""
let repo = escape ( s . repo _name )
meta += ` [★ ${ escape ( s . star _count ) } ] `
meta += ` [↓ ${ escape ( s . pull _count ) } ] `
2017-11-17 14:30:47 +00:00
if ( repo . indexOf ( "/" ) === - 1 ) {
2017-12-02 02:48:58 +00:00
repo = ` _/ ${ repo } `
2017-11-17 14:30:47 +00:00
}
2017-12-02 02:48:58 +00:00
const li = $ ( "<li/>" ) . html ( `
2017-11-17 14:30:47 +00:00
< div >
2017-11-17 15:49:16 +00:00
< div class = "title" > < strong > $ { escape ( s . repo _name ) } < / s t r o n g > < / d i v >
2017-11-17 14:30:47 +00:00
< div > $ { meta } < / d i v >
2017-11-17 15:49:16 +00:00
< div > $ { escape ( s . short _description ) } < / d i v >
2017-11-17 14:30:47 +00:00
< / d i v >
2017-12-02 02:48:58 +00:00
` )
li . data ( "url" , ` https://hub.docker.com/r/ ${ repo } ` )
return li
} )
}
2017-11-17 14:30:47 +00:00
// GitHub
completions . gh = {
2017-12-02 02:48:58 +00:00
alias : "gh" ,
name : "github" ,
search : "https://github.com/search?q=" ,
compl : "https://api.github.com/search/repositories?sort=stars&order=desc&q=" ,
}
completions . gh . callback = ( response ) => {
const res = JSON . parse ( response . text ) . items
Omnibar . listResults ( res , ( s ) => {
let prefix = ""
2017-11-17 14:30:47 +00:00
if ( s . stargazers _count ) {
2017-12-02 02:48:58 +00:00
prefix += ` [★ ${ s . stargazers _count } ] `
2017-11-17 14:30:47 +00:00
}
return Omnibar . createURLItem ( {
title : prefix + s . full _name ,
2017-12-02 02:48:58 +00:00
url : s . html _url ,
} )
} )
}
2017-11-17 14:30:47 +00:00
// Domainr domain search
completions . do = {
2017-12-02 02:48:58 +00:00
alias : "do" ,
name : "domainr" ,
search : "https://domainr.com/?q=" ,
compl : ` https://domainr.p.mashape.com/v2/search?mashape-key= ${ keys . domainr } &query=%s ` ,
}
completions . do . callback = ( response ) => {
const res = JSON . parse ( response . text ) . results
const domains = [ ]
res . forEach ( ( r ) => {
const d = {
id : escape ( r . domain ) . replace ( "." , "-" ) ,
domain : escape ( r . domain ) ,
}
domains . push ( d )
} )
const domainQuery = domains . map ( d => d . domain ) . join ( "," )
2017-11-17 14:30:47 +00:00
runtime . command ( {
2017-12-02 02:48:58 +00:00
action : "request" ,
method : "get" ,
url : ` https://domainr.p.mashape.com/v2/status?mashape-key= ${ keys . domainr } &domain= ${ domainQuery } ` ,
} , ( sresponse ) => {
const sres = JSON . parse ( sresponse . text ) . status
sres . forEach ( ( s ) => {
const id = ` #sk-domain- ${ escape ( s . domain ) . replace ( "." , "-" ) } `
const available = s . summary === "inactive"
const color = available ? "#23b000" : "#ff4d00"
const symbol = available ? "✔ " : "✘ "
$ ( id ) . text ( symbol + $ ( id ) . text ( ) ) . css ( "color" , color )
} )
} )
Omnibar . listResults ( domains , ( d ) => {
const li = $ ( "<li/>" ) . html ( `
2017-11-17 14:30:47 +00:00
< div id = "sk-domain-${d.id}" >
< div class = "title" > < strong > $ { d . domain } < / s t r o n g > < / d i v >
< / d i v >
2017-12-02 02:48:58 +00:00
` )
li . data ( "url" , ` https://domainr.com/ ${ d . domain } ` )
return li
} )
}
2017-11-17 14:30:47 +00:00
// Vim Wiki
2017-11-14 07:22:07 +00:00
completions . vw = {
2017-12-02 02:48:58 +00:00
alias : "vw" ,
name : "vimwikia" ,
search : "https://vim.wikia.com/wiki/Special:Search?query=" ,
compl : "https://vim.wikia.com/api.php?action=opensearch&format=json&formatversion=2&namespace=0&limit=10&suggest=true&search=" ,
}
2017-11-14 07:22:07 +00:00
2017-12-02 02:48:58 +00:00
completions . vw . callback = ( response ) => {
Omnibar . listWords ( JSON . parse ( response . text ) [ 1 ] )
}
2017-11-14 07:22:07 +00:00
2017-11-17 14:30:47 +00:00
// ****** Shopping & Food ****** //
// Amazon
2017-11-14 07:22:07 +00:00
completions . az = {
2017-12-02 02:48:58 +00:00
alias : "az" ,
name : "amazon" ,
search : "https://smile.amazon.com/s/?field-keywords=" ,
compl : "https://completion.amazon.com/search/complete?method=completion&mkt=1&search-alias=aps&q=" ,
}
2017-11-14 07:22:07 +00:00
2017-12-02 02:48:58 +00:00
completions . az . callback = ( response ) => {
const res = JSON . parse ( response . text ) [ 1 ]
Omnibar . listWords ( res )
}
2017-11-14 07:22:07 +00:00
2017-11-17 14:30:47 +00:00
// Craigslist
2017-11-14 07:22:07 +00:00
completions . cl = {
2017-12-02 02:48:58 +00:00
alias : "cl" ,
name : "craigslist" ,
search : "https://craigslist.org/search/sss?query=" ,
compl : "https://craigslist.org/suggest?v=12&type=search&cat=sss&area=1&term=" ,
}
2017-11-14 07:22:07 +00:00
2017-12-02 02:48:58 +00:00
completions . cl . callback = ( response ) => {
Omnibar . listWords ( JSON . parse ( response . text ) )
}
2017-11-14 07:22:07 +00:00
2017-11-17 14:30:47 +00:00
// Yelp
completions . yp = {
2017-12-02 02:48:58 +00:00
alias : "yp" ,
name : "yelp" ,
search : "https://www.yelp.com/search?find_desc=" ,
compl : "https://www.yelp.com/search_suggest/v2/prefetch?prefix=" ,
}
completions . yp . callback = ( response ) => {
const res = JSON . parse ( response . text ) . response
const words = [ ]
res . forEach ( ( r ) => {
r . suggestions . forEach ( ( s ) => {
const w = s . query
2017-11-17 14:30:47 +00:00
if ( words . indexOf ( w ) === - 1 ) {
2017-12-02 02:48:58 +00:00
words . push ( w )
2017-11-17 14:30:47 +00:00
}
2017-12-02 02:48:58 +00:00
} )
} )
Omnibar . listWords ( words )
}
2017-11-17 14:30:47 +00:00
// ****** General References, Calculators & Utilities ****** //
// Dictionary
completions . de = {
2017-12-02 02:48:58 +00:00
alias : "de" ,
name : "define" ,
search : "http://onelook.com/?w=" ,
compl : "https://api.datamuse.com/words?md=d&sp=%s*" ,
}
completions . de . callback = ( response ) => {
const res = JSON . parse ( response . text )
const defs = [ ]
res . forEach ( ( r ) => {
if ( ! r . defs || r . defs . length === 0 ) {
defs . push ( [ r . word , "" , "" ] )
return
}
r . defs . forEach ( ( d ) => {
const ds = d . split ( "\t" )
const sp = ` ( ${ ds [ 0 ] } ) `
const def = ds [ 1 ]
defs . push ( [ r . word , sp , def ] )
} )
} )
Omnibar . listResults ( defs , ( d ) => {
const word = escape ( d [ 0 ] )
const pos = escape ( d [ 1 ] )
const def = escape ( d [ 2 ] )
const li = $ ( "<li/>" ) . html ( ` <div class="title"><strong> ${ word } </strong> <em> ${ pos } </em> ${ def } </div> ` )
li . data ( "url" , ` http://onelook.com/?w= ${ encodeURIComponent ( d [ 0 ] ) } ` )
return li
} )
}
2017-11-17 14:30:47 +00:00
// Thesaurus
completions . th = {
2017-12-02 02:48:58 +00:00
alias : "th" ,
name : "thesaurus" ,
search : "https://www.onelook.com/reverse-dictionary.shtml?s=" ,
compl : "https://api.datamuse.com/words?md=d&ml=%s" ,
}
completions . th . callback = ( response ) => {
const res = JSON . parse ( response . text )
const defs = [ ]
res . forEach ( ( r ) => {
if ( ! r . defs || r . defs . length === 0 ) {
defs . push ( [ escape ( r . word ) , "" , "" ] )
return
}
r . defs . forEach ( ( d ) => {
const ds = d . split ( "\t" )
const sp = ` ( ${ escape ( ds [ 0 ] ) } ) `
const def = escape ( ds [ 1 ] )
defs . push ( [ escape ( r . word ) , sp , def ] )
} )
} )
Omnibar . listResults ( defs , ( d ) => {
const li = $ ( "<li/>" ) . html ( ` <div class="title"><strong> ${ d [ 0 ] } </strong> <em> ${ d [ 1 ] } </em> ${ d [ 2 ] } </div> ` )
li . data ( "url" , ` http://onelook.com/?w= ${ d [ 0 ] } ` )
return li
} )
}
2017-11-17 14:30:47 +00:00
// Wikipedia
completions . wp = {
2017-12-02 02:48:58 +00:00
alias : "wp" ,
name : "wikipedia" ,
search : "https://en.wikipedia.org/w/index.php?search=" ,
compl : "https://en.wikipedia.org/w/api.php?action=query&format=json&list=prefixsearch&utf8&pssearch=" ,
}
2017-11-17 14:30:47 +00:00
2017-12-02 02:48:58 +00:00
completions . wp . callback = ( response ) => {
const res = JSON . parse ( response . text ) . query . prefixsearch
. map ( r => r . title )
Omnibar . listWords ( res )
}
2017-11-17 14:30:47 +00:00
// WolframAlpha
2017-11-14 07:22:07 +00:00
completions . wa = {
2017-12-02 02:48:58 +00:00
alias : "wa" ,
name : "wolframalpha" ,
search : "http://www.wolframalpha.com/input/?i=" ,
compl : ` http://api.wolframalpha.com/v2/query?appid= ${ keys . wolframalpha } &format=plaintext&output=json&reinterpret=true&input=%s ` ,
}
2017-10-31 05:39:21 +00:00
2017-12-02 02:48:58 +00:00
completions . wa . callback = ( response ) => {
const res = JSON . parse ( response . text ) . queryresult
2017-11-14 07:22:07 +00:00
if ( res . error ) {
2017-12-02 02:48:58 +00:00
Omnibar . listResults ( [ "" ] , ( ) => {
const li = $ ( "<li/>" ) . html ( `
2017-11-14 07:22:07 +00:00
< div >
2017-11-17 15:49:16 +00:00
< div class = "title" > < strong > Error < / s t r o n g > ( C o d e $ { e s c a p e ( r e s . e r r o r . c o d e ) } ) < / d i v >
< div class = "title" > $ { escape ( res . error . msg ) } < / d i v >
2017-11-14 07:22:07 +00:00
< / d i v >
2017-12-02 02:48:58 +00:00
` )
return li
} )
return
2017-11-14 07:22:07 +00:00
}
if ( ! res . success ) {
2017-12-02 02:48:58 +00:00
if ( res . tips ) {
Omnibar . listResults ( [ "" ] , ( ) => {
const li = $ ( "<li/>" ) . html ( `
2017-11-14 07:22:07 +00:00
< div >
< div class = "title" > < strong > No Results < / s t r o n g > < / d i v >
2017-11-17 15:49:16 +00:00
< div class = "title" > $ { escape ( res . tips . text ) } < / d i v >
2017-11-14 07:22:07 +00:00
< / d i v >
2017-12-02 02:48:58 +00:00
` )
return li
} )
}
if ( res . didyoumeans ) {
Omnibar . listResults ( res . didyoumeans , ( s ) => {
const li = $ ( "<li/>" ) . html ( `
2017-11-14 07:22:07 +00:00
< div >
< div class = "title" > < strong > Did you mean ... ? < / s t r o n g > < / d i v >
2017-11-17 15:49:16 +00:00
< div class = "title" > $ { escape ( s . val ) } < / d i v >
2017-11-14 07:22:07 +00:00
< / d i v >
2017-12-02 02:48:58 +00:00
` )
return li
} )
}
return
2017-11-14 07:22:07 +00:00
}
2017-12-02 02:48:58 +00:00
const results = [ ]
res . pods . forEach ( ( p ) => {
const result = {
title : escape ( p . title ) ,
values : [ ] ,
url : "http://www.wolframalpha.com/input/?i=" ,
}
if ( p . numsubpods > 0 ) {
result . url += encodeURIComponent ( p . subpods [ 0 ] . plaintext )
p . subpods . forEach ( ( sp ) => {
if ( ! sp . plaintext ) return
let v = ""
if ( sp . title ) {
v += ` <strong> ${ escape ( sp . title ) } </strong>: `
}
v += escape ( sp . plaintext )
result . values . push ( ` <div class="title"> ${ v } </div> ` )
} )
}
if ( result . values . length > 0 ) {
results . push ( result )
}
} )
2017-11-14 07:22:07 +00:00
2017-12-02 02:48:58 +00:00
Omnibar . listResults ( results , ( r ) => {
const li = $ ( "<li/>" ) . html ( `
2017-11-14 07:22:07 +00:00
< div >
< div class = "title" > < strong > $ { r . title } < / s t r o n g > < / d i v >
$ { r . values . join ( "\n" ) }
< / d i v >
2017-12-02 02:48:58 +00:00
` )
li . data ( "url" , r . url )
return li
} )
}
2017-11-14 07:22:07 +00:00
2017-11-17 14:30:47 +00:00
// ****** Business Utilities & References ****** //
// Crunchbase Organization Search
2017-11-14 07:22:07 +00:00
completions . co = {
2017-12-02 02:48:58 +00:00
alias : "co" ,
name : "crunchbase-orgs" ,
search : "https://www.crunchbase.com/app/search/?q=" ,
compl : ` https://api.crunchbase.com/v/3/odm_organizations?user_key= ${ keys . crunchbase } &query=%s ` ,
}
completions . co . callback = ( response ) => {
const res = JSON . parse ( response . text ) . data . items
const orgs = [ ]
res . forEach ( ( rr ) => {
const r = rr . properties
const p = {
2017-11-17 15:49:16 +00:00
name : escape ( r . name ) ,
domain : escape ( r . domain ) ,
desc : escape ( r . short _description ) ,
role : escape ( r . primary _role ) ,
2017-12-02 02:48:58 +00:00
img : blank ,
loc : "" ,
2017-12-02 05:04:55 +00:00
url : ` https://www.crunchbase.com/ ${ r . web _path } ` ,
2017-12-02 02:48:58 +00:00
}
p . loc += ( r . city _name !== null ) ? escape ( r . city _name ) : ""
p . loc += ( r . region _name !== null && p . loc !== "" ) ? ", " : ""
p . loc += ( r . region _name !== null ) ? escape ( r . region _name ) : ""
p . loc += ( r . country _code !== null && p . loc !== "" ) ? ", " : ""
p . loc += ( r . country _code !== null ) ? escape ( r . country _code ) : ""
p . loc += ( p . loc === "" ) ? "Earth" : ""
2017-11-14 07:22:07 +00:00
if ( r . profile _image _url !== null ) {
2017-12-02 02:48:58 +00:00
const url = encodeURIComponent ( r . profile _image _url )
const path = url . split ( "/" )
const img = path [ path . length - 1 ]
p . img = ` http://public.crunchbase.com/t_api_images/v1402944794/c_pad,h_50,w_50/ ${ img } `
2017-11-14 07:22:07 +00:00
}
2017-12-02 02:48:58 +00:00
orgs . push ( p )
} )
2017-11-14 07:22:07 +00:00
2017-12-02 02:48:58 +00:00
Omnibar . listResults ( orgs , ( p ) => {
const li = $ ( "<li/>" ) . html ( `
2017-11-14 07:22:07 +00:00
< div style = "width:100%;height:6em;display:block;" >
< div style = "float:left;" >
< img style = "width:4em;height:4em;max-width:4em;max-height:4em;overflow:hidden;" src = "${p.img}" alt = "${p.name}" >
< / d i v >
< div style = "float:left;height:100%;margin-left:10px;" >
< div class = "title" > < strong > $ { p . name } < / s t r o n g > < / d i v >
< div class = "title" > Type : < em > $ { p . role } < / e m > , D o m a i n : < e m > $ { p . d o m a i n } < / e m > < / d i v >
< div class = "title" > $ { p . desc } < / d i v >
< div class = "title" > < em > $ { p . loc } < / e m > < / d i v >
< / d i v >
< / d i v >
2017-12-02 02:48:58 +00:00
` )
li . data ( "url" , p . url )
return li
} )
}
2017-11-14 07:22:07 +00:00
2017-11-17 14:30:47 +00:00
// Crunchbase People Search
2017-11-14 07:22:07 +00:00
completions . cp = {
2017-12-02 02:48:58 +00:00
alias : "cp" ,
name : "crunchbase-people" ,
search : "https://www.crunchbase.com/app/search/?q=" ,
compl : ` https://api.crunchbase.com/v/3/odm_people?user_key= ${ keys . crunchbase } &query=%s ` ,
}
completions . cp . callback = ( response ) => {
const res = JSON . parse ( response . text ) . data . items
const people = [ ]
res . forEach ( ( rr ) => {
const r = rr . properties
const p = {
name : ` ${ escape ( r . first _name ) } ${ escape ( r . last _name ) } ` ,
2017-11-14 07:22:07 +00:00
desc : "" ,
2017-12-02 02:48:58 +00:00
img : blank ,
loc : "" ,
2017-12-02 05:04:55 +00:00
url : ` https://www.crunchbase.com/ ${ r . web _path } ` ,
2017-12-02 02:48:58 +00:00
}
p . desc += ( r . title !== null ) ? escape ( r . title ) : ""
p . desc += ( r . organization _name !== null && p . desc !== "" ) ? ", " : ""
p . desc += ( r . organization _name !== null ) ? escape ( r . organization _name ) : ""
p . desc += ( p . desc === "" ) ? "Human" : ""
p . loc += ( r . city _name !== null ) ? escape ( r . city _name ) : ""
p . loc += ( r . region _name !== null && p . loc !== "" ) ? ", " : ""
p . loc += ( r . region _name !== null ) ? escape ( r . region _name ) : ""
p . loc += ( r . country _code !== null && p . loc !== "" ) ? ", " : ""
p . loc += ( r . country _code !== null ) ? escape ( r . country _code ) : ""
p . loc += ( p . loc === "" ) ? "Earth" : ""
2017-11-14 07:22:07 +00:00
if ( r . profile _image _url !== null ) {
2017-12-02 02:48:58 +00:00
const url = r . profile _image _url
const path = url . split ( "/" )
const img = encodeURIComponent ( path [ path . length - 1 ] )
p . img = ` http://public.crunchbase.com/t_api_images/v1402944794/c_pad,h_50,w_50/ ${ img } `
2017-11-14 07:22:07 +00:00
}
2017-12-02 02:48:58 +00:00
people . push ( p )
} )
2017-11-14 07:22:07 +00:00
2017-12-02 02:48:58 +00:00
Omnibar . listResults ( people , ( p ) => {
const li = $ ( "<li/>" ) . html ( `
2017-11-14 07:22:07 +00:00
< div style = "width:100%;height:6em;display:block;" >
< div style = "float:left;" >
< img style = "width:4em;height:4em;max-width:4em;max-height:4em;overflow:hidden;" src = "${p.img}" alt = "${p.name}" >
< / d i v >
< div style = "float:left;height:100%;margin-left:10px;" >
< div class = "title" > < strong > $ { p . name } < / s t r o n g > < / d i v >
< div class = "title" > $ { p . desc } < / d i v >
< div class = "title" > < em > $ { p . loc } < / e m > < / d i v >
< / d i v >
< / d i v >
2017-12-02 02:48:58 +00:00
` )
li . data ( "url" , p . url )
return li
} )
}
2017-11-14 07:22:07 +00:00
2017-11-17 14:30:47 +00:00
// ****** Search Engines ****** //
// DuckDuckGo
completions . dg = {
2017-12-02 02:48:58 +00:00
alias : "dg" ,
name : "duckduckgo" ,
search : "https://duckduckgo.com/?q=" ,
compl : "https://duckduckgo.com/ac/?q=" ,
}
completions . dg . callback = ( response ) => {
const res = JSON . parse ( response . text ) . map ( r => r . phrase )
Omnibar . listWords ( res )
}
2017-11-14 07:22:07 +00:00
2017-11-17 14:30:47 +00:00
// Google
completions . go = {
2017-12-02 02:48:58 +00:00
alias : "go" ,
name : "google" ,
search : "https://www.google.com/search?q=" ,
compl : "https://www.google.com/complete/search?client=chrome-omni&gs_ri=chrome-ext&oit=1&cp=1&pgcl=7&q=" ,
}
2017-11-14 07:22:07 +00:00
2017-12-02 02:48:58 +00:00
completions . go . callback = ( response ) => {
Omnibar . listWords ( JSON . parse ( response . text ) [ 1 ] )
}
2017-11-14 07:22:07 +00:00
2017-11-17 14:30:47 +00:00
// Google - I'm Feeling Lucky
completions . gl = {
2017-12-02 02:48:58 +00:00
alias : "gl" ,
name : "google-lucky" ,
search : "https://www.google.com/search?btnI=1&q=" ,
compl : "https://www.google.com/complete/search?client=chrome-omni&gs_ri=chrome-ext&oit=1&cp=1&pgcl=7&q=" ,
}
2017-11-14 07:22:07 +00:00
2017-12-02 02:48:58 +00:00
completions . gl . callback = ( response ) => {
Omnibar . listWords ( JSON . parse ( response . text ) [ 1 ] )
}
2017-11-14 07:22:07 +00:00
2017-11-17 14:30:47 +00:00
// ****** Elixir ****** //
2017-11-14 07:22:07 +00:00
2017-11-17 14:30:47 +00:00
// Hex.pm
completions . hx = {
2017-12-02 02:48:58 +00:00
alias : "hx" ,
name : "hex" ,
search : "https://hex.pm/packages?sort=downloads&search=" ,
compl : "https://hex.pm/api/packages?sort=downloads&search=" ,
}
completions . hx . callback = ( response ) => {
const res = JSON . parse ( response . text )
Omnibar . listResults ( res , ( s ) => {
let dls = ""
let desc = ""
let liscs = ""
2017-11-17 14:30:47 +00:00
if ( s . downloads && s . downloads . all ) {
2017-12-02 02:48:58 +00:00
dls = ` [↓ ${ escape ( s . downloads . all ) } ] `
2017-11-17 14:30:47 +00:00
}
2017-12-02 02:48:58 +00:00
if ( s . meta ) {
2017-11-17 14:30:47 +00:00
if ( s . meta . description ) {
2017-12-02 02:48:58 +00:00
desc = escape ( s . meta . description )
2017-11-17 14:30:47 +00:00
}
if ( s . meta . licenses ) {
2017-12-02 02:48:58 +00:00
s . meta . licenses . forEach ( ( l ) => {
liscs += ` [© ${ escape ( l ) } ] `
} )
2017-11-17 14:30:47 +00:00
}
2017-11-14 07:22:07 +00:00
}
2017-12-02 02:48:58 +00:00
const li = $ ( "<li/>" ) . html ( `
2017-11-14 07:22:07 +00:00
< div >
2017-11-17 15:49:16 +00:00
< div class = "title" > $ { escape ( s . repository ) } / < strong > $ { escape ( s . name ) } < / s t r o n g > < / d i v >
2017-11-17 14:30:47 +00:00
< div > $ { dls } $ { liscs } < / d i v >
< div > $ { desc } < / d i v >
2017-11-14 07:22:07 +00:00
< / d i v >
2017-12-02 02:48:58 +00:00
` )
li . data ( "url" , s . html _url )
return li
} )
}
2017-11-14 07:22:07 +00:00
2017-11-17 14:30:47 +00:00
// hexdocs
// Same as hex but links to documentation pages
completions . hd = {
2017-12-02 02:48:58 +00:00
alias : "hd" ,
name : "hexdocs" ,
search : "https://hex.pm/packages?sort=downloads&search=" ,
compl : "https://hex.pm/api/packages?sort=downloads&search=" ,
}
completions . hd . callback = ( response ) => {
const res = JSON . parse ( response . text )
Omnibar . listResults ( res , ( s ) => {
let dls = ""
let desc = ""
let liscs = ""
2017-11-17 14:30:47 +00:00
if ( s . downloads && s . downloads . all ) {
2017-12-02 02:48:58 +00:00
dls = ` [↓ ${ escape ( s . downloads . all ) } ] `
2017-11-17 14:30:47 +00:00
}
2017-12-02 02:48:58 +00:00
if ( s . meta ) {
2017-11-17 14:30:47 +00:00
if ( s . meta . description ) {
2017-12-02 02:48:58 +00:00
desc = escape ( s . meta . description )
2017-11-17 14:30:47 +00:00
}
if ( s . meta . licenses ) {
2017-12-02 02:48:58 +00:00
s . meta . licenses . forEach ( ( l ) => {
liscs += ` [© ${ escape ( l ) } ] `
} )
2017-11-17 14:30:47 +00:00
}
}
2017-12-02 02:48:58 +00:00
const li = $ ( "<li/>" ) . html ( `
2017-11-17 14:30:47 +00:00
< div >
2017-11-17 15:49:16 +00:00
< div class = "title" > $ { escape ( s . repository ) } / < strong > $ { escape ( s . name ) } < / s t r o n g > < / d i v >
2017-11-17 14:30:47 +00:00
< div > $ { dls } $ { liscs } < / d i v >
< div > $ { desc } < / d i v >
2017-11-14 07:22:07 +00:00
< / d i v >
2017-12-02 02:48:58 +00:00
` )
li . data ( "url" , ` https://hexdocs.pm/ ${ encodeURIComponent ( s . name ) } ` )
return li
} )
}
2017-11-14 07:22:07 +00:00
2017-11-17 14:30:47 +00:00
// Exdocs
// Similar to `hd` but searches inside docs using Google Custom Search
2017-11-14 07:22:07 +00:00
completions . ex = {
2017-12-02 02:48:58 +00:00
alias : "ex" ,
name : "exdocs" ,
search : "https://hex.pm/packages?sort=downloads&search=" ,
compl : googleCxURL ( "ex" ) ,
}
2017-11-14 07:22:07 +00:00
2017-12-02 02:48:58 +00:00
completions . ex . callback = ( response ) => {
const res = JSON . parse ( response . text ) . items
Omnibar . listResults ( res , ( s ) => {
let hash = ""
2017-11-14 07:22:07 +00:00
2017-12-02 02:48:58 +00:00
const snippet = s . htmlSnippet
const openTag = "<b>"
const closeTag = "</b>"
const openArgs = "("
const closeArgs = ")"
let f1 = snippet . indexOf ( openTag )
if ( f1 === - 1 ) {
return
}
const f2 = snippet . indexOf ( closeTag )
if ( f2 === - 1 ) {
return
}
f1 += openTag . length
const f3 = f2 + closeTag . length
const fname = snippet . slice ( f1 , f2 )
const snippetEnd = snippet . slice ( f3 )
2017-11-14 07:22:07 +00:00
2017-12-02 02:48:58 +00:00
const a1 = snippetEnd . indexOf ( openArgs )
if ( a1 !== 0 ) {
return
}
let a2 = snippetEnd . indexOf ( closeArgs )
if ( a2 === - 1 ) {
return
}
a2 += closeArgs . length
const fargs = snippetEnd . slice ( a1 , a2 )
const fary = fargs . replace ( new RegExp ( openArgs + closeArgs ) , "" ) . split ( "," ) . length
hash = escape ( ` ${ fname } / ${ fary } ` )
2017-11-14 07:22:07 +00:00
2017-12-02 02:48:58 +00:00
const moduleName = escape ( s . title ) . split ( " – " ) [ 0 ]
2017-11-14 07:22:07 +00:00
2017-12-02 02:48:58 +00:00
let subtitle = ""
2017-11-14 07:22:07 +00:00
if ( hash ) {
subtitle = `
< div style = "font-size:1.1em; line-height:1.25em" >
< em > $ { moduleName } < / e m > . < s t r o n g > $ { h a s h } < / s t r o n g >
2017-12-02 02:48:58 +00:00
< / d i v > `
2017-11-14 07:22:07 +00:00
}
2017-12-02 02:48:58 +00:00
const li = $ ( "<li/>" ) . html ( `
2017-11-14 07:22:07 +00:00
< div >
< div class = "title" > < strong > $ { s . htmlTitle } < / s t r o n g > < / d i v >
$ { subtitle }
< div > $ { s . htmlSnippet } < / d i v >
< / d i v >
2017-12-02 02:48:58 +00:00
` )
li . data ( "url" , ` ${ s . link } # ${ hash } ` )
return li // eslint-disable-line consistent-return
} )
}
2017-11-14 07:22:07 +00:00
2017-11-17 14:30:47 +00:00
// ****** Golang ****** //
// Godoc
2017-11-14 07:22:07 +00:00
completions . gd = {
2017-12-02 02:48:58 +00:00
alias : "gd" ,
name : "godoc" ,
search : "https://godoc.org/?q=" ,
compl : "https://api.godoc.org/search?q=" ,
}
completions . gd . callback = ( response ) => {
const res = JSON . parse ( response . text ) . results
Omnibar . listResults ( res , ( s ) => {
let prefix = ""
2017-11-14 07:22:07 +00:00
if ( s . import _count ) {
2017-12-02 02:48:58 +00:00
prefix += ` [↓ ${ s . import _count } ] `
2017-11-14 07:22:07 +00:00
}
if ( s . stars ) {
2017-12-02 02:48:58 +00:00
prefix += ` [★ ${ s . stars } ] `
2017-11-14 07:22:07 +00:00
}
return Omnibar . createURLItem ( {
title : prefix + s . path ,
2017-12-02 02:48:58 +00:00
url : ` https://godoc.org/ ${ s . path } ` ,
} )
} )
}
2017-11-14 07:22:07 +00:00
2017-11-18 08:11:51 +00:00
// Gowalker
completions . gw = {
2017-12-02 02:48:58 +00:00
alias : "gw" ,
name : "gowalker" ,
search : "https://gowalker.org/search?auto_redirect=true&q=" ,
compl : "https://gowalker.org/search/json?q=" ,
}
completions . gw . callback = ( response ) => {
const res = JSON . parse ( response . text ) . results
Omnibar . listResults ( res , ( s ) => {
const title = escape ( s . title )
const desc = escape ( s . description )
const li = $ ( "<li/>" ) . html ( `
2017-11-18 08:11:51 +00:00
< div >
< div class = "title" > < strong > $ { title } < / s t r o n g > < / d i v >
< div > $ { desc } < / d i v >
< / d i v >
2017-12-02 02:48:58 +00:00
` )
li . data ( "url" , ` https://golang.org/doc/ ${ encodeURIComponent ( s . url ) } ` )
return li
} )
}
2017-11-18 08:11:51 +00:00
2017-11-17 14:30:47 +00:00
// Go-Search
2017-11-14 07:22:07 +00:00
completions . gs = {
2017-12-02 02:48:58 +00:00
alias : "gs" ,
name : "go-search" ,
search : "http://go-search.org/search?q=" ,
compl : "http://go-search.org/api?action=search&q=" ,
}
completions . gs . callback = ( response ) => {
const res = JSON . parse ( response . text ) . hits
. map ( r => r . package )
Omnibar . listWords ( res )
}
2017-11-14 07:22:07 +00:00
2017-11-17 14:30:47 +00:00
// ****** Haskell ****** //
// Hackage
2017-11-14 07:22:07 +00:00
completions . ha = {
2017-12-02 02:48:58 +00:00
alias : "ha" ,
name : "hackage" ,
search : "https://hackage.haskell.org/packages/search?terms=" ,
compl : "https://hackage.haskell.org/packages/search.json?terms=" ,
}
completions . ha . callback = ( response ) => {
const res = JSON . parse ( response . text )
Omnibar . listResults ( res , s => Omnibar . createURLItem ( {
title : s . name ,
url : ` https://hackage.haskell.org/package/ ${ s . name } ` ,
} ) )
}
2017-11-14 07:22:07 +00:00
2017-11-17 14:30:47 +00:00
// Hoogle
2017-11-14 07:22:07 +00:00
completions . ho = {
2017-12-02 02:48:58 +00:00
alias : "ho" ,
name : "hoogle" ,
search : ` https://www.haskell.org/hoogle/?hoogle= ${
encodeURIComponent ( "+platform +xmonad +xmonad-contrib " ) } ` , // This tells Hoogle to include these modules in the search - encodeURIComponent is only used for better readability
compl : ` https://www.haskell.org/hoogle/?mode=json&hoogle= ${
encodeURIComponent ( "+platform +xmonad +xmonad-contrib " ) } ` ,
}
completions . ho . callback = ( response ) => {
const res = JSON . parse ( response . text ) . results
Omnibar . listResults ( res , s => Omnibar . createURLItem ( {
title : s . self ,
url : s . location ,
} ) )
}
2017-11-14 07:22:07 +00:00
2017-11-17 14:30:47 +00:00
// Haskell Wiki
2017-11-14 07:22:07 +00:00
completions . hw = {
2017-12-02 02:48:58 +00:00
alias : "hw" ,
name : "haskellwiki" ,
search : "https://wiki.haskell.org/index.php?go=go&search=" ,
compl : "https://wiki.haskell.org/api.php?action=opensearch&format=json&formatversion=2&namespace=0&limit=10&suggest=true&search=" ,
}
2017-11-14 07:22:07 +00:00
2017-12-02 02:48:58 +00:00
completions . hw . callback = ( response ) => {
Omnibar . listWords ( JSON . parse ( response . text ) [ 1 ] )
}
2017-11-14 07:22:07 +00:00
2017-11-17 14:30:47 +00:00
// Hayoo
2017-11-14 07:22:07 +00:00
completions . hy = {
2017-12-02 02:48:58 +00:00
alias : "hy" ,
name : "hayoo" ,
search : "http://hayoo.fh-wedel.de/?query=" ,
compl : "http://hayoo.fh-wedel.de/json?query=" ,
}
completions . hy . callback = ( response ) => {
const res = JSON . parse ( response . text ) . result
Omnibar . listResults ( res , s => Omnibar . createURLItem ( {
title : ` [ ${ s . resultType } ] ${ s . resultName } ` ,
url : s . resultUri ,
} ) )
}
2017-11-14 07:22:07 +00:00
2017-11-17 14:30:47 +00:00
// ****** HTML, CSS, JavaScript, NodeJS, ... ****** //
2017-11-17 15:46:51 +00:00
// jQuery API documentation
completions . jq = {
2017-12-02 02:48:58 +00:00
alias : "jq" ,
name : "jquery" ,
search : googleCxPublicURL ( "jq" ) ,
compl : googleCxURL ( "jq" ) ,
callback : googleCxCallback ,
}
2017-11-17 15:46:51 +00:00
2017-11-17 14:30:47 +00:00
// NodeJS standard library documentation
completions . no = {
2017-12-02 02:48:58 +00:00
alias : "no" ,
name : "node" ,
search : googleCxPublicURL ( "no" ) ,
compl : googleCxURL ( "no" ) ,
callback : googleCxCallback ,
}
2017-11-17 14:30:47 +00:00
// Mozilla Developer Network (MDN)
2017-11-14 07:22:07 +00:00
completions . md = {
2017-12-02 02:48:58 +00:00
alias : "md" ,
name : "mdn" ,
search : "https://developer.mozilla.org/en-US/search?q=" ,
compl : "https://developer.mozilla.org/en-US/search.json?q=" ,
}
completions . md . callback = ( response ) => {
const res = JSON . parse ( response . text )
Omnibar . listResults ( res . documents , ( s ) => {
let excerpt = escape ( s . excerpt )
if ( excerpt . length > 240 ) {
excerpt = ` ${ excerpt . slice ( 0 , 240 ) } … `
2017-11-14 07:22:07 +00:00
}
2017-12-02 02:48:58 +00:00
res . query . split ( " " ) . forEach ( ( q ) => {
excerpt = excerpt . replace ( new RegExp ( q , "gi" ) , "<strong>$&</strong>" )
} )
const title = escape ( s . title )
const slug = escape ( s . slug )
const li = $ ( "<li/>" ) . html ( `
2017-11-14 07:22:07 +00:00
< div >
2017-11-17 15:49:16 +00:00
< div class = "title" > < strong > $ { title } < / s t r o n g > < / d i v >
< div style = "font-size:0.8em" > < em > $ { slug } < / e m > < / d i v >
2017-11-14 07:22:07 +00:00
< div > $ { excerpt } < / d i v >
< / d i v >
2017-12-02 02:48:58 +00:00
` )
li . data ( "url" , s . url )
return li
} )
}
2017-11-14 07:22:07 +00:00
2017-11-17 14:30:47 +00:00
// NPM registry search
2017-11-14 07:22:07 +00:00
completions . np = {
2017-12-02 02:48:58 +00:00
alias : "np" ,
name : "npm" ,
search : "https://www.npmjs.com/search?q=" ,
compl : "https://api.npms.io/v2/search/suggestions?size=20&q=" ,
}
completions . np . callback = ( response ) => {
const res = JSON . parse ( response . text )
Omnibar . listResults ( res , ( s ) => {
let flags = ""
let desc = ""
let stars = ""
let score = ""
2017-11-14 07:22:07 +00:00
if ( s . package . description ) {
2017-12-02 02:48:58 +00:00
desc = escape ( s . package . description )
2017-11-14 07:22:07 +00:00
}
2017-12-02 02:48:58 +00:00
if ( s . score ) {
2017-11-14 07:22:07 +00:00
if ( s . score . final ) {
2017-12-02 02:48:58 +00:00
score = Math . round ( Number ( s . score . final ) * 5 )
stars = "★" . repeat ( score ) + "☆" . repeat ( 5 - score )
2017-11-14 07:22:07 +00:00
}
}
if ( s . flags ) {
2017-12-02 02:48:58 +00:00
Object . keys ( s . flags ) . forEach ( ( f ) => {
flags += ` [<span style='color:#ff4d00'>⚑</span> ${ escape ( f ) } ] `
} )
2017-11-14 07:22:07 +00:00
}
2017-12-02 02:48:58 +00:00
const li = $ ( "<li/>" ) . html ( `
2017-11-14 07:22:07 +00:00
< div >
< style >
. title > em {
font - weight : bold ;
2017-10-31 05:39:21 +00:00
}
2017-11-14 07:22:07 +00:00
< / s t y l e >
2017-12-02 02:48:58 +00:00
< div class = "title" > $ { s . highlight } < / d i v >
2017-11-14 07:22:07 +00:00
< div >
< span style = "font-size:2em;line-height:0.5em" > $ { stars } < / s p a n >
< span > $ { flags } < / s p a n >
< / d i v >
< div > $ { desc } < / d i v >
< / d i v >
2017-12-02 02:48:58 +00:00
` )
li . data ( "url" , s . package . links . npm )
return li
} )
}
2017-11-14 07:22:07 +00:00
2017-11-17 14:30:47 +00:00
// ****** Social Media & Entertainment ****** //
// Hacker News (YCombinator)
completions . hn = {
2017-12-02 02:48:58 +00:00
alias : "hn" ,
name : "hackernews" ,
search : "https://hn.algolia.com/?query=" ,
compl : "https://hn.algolia.com/api/v1/search?tags=(story,comment)&query=" ,
}
completions . hn . callback = ( response ) => {
const res = JSON . parse ( response . text ) . hits
Omnibar . listResults ( res , ( s ) => {
let title = ""
let prefix = ""
if ( s . points ) {
prefix += ` [↑ ${ s . points } ] `
}
if ( s . num _comments ) {
prefix += ` [↲ ${ s . num _comments } ] `
}
switch ( s . _tags [ 0 ] ) { // eslint-disable-line no-underscore-dangle
case "story" :
[ title ] = s . title
break
case "comment" :
title = s . comment _text
break
default :
title = s . objectID
}
return Omnibar . createURLItem ( {
title : prefix + title ,
url : ` https://news.ycombinator.com/item?id= ${ s . objectID } ` ,
} )
} )
}
2017-11-17 14:30:47 +00:00
// Reddit
2017-11-14 07:22:07 +00:00
completions . re = {
2017-12-02 02:48:58 +00:00
alias : "re" ,
name : "reddit" ,
search : "https://www.reddit.com/search?sort=relevance&t=all&q=" ,
compl : "https://api.reddit.com/search?syntax=plain&sort=relevance&limit=20&q=" ,
}
completions . re . callback = ( response ) => {
const res = JSON . parse ( response . text ) . data . children
Omnibar . listResults ( res , ( s ) => {
const d = s . data
2017-11-14 07:22:07 +00:00
return Omnibar . createURLItem ( {
2017-12-02 02:48:58 +00:00
title : ` [ ${ d . score } ] ${ d . title } ` ,
url : ` https://reddit.com ${ d . permalink } ` ,
} )
} )
}
2017-11-14 07:22:07 +00:00
2017-11-17 14:30:47 +00:00
// YouTube
2017-11-14 07:22:07 +00:00
completions . yt = {
2017-12-02 02:48:58 +00:00
alias : "yt" ,
name : "youtube" ,
search : "https://www.youtube.com/search?q=" ,
compl : ` https://www.googleapis.com/youtube/v3/search?maxResults=20&part=snippet&type=video,channel&key= ${ keys . google _yt } &safeSearch=none&q= ` ,
2017-11-17 14:30:47 +00:00
}
2017-12-02 02:48:58 +00:00
completions . yt . callback = ( response ) => {
const res = JSON . parse ( response . text ) . items
Omnibar . listResults ( res , ( s ) => {
switch ( s . id . kind ) {
case "youtube#channel" :
return Omnibar . createURLItem ( {
title : ` ${ s . snippet . channelTitle } : ${ s . snippet . description } ` ,
url : ` https://youtube.com/channel/ ${ s . id . channelId } ` ,
} )
case "youtube#video" :
return Omnibar . createURLItem ( {
title : ` ▶ ${ s . snippet . title } ` ,
url : ` https://youtu.be/ ${ s . id . videoId } ` ,
} )
default :
return ""
}
} )
2017-11-17 14:30:47 +00:00
}
2017-12-02 02:48:58 +00:00
if ( typeof module !== "undefined" && typeof module . exports !== "undefined" ) {
module . exports = completions
2017-10-31 05:39:21 +00:00
}
2017-11-14 07:22:07 +00:00