Last active
June 6, 2019 03:09
-
-
Save dylan-conlin/fd94f1ce9a8bf229b36a1ebebc33a4fe to your computer and use it in GitHub Desktop.
surfingkeys config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
settings.blacklistPattern = undefined; | |
const unmapMultiple = (keyArray, url) => { keyArray.forEach(key => { unmap(key, url); }) }; | |
var ri = { repeatIgnore: true } | |
const open = (url) => () => tabOpenLink(url); | |
unmapMultiple(['N', 'P'] , /.*reddit-radio.dylanconlin.com.*/) | |
unmapMultiple(['N', 'P'] , /.*music.youtube.com.*/) | |
unmapMultiple(['j', 'k', '?', 'c', '/', 'z', 'n', 'p', 'e', 'y', 'r', '#', '!', 'H', 'L', 'b', 'I', ',', 'gi'] , /.*mail.google.com.*/) | |
unmapMultiple(['C', 'j', 'k', 'x', '?', 'G', '.'] , /.*reddit.com.*/) | |
unmapMultiple(['j', 'k', 'l', 'N', 'P'] , /.*youtube.com.*/) | |
unmapMultiple(['s'] , /.*github.com.*/) | |
// unmapMultiple(['j', 'k', 'u'] , /.*google.com\/search.*/) | |
// settings.smoothScroll = true; | |
settings.scrollStepSize = 100; | |
settings.hintAlign = "left"; | |
settings.omnibarMaxResults = 15; | |
settings.omnibarSuggestion = true; | |
settings.focusFirstCandidate = false; | |
settings.historyMUOrder = false; | |
// settings.newTabPosition = 'default' // 'left', 'right', 'first', 'last', 'default' | |
settings.newTabPosition = 'right' // 'left', 'right', 'first', 'last', 'default' | |
unmap('x'); | |
map('U', 'X'); | |
map('H', 'S'); | |
map('L', 'D'); | |
map('<Backspace>', 'H'); | |
map('M', '<Alt-m>') | |
cmap('<Ctrl-,>', '<Tab>'); | |
// // toggle surfingkeys | |
map('<Alt-s>', '<Alt-q>'); // hotkey must be one keystroke with/without modifier, it can not be a sequence of keystrokes like `gg`. | |
map('<', '<<'); | |
map('>', '>>'); | |
imap('<Ctrl-f>', '<ArrowRight>') | |
const s = 'https://github.com/pancakelabs/'; | |
mapkey("oud", "#14Open shortstack-designer on github", open(`${s}shortstack-designer`), ri) | |
mapkey("ous", "#14Open shortstack on github", open(`${s}shortstack`), ri) | |
mapkey("ou2", "#14Open shortstack2 on github", open(`${s}shortstack2`), ri) | |
mapkey("oua", "#14Open shortstack-api on github", open(`${s}shortstack-api`), ri) | |
mapkey("our", "#14Open shortstack-server on github", open(`${s}shortstack-server`), ri) | |
mapkey("ouy", "#14Open shortstack-style on github", open(`${s}shortstack-style`), ri) | |
mapkey("oue", "#14Open shortstack-emails on github", open(`${s}shortstack-emails`), ri) | |
mapkey("old", "#14Open local designer", open("https://design.shortstack.local/"), ri) | |
mapkey("ol2", "#14Open local shortstack2", open("https://app2.shortstack.local/manage#/campaigns"), ri) | |
mapkey("ols", "#14Open local shortstack", open("https://app.shortstack.local/member/working_tabs"), ri) | |
mapkey("opd", "#14Open production designer", open("https://designer.shortstackapp.com/"), ri) | |
mapkey("op2", "#14Open production shortstack2", open("https://app2.shortstackapp.com/manage#/campaigns"), ri) | |
mapkey("ops", "#14Open production shortstack", open("https://www.shortstackapp.com/member"), ri) | |
mapkey('oo', '#13toggle google year results', function() { | |
var currentUrl = window.location.href; | |
if (currentUrl.includes('tbs=qdr')) { | |
window.location.href = currentUrl.replace(/&?tbs=qdr.*y/, ''); | |
} else { | |
window.location.href = currentUrl + '&tbs=qdr:y' | |
} | |
}); | |
const hintsCss = ` | |
border: solid 1px hsla(229, 25%, 35%, 1); | |
color: black; | |
background: initial; | |
background-color: yellow; | |
padding: 4px 8px; | |
font-family: Segoe UI, Helvetica Neue, Helvetica, Arial, sans-serif !important; | |
` | |
Hints.style(hintsCss); | |
Hints.style(hintsCss, 'text'); | |
removeSearchAliasX('w'); | |
addSearchAliasX('w', 'Wikipedia', 'https://en.wikipedia.org/w/index.php?search=', 's', 'https://en.wikipedia.org/w/api.php?action=opensearch&format=json&search=', function(response) { | |
var res = JSON.parse(response.text); | |
Omnibar.listWords(res[1]); | |
}); | |
function escape(str) { | |
return String(str).replace(/[&<>"'`=/]/g, s => ({ | |
"&": "&", | |
"<": "<", | |
">": ">", | |
"\"": """, | |
"'": "'", | |
"/": "/", | |
"`": "`", | |
"=": "=", | |
}[s])) | |
} | |
function createSuggestionItem(html, props = {}) { | |
const li = document.createElement("li") | |
li.innerHTML = html | |
return { html: li.outerHTML, props } | |
} | |
function createURLItem(title, url, sanitize = true, img = null) { | |
let t = title | |
let u = url | |
if (sanitize) { | |
t = escape(t) | |
u = new URL(u).toString() | |
} | |
const imgEl = img && img.length > 0 ? `<img style="width:60px;float:left;padding-right:5px;" src="${img}">` : null; | |
return createSuggestionItem(` | |
${imgEl} | |
<div class="title">${t}</div> | |
<div class="url">${u}</div> | |
`, { url: u }) | |
} | |
const completions = {} | |
const keys = { | |
google_yt: 'AIzaSyC7WXxtGETz-AjA-x_mQwU3iReG7R1iARY', | |
wolframalpha: '9U994L-4KVV7VAPAX', | |
}; | |
// Google - I'm Feeling Lucky | |
completions.gl = { | |
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=", | |
} | |
completions.gl.callback = response => JSON.parse(response.text)[1] | |
// YouTube | |
completions.yt = { | |
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&key=${keys.google_yt}&safeSearch=none&q=`, | |
} | |
completions.yt.callback = response => { | |
return JSON.parse(response.text).items | |
.map((s) => { | |
switch (s.id.kind) { | |
case "youtube#channel": | |
return createURLItem( | |
`${s.snippet.channelTitle}: ${s.snippet.description}`, | |
`https://youtube.com/channel/${s.id.channelId}`, | |
true, | |
`${s.snippet.thumbnails.default.url}`, | |
) | |
case "youtube#video": | |
return createURLItem( | |
` ▶ ${s.snippet.title}`, | |
`https://youtu.be/${s.id.videoId}`, | |
true, | |
`${s.snippet.thumbnails.default.url}`, | |
) | |
default: | |
return null | |
} | |
}).filter(s => s !== null); | |
} | |
// GitHub | |
completions.gh = { | |
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 => JSON.parse(response.text).items.map((s) => { | |
let prefix = "" | |
if (s.stargazers_count) { | |
prefix += `[★${s.stargazers_count}] ` | |
} | |
return createURLItem(prefix + s.full_name, s.html_url) | |
}); | |
// StackOverflow | |
completions.so = { | |
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 => | |
JSON.parse(response.text).items.map(s => createURLItem(`[${s.score}] ${s.title}`, s.link)); | |
// Wikipedia | |
completions.wp = { | |
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&generator=prefixsearch&prop=info|pageprops%7Cpageimages%7Cdescription&redirects=&ppprop=displaytitle&piprop=thumbnail&pithumbsize=100&pilimit=6&inprop=url&gpssearch=", | |
} | |
const wpNoimg = "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" | |
completions.wp.callback = response => Object.values(JSON.parse(response.text).query.pages) | |
.map((p) => { | |
const img = p.thumbnail ? p.thumbnail.source : wpNoimg | |
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}</strong></div> | |
<div class="title">${p.description}</div> | |
</div> | |
</div> | |
`, | |
{ url: p.fullurl } | |
) | |
}); | |
// WolframAlpha | |
completions.wa = { | |
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`, | |
}; | |
completions.wa.callback = (response) => { | |
const res = JSON.parse(response.text).queryresult | |
if (res.error) { | |
return [createSuggestionItem(` | |
<div> | |
<div class="title"><strong>Error</strong> (Code ${escape(res.error.code)})</div> | |
<div class="title">${escape(res.error.msg)}</div> | |
</div>`, { url: "https://www.wolframalpha.com/" })] | |
} | |
if (!res.success) { | |
if (res.tips) { | |
return [createSuggestionItem(` | |
<div> | |
<div class="title"><strong>No Results</strong></div> | |
<div class="title">${escape(res.tips.text)}</div> | |
</div>`, { url: "https://www.wolframalpha.com/" })] | |
} | |
if (res.didyoumeans) { | |
return res.didyoumeans.map(s => createSuggestionItem(` | |
<div> | |
<div class="title"><strong>Did you mean...?</strong></div> | |
<div class="title">${escape(s.val)}</div> | |
</div>`, { url: "https://www.wolframalpha.com/" })) | |
} | |
return [createSuggestionItem(` | |
<div> | |
<div class="title"><strong>Error</strong></div> | |
<div class="title">An unknown error occurred.</div> | |
</div>`, { url: "https://www.wolframalpha.com/" })] | |
} | |
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) | |
} | |
}) | |
return results.map(r => createSuggestionItem(` | |
<div> | |
<div class="title"><strong>${r.title}</strong></div> | |
${r.values.join("\n")} | |
</div>`, { url: r.url })) | |
} | |
const sl = "a" | |
Object.keys(completions).forEach((k) => { | |
const s = completions[k] // Search Engine object | |
const la = sl + s.alias // Search leader + alias | |
addSearchAliasX(s.alias, s.name, s.search, sl, s.compl, s.callback) | |
mapkey(la, `#8Search ${s.name}`, () => Front.openOmnibar({ type: "SearchEngine", extra: s.alias })) | |
}); | |
settings.theme = ` | |
#sk_status, #sk_find { | |
font-size: 18pt; | |
} | |
}`; | |
// end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment