2018-08-09 21:37:14 +00:00
const { keys } = require ( "./conf.priv.js" )
2018-11-03 00:21:44 +00:00
const { escape , createSuggestionItem , createURLItem } = require ( "./util" )
2017-12-02 02:58:06 +00:00
2019-03-07 23:05:51 +00:00
const wpDefaultIcon = "data:image/svg+xml,%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22utf-8%22%3F%3E%0A%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2056%2056%22%20enable-background%3D%22new%200%200%2056%2056%22%3E%0A%20%20%20%20%3Cpath%20fill%3D%22%23eee%22%20d%3D%22M0%200h56v56h-56z%22%2F%3E%0A%20%20%20%20%3Cpath%20fill%3D%22%23999%22%20d%3D%22M36.4%2013.5h-18.6v24.9c0%201.4.9%202.3%202.3%202.3h18.7v-25c.1-1.4-1-2.2-2.4-2.2zm-6.2%203.5h5.1v6.4h-5.1v-6.4zm-8.8%200h6v1.8h-6v-1.8zm0%204.6h6v1.8h-6v-1.8zm0%2015.5v-1.8h13.8v1.8h-13.8zm13.8-4.5h-13.8v-1.8h13.8v1.8zm0-4.7h-13.8v-1.8h13.8v1.8z%22%2F%3E%0A%3C%2Fsvg%3E%0A"
const cbDefaultIcon = "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"
2018-11-03 00:21:44 +00:00
const completions = { }
2018-08-09 21:37:14 +00:00
2018-11-03 00:21:44 +00:00
// Helper functions for Google Custom Search Engine completions
const googleCxURL = ( alias ) => {
const key = ` google_cx_ ${ alias } `
return ` https://www.googleapis.com/customsearch/v1?key= ${ keys . google _cs } &cx= ${ keys [ key ] } &q= `
2018-08-09 21:37:14 +00:00
}
2018-11-03 00:21:44 +00:00
const googleCxPublicURL = ( alias ) => {
const key = ` google_cx_ ${ alias } `
return ` https://cse.google.com/cse/publicurl?cx= ${ keys [ key ] } &q= `
2017-12-02 02:48:58 +00:00
}
2018-11-03 00:21:44 +00:00
const googleCxCallback = ( response ) => {
2017-12-02 02:48:58 +00:00
const res = JSON . parse ( response . text ) . items
2019-09-11 11:51:27 +00:00
return res . map ( ( s ) => createSuggestionItem ( `
2017-12-02 02:48:58 +00:00
< 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 >
2018-08-09 21:37:14 +00:00
` , { url: s.link }))
2017-12-02 02:48:58 +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 = {
2019-03-10 17:20:49 +00:00
alias : "au" ,
name : "AUR" ,
favicon : "https://aur.archlinux.org/images/favicon.ico" ,
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=" ,
2017-12-02 02:48:58 +00:00
}
completions . au . callback = ( response ) => {
const res = JSON . parse ( response . text )
2019-09-11 11:51:27 +00:00
return res . map ( ( s ) => createURLItem ( s , ` https://aur.archlinux.org/packages/ ${ s } ` ) )
2017-12-02 02:48:58 +00:00
}
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
2019-09-11 11:51:27 +00:00
completions . aw . callback = ( response ) => 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" ,
2019-03-10 03:28:48 +00:00
domain : "bbs.archlinux.org" ,
2017-12-02 02:48:58 +00:00
search : googleCxPublicURL ( "af" ) ,
compl : googleCxURL ( "af" ) ,
callback : googleCxCallback ,
}
2017-11-17 14:30:47 +00:00
// ****** Technical Resources ****** //
2019-03-07 23:05:51 +00:00
// AlternativeTo
completions . at = {
alias : "at" ,
name : "alternativeTo" ,
search : "https://alternativeto.net/browse/search/?q=" ,
compl : ` https://zidpns2vb0-dsn.algolia.net/1/indexes/fullitems?x-algolia-application-id=ZIDPNS2VB0&x-algolia-api-key= ${ keys . alternativeTo } &attributesToRetrieve=Name,UrlName,TagLine,Description,Likes,HasIcon,IconId,IconExtension,InternalUrl&query= ` ,
}
completions . at . callback = ( response ) => {
const res = JSON . parse ( response . text )
return res . hits . map ( ( s ) => {
const name = escape ( s . Name )
let title = name
let prefix = ""
if ( s . _highlightResult ) { // eslint-disable-line no-underscore-dangle
if ( s . _highlightResult . Name ) { // eslint-disable-line no-underscore-dangle
title = s . _highlightResult . Name . value // eslint-disable-line no-underscore-dangle
}
}
if ( s . Likes ) {
prefix += ` [↑ ${ s . Likes } ] `
}
let tagline = ""
if ( s . TagLine ) {
tagline = escape ( s . TagLine )
}
const desc = s . Description ? ` <div class="title"> ${ escape ( s . Description ) } </div> ` : ""
let icUrl = wpDefaultIcon
if ( s . HasIcon ) {
const icBase = "https://d2.alternativeto.net/dist/icons/"
const icQuery = "?width=100&height=100&mode=crop&upscale=false"
const icName = s . UrlName
icUrl = encodeURI ( ` ${ icBase } ${ icName } _ ${ s . IconId } ${ s . IconExtension } ${ icQuery } ` )
}
return createSuggestionItem ( `
< div style = "padding:5px;display:grid;grid-template-columns:60px 1fr;grid-gap:15px" >
< img style = "width:60px" src = "${icUrl}" alt = "${escape(s.Name)}" >
< div >
< div class = "title" > < strong > $ { prefix } $ { title } < / s t r o n g > $ { t a g l i n e } < / d i v >
$ { desc }
< / d i v >
< / d i v >
2019-03-14 17:32:45 +00:00
` , { url: ` https : //${s.InternalUrl}` })
2019-03-07 23:05:51 +00:00
} )
}
2017-11-17 14:30:47 +00:00
// Chrome Webstore
completions . cs = {
2017-12-02 02:48:58 +00:00
alias : "cs" ,
name : "chromestore" ,
2019-03-10 03:28:48 +00:00
favicon : "https://www.google.com/images/icons/product/chrome_web_store-32.png" ,
2017-12-02 02:48:58 +00:00
search : "https://chrome.google.com/webstore/search/" ,
compl : googleCxURL ( "cs" ) ,
callback : googleCxCallback ,
}
2017-11-17 14:30:47 +00:00
2019-06-21 20:12:44 +00:00
2019-09-11 11:51:27 +00:00
const parseFirefoxAddonsRes = ( response ) => JSON . parse ( response . text ) . results . map ( ( s ) => {
2019-06-21 20:12:44 +00:00
let { name } = s
if ( typeof name === "object" ) {
if ( name [ navigator . language ] !== undefined ) {
name = name [ navigator . language ]
} else {
[ name ] = Object . values ( name )
}
}
name = escape ( name )
let prefix = ""
switch ( s . type ) {
case "extension" :
prefix += "🧩 "
break
case "statictheme" :
prefix += "🖌 "
break
default :
break
}
return createSuggestionItem ( `
< div style = "padding:5px;display:grid;grid-template-columns:2em 1fr;grid-gap:15px" >
< img style = "width:2em" src = "${s.icon_url}" alt = "${name}" >
< div >
< div class = "title" > < strong > $ { prefix } $ { name } < / s t r o n g > < / d i v >
< / d i v >
< / d i v >
` , { url: s.url })
} )
// Firefox Addons
completions . fa = {
alias : "fa" ,
name : "firefox-addons" ,
search : "https://addons.mozilla.org/en-US/firefox/search/?q=" ,
compl : "https://addons.mozilla.org/api/v4/addons/autocomplete/?q=" ,
2019-09-10 23:54:32 +00:00
callback : parseFirefoxAddonsRes ,
2019-06-21 20:12:44 +00:00
}
// Firefox Themes
completions . ft = {
alias : "ft" ,
name : "firefox-themes" ,
search : "https://addons.mozilla.org/en-US/firefox/search/?type=statictheme&q=" ,
compl : "https://addons.mozilla.org/api/v4/addons/autocomplete/?type=statictheme&q=" ,
2019-09-10 23:54:32 +00:00
callback : parseFirefoxAddonsRes ,
2019-06-21 20:12:44 +00:00
}
// Firefox Extensions
completions . fe = {
alias : "fe" ,
name : "firefox-extensions" ,
search : "https://addons.mozilla.org/en-US/firefox/search/?type=extension&q=" ,
compl : "https://addons.mozilla.org/api/v4/addons/autocomplete/?type=extension&q=" ,
2019-09-10 23:54:32 +00:00
callback : parseFirefoxAddonsRes ,
2019-06-21 20:12:44 +00:00
}
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
2019-09-11 11:51:27 +00:00
completions . ow . callback = ( response ) => 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=" ,
}
2019-09-11 11:51:27 +00:00
completions . so . callback = ( response ) => JSON . parse ( response . text ) . items . map ( ( s ) => createURLItem ( ` [ ${ s . score } ] ${ s . title } ` , s . link ) )
2017-11-17 14:30:47 +00:00
2020-04-26 04:01:38 +00:00
// StackExchange - all sites (No completion)
completions . se = {
alias : "se" ,
name : "stackexchange" ,
search : "https://stackexchange.com/search?q=" ,
}
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=" ,
}
2019-09-11 11:51:27 +00:00
completions . dh . callback = ( response ) => JSON . parse ( response . text ) . results . map ( ( s ) => {
2018-08-09 21:37:14 +00:00
let meta = ""
2018-11-09 01:46:22 +00:00
let repo = s . repo _name
2018-08-09 21:37:14 +00:00
meta += ` [★ ${ escape ( s . star _count ) } ] `
meta += ` [↓ ${ escape ( s . pull _count ) } ] `
if ( repo . indexOf ( "/" ) === - 1 ) {
repo = ` _/ ${ repo } `
}
return createSuggestionItem ( `
2017-11-17 14:30:47 +00:00
< div >
2018-11-09 01:46:22 +00:00
< div class = "title" > < strong > $ { escape ( repo ) } < / 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 >
2018-08-09 21:37:14 +00:00
` , { url: ` https : //hub.docker.com/r/${repo}` })
} )
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=" ,
}
2019-09-11 11:51:27 +00:00
completions . gh . callback = ( response ) => JSON . parse ( response . text ) . items . map ( ( s ) => {
2018-08-09 21:37:14 +00:00
let prefix = ""
if ( s . stargazers _count ) {
prefix += ` [★ ${ s . stargazers _count } ] `
}
return createURLItem ( prefix + s . full _name , 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=" ,
2018-11-21 11:05:41 +00:00
compl : "https://5jmgqstc3m.execute-api.us-west-1.amazonaws.com/v1/domainr?q=" ,
}
2019-09-11 11:51:27 +00:00
completions . do . callback = ( response ) => Object . entries ( JSON . parse ( response . text ) )
2018-11-21 11:05:41 +00:00
. map ( ( [ domain , data ] ) => {
let color = "inherit"
let symbol = "<strong>?</strong> "
switch ( data . summary ) {
case "inactive" :
color = "#23b000"
symbol = "✔ "
break
case "unknown" :
break
default :
color = "#ff4d00"
symbol = "✘ "
}
return createSuggestionItem (
` <div><div class="title" style="color: ${ color } "><strong> ${ symbol } ${ escape ( domain ) } </strong></div></div> ` ,
2020-04-26 04:02:29 +00:00
{ url : ` https://domainr.com/ ${ domain } ` } ,
2018-11-21 11:05:41 +00:00
)
} )
2017-11-17 14:30:47 +00:00
// Vim Wiki
2017-11-14 07:22:07 +00:00
completions . vw = {
2019-03-14 17:44:25 +00:00
alias : "vw" ,
name : "vimwiki" ,
favicon : "https://vignette.wikia.nocookie.net/vim/images/6/64/Favicon.ico" ,
search : "https://vim.fandom.com/wiki/Special:Search?query=" ,
compl : "https://vim.fandom.com/api.php?action=opensearch&format=json&formatversion=2&namespace=0&limit=10&suggest=true&search=" ,
2017-12-02 02:48:58 +00:00
}
2017-11-14 07:22:07 +00:00
2019-09-11 11:51:27 +00:00
completions . vw . callback = ( response ) => JSON . parse ( response . text ) [ 1 ]
. map ( ( r ) => createURLItem ( r , ` https://vim.fandom.com/wiki/ ${ r } ` ) )
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
2019-09-11 11:51:27 +00:00
completions . az . callback = ( response ) => JSON . parse ( response . text ) [ 1 ]
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" ,
2019-06-21 20:13:28 +00:00
search : "https://www.craigslist.org/search/sss?query=" ,
compl : "https://www.craigslist.org/suggest?v=12&type=search&cat=sss&area=1&term=" ,
2017-12-02 02:48:58 +00:00
}
2017-11-14 07:22:07 +00:00
2019-09-11 11:51:27 +00:00
completions . cl . callback = ( response ) => JSON . parse ( response . text )
2017-11-14 07:22:07 +00:00
2018-02-17 06:14:32 +00:00
// EBay
completions . eb = {
alias : "eb" ,
name : "ebay" ,
search : "https://www.ebay.com/sch/i.html?_nkw=" ,
compl : "https://autosug.ebay.com/autosug?callback=0&sId=0&kwd=" ,
}
2019-09-11 11:51:27 +00:00
completions . eb . callback = ( response ) => JSON . parse ( response . text ) . res . sug
2018-02-17 06:14:32 +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
} )
} )
2018-08-09 21:37:14 +00:00
return words
2017-12-02 02:48:58 +00:00
}
2017-11-17 14:30:47 +00:00
// ****** General References, Calculators & Utilities ****** //
2018-11-20 01:01:17 +00:00
const parseDatamuseRes = ( res , o = { } ) => {
2019-09-11 11:51:27 +00:00
const opts = {
2018-11-20 01:01:17 +00:00
maxDefs : - 1 ,
ellipsis : false ,
2019-09-11 11:51:27 +00:00
}
Object . assign ( opts , o )
2018-11-20 01:01:17 +00:00
return res . map ( ( r ) => {
const defs = [ ]
let defsHtml = ""
if ( ( opts . maxDefs <= - 1 || opts . maxDefs > 0 ) && r . defs && r . defs . length > 0 ) {
for ( const d of r . defs . slice ( 0 , opts . maxDefs <= - 1 ? undefined : opts . maxDefs ) ) {
const ds = d . split ( "\t" )
const partOfSpeech = ` ( ${ escape ( ds [ 0 ] ) } ) `
const def = escape ( ds [ 1 ] )
defs . push ( ` <span><em> ${ partOfSpeech } </em> ${ def } </span> ` )
}
if ( opts . ellipsis && r . defs . length > opts . maxDefs ) {
defs . push ( "<span><em>…</em></span>" )
}
defsHtml = ` <div> ${ defs . join ( "<br />" ) } </div> `
}
return createSuggestionItem ( `
< div >
< div class = "title" > < strong > $ { escape ( r . word ) } < / s t r o n g > < / d i v >
$ { defsHtml }
< / d i v >
` , { url: ` $ { opts . wordBaseURL } $ { r . word } ` })
} )
}
2017-11-17 14:30:47 +00:00
// 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*" ,
2018-11-20 01:01:17 +00:00
opts : {
maxDefs : 16 ,
ellipsis : true ,
wordBaseURL : "http://onelook.com/?w=" ,
} ,
2017-12-02 02:48:58 +00:00
}
completions . de . callback = ( response ) => {
const res = JSON . parse ( response . text )
2018-11-20 01:01:17 +00:00
return parseDatamuseRes ( res , completions . de . opts )
2017-12-02 02:48:58 +00:00
}
2017-11-17 14:30:47 +00:00
// Thesaurus
completions . th = {
2017-12-02 02:48:58 +00:00
alias : "th" ,
name : "thesaurus" ,
2018-08-09 21:37:14 +00:00
search : "https://www.onelook.com/thesaurus/?s=" ,
2017-12-02 02:48:58 +00:00
compl : "https://api.datamuse.com/words?md=d&ml=%s" ,
2018-11-20 01:01:17 +00:00
opts : {
maxDefs : 3 ,
ellipsis : true ,
wordBaseURL : "http://onelook.com/thesaurus/?s=" ,
} ,
2017-12-02 02:48:58 +00:00
}
completions . th . callback = ( response ) => {
const res = JSON . parse ( response . text )
2018-11-20 01:01:17 +00:00
return parseDatamuseRes ( res , completions . th . opts )
2017-12-02 02:48:58 +00:00
}
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=" ,
2018-08-09 21:37:14 +00:00
compl : "https://en.wikipedia.org/w/api.php?action=query&format=json&generator=prefixsearch&prop=info|pageprops%7Cpageimages%7Cdescription&redirects=&ppprop=displaytitle&piprop=thumbnail&pithumbsize=100&pilimit=6&inprop=url&gpssearch=" ,
2017-12-02 02:48:58 +00:00
}
2017-11-17 14:30:47 +00:00
2019-09-11 11:51:27 +00:00
completions . wp . callback = ( response ) => Object . values ( JSON . parse ( response . text ) . query . pages )
2018-08-09 21:37:14 +00:00
. map ( ( p ) => {
2019-03-07 23:05:51 +00:00
const img = p . thumbnail ? p . thumbnail . source : wpDefaultIcon
2018-11-03 00:21:44 +00:00
const desc = p . description ? p . description : ""
2018-08-09 21:37:14 +00:00
return createSuggestionItem (
`
< div style = "padding:5px;display:grid;grid-template-columns:60px 1fr;grid-gap:15px" >
< img style = "width:60px" src = "${img}" alt = "${p.title}" >
< div >
< div class = "title" > < strong > $ { p . title } < / s t r o n g > < / d i v >
2018-11-03 00:21:44 +00:00
< div class = "title" > $ { desc } < / d i v >
2018-08-09 21:37:14 +00:00
< / d i v >
< / d i v >
` ,
2020-04-26 04:02:29 +00:00
{ url : p . fullurl } ,
2018-08-09 21:37:14 +00:00
)
} )
2017-11-17 14:30:47 +00:00
2018-08-23 09:50:39 +00:00
// Wikipedia - Simple English version
completions . ws = {
alias : "ws" ,
name : "wikipedia-simple" ,
search : "https://simple.wikipedia.org/w/index.php?search=" ,
compl : "https://simple.wikipedia.org/w/api.php?action=query&format=json&generator=prefixsearch&prop=info|pageprops%7Cpageimages%7Cdescription&redirects=&ppprop=displaytitle&piprop=thumbnail&pithumbsize=100&pilimit=6&inprop=url&gpssearch=" ,
callback : completions . wp . callback ,
}
2017-11-17 14:30:47 +00:00
2019-03-07 23:05:51 +00:00
// Wiktionary
completions . wt = {
alias : "wt" ,
name : "wiktionary" ,
search : "https://en.wiktionary.org/w/index.php?search=" ,
compl : "https://en.wiktionary.org/w/api.php?action=query&format=json&generator=prefixsearch&gpssearch=" ,
}
2019-09-11 11:51:27 +00:00
completions . wt . callback = ( response ) => Object . values ( JSON . parse ( response . text ) . query . pages )
. map ( ( p ) => p . title )
2019-03-07 23:05:51 +00:00
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 ) {
2018-08-09 21:37:14 +00:00
return [ createSuggestionItem ( `
< div >
< 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 >
< /div>`, { url: "https:/ / www . wolframalpha . com / " } ) ]
2017-11-14 07:22:07 +00:00
}
if ( ! res . success ) {
2017-12-02 02:48:58 +00:00
if ( res . tips ) {
2018-08-09 21:37:14 +00:00
return [ createSuggestionItem ( `
< div >
< div class = "title" > < strong > No Results < / s t r o n g > < / d i v >
< div class = "title" > $ { escape ( res . tips . text ) } < / d i v >
< /div>`, { url: "https:/ / www . wolframalpha . com / " } ) ]
2017-12-02 02:48:58 +00:00
}
if ( res . didyoumeans ) {
2019-09-11 11:51:27 +00:00
return res . didyoumeans . map ( ( s ) => createSuggestionItem ( `
2018-08-09 21:37:14 +00:00
< div >
< div class = "title" > < strong > Did you mean ... ? < / s t r o n g > < / d i v >
< div class = "title" > $ { escape ( s . val ) } < / d i v >
< /div>`, { url: "https:/ / www . wolframalpha . com / " } ) )
2017-12-02 02:48:58 +00:00
}
2018-08-09 21:37:14 +00:00
return [ createSuggestionItem ( `
< div >
< div class = "title" > < strong > Error < / s t r o n g > < / d i v >
< div class = "title" > An unknown error occurred . < / d i v >
< /div>`, { url: "https:/ / www . wolframalpha . com / " } ) ]
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
2019-09-11 11:51:27 +00:00
return results . map ( ( r ) => createSuggestionItem ( `
2018-08-09 21:37:14 +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 > ` , { u r l : r . u r l } ) )
2017-12-02 02:48:58 +00:00
}
2017-11-14 07:22:07 +00:00
2017-11-17 14:30:47 +00:00
// ****** Business Utilities & References ****** //
2018-08-09 21:37:14 +00:00
const parseCrunchbase = ( response , parse ) => {
const res = JSON . parse ( response . text ) . data . items
if ( res . length === 0 ) {
return [ createSuggestionItem ( `
< div >
< div class = "title" > < strong > No Results < / s t r o n g > < / d i v >
< div class = "title" > Nothing matched your query < / d i v >
< /div>`, { url: "https:/ / www . crunchbase . com / " } ) ]
}
2019-09-11 11:51:27 +00:00
const objs = res . map ( ( obj ) => parse ( obj ) )
2018-08-09 21:37:14 +00:00
return objs . map ( ( p ) => {
const domain = p . domain ? ` | <a href="https:// ${ p . domain } " target="_blank"> ${ p . domain } </a> ` : ""
const location = p . loc ? ` located in <em> ${ p . loc } </em> ` : ""
return createSuggestionItem ( `
< div style = "padding:5px;display:grid;grid-template-columns:60px 1fr;grid-gap:15px" >
< img style = "width:60px" src = "${p.img}" alt = "${p.name}" >
< div style = "display:grid;grid-template-rows:1fr 1fr 0.8fr" >
< div class = "title" > < strong style = "font-size: 1.2em" > $ { p . name } < / s t r o n g > < / d i v >
< div class = "title" style = "font-size: 1.2em" > $ { p . desc } < / d i v >
< div class = "title" > < em > $ { p . role } < / e m > $ { l o c a t i o n } $ { d o m a i n } < / d i v >
< / d i v >
< / d i v > ` , { u r l : p . u r l } )
} )
}
2017-11-17 14:30:47 +00:00
// 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" ,
2018-08-09 21:37:14 +00:00
search : "https://www.crunchbase.com/textsearch?q=" ,
2017-12-02 02:48:58 +00:00
compl : ` https://api.crunchbase.com/v/3/odm_organizations?user_key= ${ keys . crunchbase } &query=%s ` ,
}
2019-09-11 11:51:27 +00:00
completions . co . callback = ( response ) => parseCrunchbase ( response , ( org ) => {
2018-08-09 21:37:14 +00:00
const r = org . properties
const p = {
name : escape ( r . name ) ,
domain : r . domain !== null ? escape ( r . domain ) . replace ( /\/$/ , "" ) : null ,
desc : escape ( r . short _description ) ,
role : escape ( r . primary _role ) ,
2019-03-07 23:05:51 +00:00
img : cbDefaultIcon ,
2018-08-09 21:37:14 +00:00
loc : "" ,
url : ` https://www.crunchbase.com/ ${ r . web _path } ` ,
}
2017-12-02 02:48:58 +00:00
2018-08-09 21:37:14 +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 ) : ""
2017-11-14 07:22:07 +00:00
2018-08-09 21:37:14 +00:00
if ( r . profile _image _url !== null ) {
const u = r . profile _image _url
const img = u . slice ( u . indexOf ( "t_api_images" ) + "t_api_images" . length + 1 )
p . img = ` https://res-4.cloudinary.com/crunchbase-production/image/upload/c_lpad,h_100,w_100,f_auto,b_white,q_auto:eco/ ${ img } `
}
2017-11-14 07:22:07 +00:00
2018-08-09 21:37:14 +00:00
return p
} )
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 ` ,
}
2019-09-11 11:51:27 +00:00
completions . cp . callback = ( response ) => parseCrunchbase ( response , ( person ) => {
2018-08-09 21:37:14 +00:00
const r = person . properties
const p = {
name : ` ${ escape ( r . first _name ) } ${ escape ( r . last _name ) } ` ,
desc : "" ,
2019-03-07 23:05:51 +00:00
img : cbDefaultIcon ,
2018-08-09 21:37:14 +00:00
role : "" ,
loc : "" ,
url : ` https://www.crunchbase.com/ ${ r . web _path } ` ,
}
2017-12-02 02:48:58 +00:00
2018-08-09 21:37:14 +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 . 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 ) : ""
if ( r . profile _image _url !== null ) {
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
2018-08-09 21:37:14 +00:00
return p
} )
2017-11-14 07:22:07 +00:00
2017-11-17 14:30:47 +00:00
// ****** Search Engines ****** //
// DuckDuckGo
2019-06-03 19:50:07 +00:00
completions . dd = {
alias : "dd" ,
2017-12-02 02:48:58 +00:00
name : "duckduckgo" ,
search : "https://duckduckgo.com/?q=" ,
compl : "https://duckduckgo.com/ac/?q=" ,
}
2019-09-11 11:51:27 +00:00
completions . dd . callback = ( response ) => JSON . parse ( response . text ) . map ( ( r ) => r . phrase )
2017-11-14 07:22:07 +00:00
2019-06-21 20:15:39 +00:00
// DuckDuckGo - I'm Feeling Lucky
completions . D = {
2019-09-10 23:54:32 +00:00
alias : "D" ,
name : "duckduckgo-lucky" ,
search : "https://duckduckgo.com/?q=\\" ,
compl : "https://duckduckgo.com/ac/?q=\\" ,
2019-06-21 20:15:39 +00:00
callback : completions . dd . callback ,
}
// DuckDuckGo Images
completions . di = {
2019-09-10 23:54:32 +00:00
alias : "di" ,
name : "duckduckgo-images" ,
search : "https://duckduckgo.com/?ia=images&iax=images&q=" ,
compl : "https://duckduckgo.com/ac/?ia=images&iax=images&q=" ,
2019-06-21 20:15:39 +00:00
callback : completions . dd . callback ,
}
// DuckDuckGo Videos
completions . dv = {
2019-09-10 23:54:32 +00:00
alias : "dv" ,
name : "duckduckgo-videos" ,
search : "https://duckduckgo.com/?ia=videos&iax=videos&q=" ,
compl : "https://duckduckgo.com/ac/?ia=videos&iax=videos&q=" ,
2019-06-21 20:15:39 +00:00
callback : completions . dd . callback ,
}
// DuckDuckGo News
completions . dn = {
2019-09-10 23:54:32 +00:00
alias : "dn" ,
name : "duckduckgo-news" ,
search : "https://duckduckgo.com/?iar=news&ia=news&q=" ,
compl : "https://duckduckgo.com/ac/?iar=news&ia=news&q=" ,
2019-06-21 20:15:39 +00:00
callback : completions . dd . callback ,
}
// DuckDuckGo Maps
completions . dm = {
2019-09-10 23:54:32 +00:00
alias : "dm" ,
name : "duckduckgo-maps" ,
search : "https://duckduckgo.com/?ia=maps&iax=maps&iaxm=places&q=" ,
compl : "https://duckduckgo.com/ac/?ia=maps&iax=maps&iaxm=places&q=" ,
2019-06-21 20:15:39 +00:00
callback : completions . dd . callback ,
}
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
2019-09-11 11:51:27 +00:00
completions . go . callback = ( response ) => JSON . parse ( response . text ) [ 1 ]
2017-11-14 07:22:07 +00:00
2018-01-04 02:23:08 +00:00
// Google Images
completions . gi = {
2019-09-10 23:54:32 +00:00
alias : "gi" ,
name : "google-images" ,
search : "https://www.google.com/search?tbm=isch&q=" ,
compl : "https://www.google.com/complete/search?client=chrome-omni&gs_ri=chrome-ext&oit=1&cp=1&pgcl=7&ds=i&q=" ,
2019-06-21 20:21:02 +00:00
callback : completions . go . callback ,
2018-01-04 02:23:08 +00:00
}
2017-11-17 14:30:47 +00:00
// Google - I'm Feeling Lucky
2019-06-21 20:19:28 +00:00
completions . G = {
2019-09-10 23:54:32 +00:00
alias : "G" ,
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=" ,
2019-06-21 20:21:02 +00:00
callback : completions . go . callback ,
2017-12-02 02:48:58 +00:00
}
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=" ,
2018-08-09 21:37:14 +00:00
compl : "https://hex.pm/api/packages?sort=downloads&hx&search=" ,
2017-12-02 02:48:58 +00:00
}
2019-09-11 11:51:27 +00:00
completions . hx . callback = ( response ) => JSON . parse ( response . text ) . map ( ( s ) => {
2018-08-09 21:37:14 +00:00
let dls = ""
let desc = ""
let liscs = ""
if ( s . downloads && s . downloads . all ) {
dls = ` [↓ ${ escape ( s . downloads . all ) } ] `
}
if ( s . meta ) {
if ( s . meta . description ) {
desc = escape ( s . meta . description )
2017-11-17 14:30:47 +00:00
}
2018-08-09 21:37:14 +00:00
if ( s . meta . licenses ) {
s . meta . licenses . forEach ( ( l ) => {
liscs += ` [© ${ escape ( l ) } ] `
} )
2017-11-14 07:22:07 +00:00
}
2018-08-09 21:37:14 +00:00
}
return createSuggestionItem ( `
< div >
< div class = "title" > $ { escape ( s . repository ) } / < strong > $ { escape ( s . name ) } < / s t r o n g > < / d i v >
< div > $ { dls } $ { liscs } < / d i v >
< div > $ { desc } < / d i v >
< / d i v >
` , { url: s.html_url })
} )
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=" ,
2018-08-09 21:37:14 +00:00
compl : "https://hex.pm/api/packages?sort=downloads&hd&search=" ,
2017-12-02 02:48:58 +00:00
}
2019-09-11 11:51:27 +00:00
completions . hd . callback = ( response ) => JSON . parse ( response . text ) . map ( ( s ) => {
2018-08-09 21:37:14 +00:00
let dls = ""
let desc = ""
if ( s . downloads && s . downloads . all ) {
dls = ` [↓ ${ escape ( s . downloads . all ) } ] `
}
if ( s . meta ) {
if ( s . meta . description ) {
desc = escape ( s . meta . description )
2017-11-17 14:30:47 +00:00
}
2018-08-09 21:37:14 +00:00
}
return createSuggestionItem ( `
2017-11-17 14:30:47 +00:00
< div >
2018-08-09 21:37:14 +00:00
< div class = "title" > $ { escape ( s . repository ) } / < strong > $ { escape ( s . name ) } < / s t r o n g > $ { d l s } < / d i v >
< div > < / d i v >
2017-11-17 14:30:47 +00:00
< div > $ { desc } < / d i v >
2017-11-14 07:22:07 +00:00
< / d i v >
2018-08-09 21:37:14 +00:00
` , { url: ` https : //hexdocs.pm/${encodeURIComponent(s.name)}` })
} )
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" ,
2018-08-09 21:37:14 +00:00
search : "https://hex.pm/packages?sort=downloads&ex&search=" ,
2017-12-02 02:48:58 +00:00
compl : googleCxURL ( "ex" ) ,
}
2017-11-14 07:22:07 +00:00
2019-09-11 11:51:27 +00:00
completions . ex . callback = ( response ) => JSON . parse ( response . text ) . items . map ( ( s ) => {
2018-08-09 21:37:14 +00:00
let hash = ""
2017-11-14 07:22:07 +00:00
2018-08-09 21:37:14 +00:00
const snippet = s . htmlSnippet
const openTag = "<b>"
const closeTag = "</b>"
const openArgs = "("
const closeArgs = ")"
2017-12-02 02:48:58 +00:00
2018-08-09 21:37:14 +00:00
let f1 = snippet . indexOf ( openTag )
if ( f1 === - 1 ) {
return null
}
const f2 = snippet . indexOf ( closeTag )
if ( f2 === - 1 ) {
return null
}
2017-12-02 02:48:58 +00:00
2018-08-09 21:37:14 +00:00
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
2018-08-09 21:37:14 +00:00
const a1 = snippetEnd . indexOf ( openArgs )
if ( a1 !== 0 ) {
return null
}
let a2 = snippetEnd . indexOf ( closeArgs )
if ( a2 === - 1 ) {
return null
}
2017-12-02 02:48:58 +00:00
2018-08-09 21:37:14 +00:00
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
2018-08-09 21:37:14 +00:00
const moduleName = escape ( s . title ) . split ( " – " ) [ 0 ]
2017-11-14 07:22:07 +00:00
2018-08-09 21:37:14 +00:00
let subtitle = ""
if ( hash ) {
subtitle = `
2017-11-14 07:22:07 +00:00
< 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 > `
2018-08-09 21:37:14 +00:00
}
return createSuggestionItem ( `
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 >
2018-08-09 21:37:14 +00:00
` , { url: ` $ { s . link } # $ { hash } ` })
2019-09-11 11:51:27 +00:00
} ) . filter ( ( s ) => s !== null )
2017-11-14 07:22:07 +00:00
2017-11-17 14:30:47 +00:00
// ****** Golang ****** //
2018-03-22 00:05:26 +00:00
// Golang Docs (Google CSE)
completions . gg = {
alias : "gg" ,
name : "golang" ,
2019-03-10 03:28:48 +00:00
domain : "golang.org" ,
2018-03-22 00:05:26 +00:00
search : googleCxPublicURL ( "gg" ) ,
compl : googleCxURL ( "gg" ) ,
callback : googleCxCallback ,
}
2017-11-17 14:30:47 +00:00
// 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=" ,
}
2019-09-11 11:51:27 +00:00
completions . gd . callback = ( response ) => JSON . parse ( response . text ) . results . map ( ( s ) => {
2018-08-09 21:37:14 +00:00
let prefix = ""
if ( s . import _count ) {
prefix += ` [↓ ${ s . import _count } ] `
}
if ( s . stars ) {
prefix += ` [★ ${ s . stars } ] `
}
return createURLItem ( prefix + s . path , ` https://godoc.org/ ${ s . path } ` )
} )
2017-11-14 07:22:07 +00:00
2017-11-18 08:11:51 +00:00
// Gowalker
completions . gw = {
2019-03-10 17:20:49 +00:00
alias : "gw" ,
name : "gowalker" ,
2019-03-10 03:28:48 +00:00
favicon : "https://gowalker.org/img/favicon.png" ,
2019-03-10 17:20:49 +00:00
search : "https://gowalker.org/search?auto_redirect=true&q=" ,
compl : "https://gowalker.org/search/json?q=" ,
2017-12-02 02:48:58 +00:00
}
2019-09-11 11:51:27 +00:00
completions . gw . callback = ( response ) => JSON . parse ( response . text ) . results . map ( ( s ) => {
2018-08-09 21:37:14 +00:00
const title = escape ( s . title )
const desc = escape ( s . description )
return createSuggestionItem ( `
< div >
< div class = "title" > < strong > $ { title } < / s t r o n g > < / d i v >
< div > $ { desc } < / d i v >
< / d i v >
` , { url: ` https : //golang.org/doc/${encodeURIComponent(s.url)}` })
} )
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 = {
2019-03-10 17:20:49 +00:00
alias : "gs" ,
name : "go-search" ,
2019-03-10 03:28:48 +00:00
favicon : "https://go-search.org/images/logo-16.png" ,
2019-03-10 17:20:49 +00:00
search : "http://go-search.org/search?q=" ,
compl : "http://go-search.org/api?action=search&q=" ,
2017-12-02 02:48:58 +00:00
}
2019-09-11 11:51:27 +00:00
completions . gs . callback = ( response ) => JSON . parse ( response . text ) . hits
. map ( ( r ) => r . package )
2018-08-09 21:37:14 +00:00
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 = {
2019-03-10 17:20:49 +00:00
alias : "ha" ,
name : "hackage" ,
2019-03-10 03:28:48 +00:00
favicon : "https://hackage.haskell.org/static/favicon.png" ,
2019-03-10 17:20:49 +00:00
search : "https://hackage.haskell.org/packages/search?terms=" ,
compl : "https://hackage.haskell.org/packages/search.json?terms=" ,
2017-12-02 02:48:58 +00:00
}
2019-09-11 11:51:27 +00:00
completions . ha . callback = ( response ) => JSON . parse ( response . text )
. map ( ( s ) => createURLItem ( s . name , ` 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 = {
2019-03-10 17:20:49 +00:00
alias : "ho" ,
name : "hoogle" ,
2019-03-10 03:28:48 +00:00
favicon : "https://www.haskell.org/img/favicon.ico" ,
2019-03-10 17:20:49 +00:00
search : ` https://www.haskell.org/hoogle/?hoogle= ${
2017-12-02 02:48:58 +00:00
encodeURIComponent ( "+platform +xmonad +xmonad-contrib " ) } ` , // This tells Hoogle to include these modules in the search - encodeURIComponent is only used for better readability
2019-03-10 17:20:49 +00:00
compl : ` https://www.haskell.org/hoogle/?mode=json&hoogle= ${
2017-12-02 02:48:58 +00:00
encodeURIComponent ( "+platform +xmonad +xmonad-contrib " ) } ` ,
}
2019-09-11 11:51:27 +00:00
completions . ho . callback = ( response ) => JSON . parse ( response . text ) . results
. map ( ( s ) => createURLItem ( s . self , 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 = {
2019-03-10 17:20:49 +00:00
alias : "hw" ,
name : "haskellwiki" ,
2019-03-10 03:28:48 +00:00
favicon : "https://www.haskell.org/img/favicon.ico" ,
2019-03-10 17:20:49 +00:00
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-12-02 02:48:58 +00:00
}
2017-11-14 07:22:07 +00:00
2019-09-11 11:51:27 +00:00
completions . hw . callback = ( response ) => 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 = {
2019-03-10 17:20:49 +00:00
alias : "hy" ,
name : "hayoo" ,
2019-03-10 03:28:48 +00:00
favicon : "https://www.haskell.org/img/favicon.ico" ,
2019-03-10 17:20:49 +00:00
search : "http://hayoo.fh-wedel.de/?query=" ,
compl : "http://hayoo.fh-wedel.de/json?query=" ,
2017-12-02 02:48:58 +00:00
}
2019-09-11 11:51:27 +00:00
completions . hy . callback = ( response ) => JSON . parse ( response . text ) . result
. map ( ( s ) => createURLItem ( ` [ ${ s . resultType } ] ${ s . resultName } ` , 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" ,
2019-03-10 03:28:48 +00:00
domain : "jquery.com" ,
2017-12-02 02:48:58 +00:00
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" ,
2019-03-10 03:28:48 +00:00
domain : "nodejs.org" ,
2017-12-02 02:48:58 +00:00
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 )
2018-08-09 21:37:14 +00:00
return res . documents . map ( ( s ) => {
2017-12-02 02:48:58 +00:00
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 )
2018-08-09 21:37:14 +00:00
return createSuggestionItem ( `
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 >
2020-01-22 09:14:54 +00:00
` , { url: ` https : //developer.mozilla.org/${s.slug}` })
2017-12-02 02:48:58 +00:00
} )
}
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 = {
2019-03-10 17:20:49 +00:00
alias : "np" ,
name : "npm" ,
2019-03-10 03:28:48 +00:00
favicon : "https://static.npmjs.com/da3ab40fb0861d15c83854c29f5f2962.png" ,
2019-03-10 17:20:49 +00:00
search : "https://www.npmjs.com/search?q=" ,
compl : "https://api.npms.io/v2/search/suggestions?size=20&q=" ,
2017-12-02 02:48:58 +00:00
}
2019-09-11 11:51:27 +00:00
completions . np . callback = ( response ) => JSON . parse ( response . text )
2018-08-09 21:37:14 +00:00
. map ( ( s ) => {
2017-12-02 02:48:58 +00:00
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
}
2018-08-09 21:37:14 +00:00
return createSuggestionItem ( `
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 >
2018-08-09 21:37:14 +00:00
` , { url: s.package.links.npm })
2017-12-02 02:48:58 +00:00
} )
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" ,
2019-03-10 03:28:48 +00:00
domain : "news.ycombinator.com" ,
2017-12-02 02:48:58 +00:00
search : "https://hn.algolia.com/?query=" ,
compl : "https://hn.algolia.com/api/v1/search?tags=(story,comment)&query=" ,
}
completions . hn . callback = ( response ) => {
2018-02-13 03:46:12 +00:00
const res = JSON . parse ( response . text )
2018-08-09 21:37:14 +00:00
return res . hits . map ( ( s ) => {
2017-12-02 02:48:58 +00:00
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" :
2018-02-13 03:47:09 +00:00
title = s . title // eslint-disable-line prefer-destructuring
2017-12-02 02:48:58 +00:00
break
case "comment" :
title = s . comment _text
break
default :
title = s . objectID
}
2018-02-13 03:46:12 +00:00
const re = new RegExp ( ` ( ${ res . query . split ( " " ) . join ( "|" ) } ) ` , "ig" )
title = title . replace ( re , "<strong>$&</strong>" )
2018-04-23 03:37:37 +00:00
const url = ` https://news.ycombinator.com/item?id= ${ s . objectID } `
2018-08-09 21:37:14 +00:00
return createSuggestionItem ( `
2018-02-13 03:46:12 +00:00
< div >
< div class = "title" > $ { prefix + title } < / d i v >
2018-04-23 03:37:37 +00:00
< div class = "url" > $ { url } < / d i v >
2018-02-13 03:46:12 +00:00
< / d i v >
2018-08-09 21:37:14 +00:00
` , { url })
2017-12-02 02:48:58 +00:00
} )
}
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=" ,
}
2019-09-11 11:51:27 +00:00
completions . re . callback = ( response ) => JSON . parse ( response . text ) . data . children
. map ( ( s ) => createURLItem ( ` [ ${ s . data . score } ] ${ s . data . title } ` , ` https://reddit.com ${ s . data . 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
}
2019-09-11 11:51:27 +00:00
completions . yt . callback = ( response ) => JSON . parse ( response . text ) . items
2018-08-09 21:37:14 +00:00
. map ( ( s ) => {
2017-12-02 02:48:58 +00:00
switch ( s . id . kind ) {
case "youtube#channel" :
2018-08-09 21:37:14 +00:00
return createURLItem (
` ${ s . snippet . channelTitle } : ${ s . snippet . description } ` ,
` https://youtube.com/channel/ ${ s . id . channelId } ` ,
)
2017-12-02 02:48:58 +00:00
case "youtube#video" :
2018-08-09 21:37:14 +00:00
return createURLItem (
` ▶ ${ s . snippet . title } ` ,
` https://youtu.be/ ${ s . id . videoId } ` ,
)
2017-12-02 02:48:58 +00:00
default :
2018-08-09 21:37:14 +00:00
return null
2017-12-02 02:48:58 +00:00
}
2019-09-11 11:51:27 +00:00
} ) . filter ( ( s ) => s !== null )
2017-11-14 07:22:07 +00:00
2018-08-09 21:37:14 +00:00
module . exports = completions