Last active
November 15, 2024 17:11
-
-
Save chroju/2118c2193fb9892d95b9686eb95189d2 to your computer and use it in GitHub Desktop.
surfingkeys
This file contains 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
// option | |
settings.smoothScroll = false; | |
settings.omnibarPosition = 'bottom'; | |
settings.hintAlign = 'left'; | |
settings.focusAfterClosed = 'left'; | |
settings.smartCase = false; | |
// chrome.storage.local.set({"noPdfViewer": 1}) | |
// https://github.com/brookhong/Surfingkeys/issues/2159 | |
// disable surfingkeys | |
// settings.blocklistPattern = /.*mail.google.com.*|.*read.readwise.io.*|.*app.shortwave.com.*|.*omnivore.app.*/i; | |
api.unmapAllExcept([], /^https:\/\/(mail|calendar|contacts|docs|drive|keep).google.com/); | |
// add search | |
settings.defaultSearchEngine = 'd'; | |
// map | |
api.iunmap(":"); | |
api.map('H', 'S'); | |
api.unmap('S'); | |
api.map('L', 'D'); | |
api.unmap('D'); | |
api.map('F', 'af'); | |
api.map('@', '<Alt-p>'); | |
api.map('<Ctrl-h>', '<<'); | |
api.map('<Ctrl-l>', '>>'); | |
api.map('#', 'gt'); | |
api.map('h', 'E'); | |
api.map('l', 'R'); | |
api.map('d', 'x'); | |
api.map('u', 'X'); | |
api.map('o', 'go'); | |
api.map('O', ';U'); | |
api.imap('<Ctrl-w>', '<Alt-w>'); | |
api.mapkey('b', 'Choose a tab with omnibar', function() { | |
api.Front.openOmnibar({type: "Tabs"}); | |
}); | |
// paste URL | |
api.mapkey('p', 'Open URL in clipboard', function () { | |
api.Clipboard.read((response) => { | |
const clipText = response.data; | |
var markInfo = { | |
scrollLeft: 0, | |
scrollTop: 0 | |
}; | |
markInfo.tab = { | |
tabbed: false, | |
active: false | |
}; | |
if (clipText.indexOf(".") != -1) { | |
markInfo.url = clipText; | |
} else { | |
markInfo.url = "https://duckduckgo.com/?q=" + encodeURIComponent(clipText); | |
} | |
api.RUNTIME("openLink", markInfo) | |
}); | |
}); | |
api.mapkey('P', 'Open URL in clipboard at new tab', function () { | |
api.Clipboard.read((response) => { | |
const clipText = response.data; | |
markInfo = { | |
scrollLeft: 0, | |
scrollTop: 0 | |
}; | |
markInfo.tab = { | |
tabbed: true, | |
active: true | |
}; | |
if (clipText.indexOf(".") != -1) { | |
markInfo.url = clipText; | |
} else { | |
markInfo.url = "https://duckduckgo.com/?q=" + encodeURIComponent(clipText); | |
} | |
api.RUNTIME("openLink", markInfo) | |
}); | |
}); | |
//// bookmarklets | |
// yank | |
api.mapkey(',u', 'Copy URL and title', function () { | |
let str = document.title + " " + location.href; | |
navigator.clipboard | |
.writeText(str) | |
.then(() => { | |
api.Front.showBanner('Copied: ' + str) | |
}) | |
.catch(() => { | |
api.Front.showBanner('Failed !') | |
}); | |
}); | |
api.mapkey(',s', 'Copy URL scrapbox style', function () { | |
let str = "[" + location.href + " " + document.title.replace(/[\\[\\]]/g, "\\\\$&").replace(/\\\\$/, "") + "]"; | |
navigator.clipboard | |
.writeText(str) | |
.then(() => { | |
api.Front.showBanner('Copied: ' + str) | |
}) | |
.catch(() => { | |
api.Front.showBanner('Failed !') | |
}); | |
}); | |
api.mapkey(',m', 'Copy URL markdown style', function () { | |
let str = "[" + document.title.replace(/[\[\]]/g, "\\$&").replace(/\\$/, "") + "](" + location.href + ")" | |
navigator.clipboard | |
.writeText(str) | |
.then(() => { | |
api.Front.showBanner('Copied: ' + str) | |
}) | |
.catch(() => { | |
api.Front.showBanner('Failed !') | |
}); | |
}); | |
api.mapkey(',e', 'Scrapbox to markdown', function () { | |
var m = function (b) { b = b.replace(/&/g, "&"); b = b.replace(/</g, "<"); b = b.replace(/>/g, ">"); b = b.replace(/"/g, """); return b = b.replace(/'/g, "'") }, n = function (b) { b = void 0 === b ? 0 : b; for (var a = "", g = 1; g < b; g++)a += " "; return a }, p = function (b) { | |
b = void 0 === b ? "" : b; var a = document.createElement("div"); a.innerHTML = b; b = a.querySelectorAll("strong"); for (var g = 0; g < b.length; g++) { | |
var d = b[g], e = +d.className.split("level-")[1], c = d.innerHTML; e = void 0 === e ? 1 : e; e = 6 - e; for (var f = "", h = 0; h < e; h++)f += "#"; d.innerHTML = | |
f + " " + c | |
} return a.innerHTML | |
}, q = function (b) { b = void 0 === b ? "" : b; var a = document.createElement("div"); a.innerHTML = b; b = a.querySelectorAll("a"); for (var g = 0; g < b.length; g++) { var d = b[g], e = d.innerText.trim(), c = d.href; if (c.startsWith("https://scrapbox.io/chroju")) continue; e = "[" + e + "](" + c + ")"; var f = d.querySelector("img"); null !== f && (e = "[![Image](" + f.src + ")](" + c + ")"); d.innerText = e } return a.innerText }, f = document.querySelector(".lines"), r = f.querySelector(".line-title .text").innerText; f = f.querySelectorAll(".line"); pageTexts = []; for (var l = 1; l < f.length; l++) { | |
for (var c = f[l].querySelector(".text").cloneNode(!0), | |
h = c.querySelectorAll("span.empty-char-index"), a = 0; a < h.length; a++) { var k = h[a]; k.innerText = "" } h = c.querySelectorAll("span.backquote"); for (a = 0; a < h.length; a++)k = h[a], k.innerText = "`"; a = c.innerHTML.replace(/<span>/g, ""); a = a.replace(/<span.+?>/g, "").replace(/<\/span>/g, ""); a = a.replace(/<br.+?>/g, ""); a = a.replace(/\n/gi, "").replace(/\t/gi, "").trim(); a = p(a); a = q(a); c = c.querySelector(".indent-mark"); null !== c && (k = +c.style.width.split("em")[0] / 1.5 * 2 - 1, a = n(k) + "- " + a); null === c && 0 < a.length && "#" !== a[0] && (a += "<br>"); pageTexts.push(a) | |
} (function (b, | |
a) { b = void 0 === b ? "Title" : b; a = void 0 === a ? [] : a; for (var c = "# " + b + "\n", d = 0; d < a.length; d++)c += "\n" + a[d]; a = window.open(); a.document.open(); a.document.write("<title>" + b + "</title>"); a.document.write("<pre>"); a.document.write(m(c)); a.document.write("</pre>"); a.document.close() })(r, pageTexts) | |
}); | |
api.mapkey(',j', 'Scrapbox journal template', function () { | |
// ページ作成日時を入れたタイトルにする 例:「おしごとログ 2017-09-11」 | |
var dt = new Date(); | |
var journal_title = dt.getFullYear() + dt.getMonth() + dt.getDate() + ' その'; | |
// ここがページ内容のテンプレート。1行目にタグをつけて、2行目は空、3行目は「ほにゃらら~」 | |
var lines = ['[journal] from [' + dt.getFullYear() + '-' + ("0" + (dt.getMonth() + 1)).slice(-2) + ']-XX to XXXX', '', '[**** 🚀 Outcome]', '', '', '[**** 📖 Inputs]', '[** 本]', '', '[** 技術記事]', '', '[** 技術以外の記事]', '', '', '[**** 📋 Clips]', '', '', '[**** 🔍 Observe & Orient]', '', '', '[**** ☕ Afterwords]']; | |
var body = encodeURIComponent(lines.join('\n')); | |
var markInfo = { | |
scrollLeft: 0, | |
scrollTop: 0 | |
}; | |
markInfo.tab = { | |
tabbed: false, | |
active: false | |
}; | |
markInfo.url = 'https://scrapbox.io/chroju/' + encodeURIComponent(journal_title.trim()) + '?body=' + body; | |
api.RUNTIME("openLink", markInfo); | |
} | |
); | |
// shorten Amazon URL | |
api.mapkey(',a', 'Update Amazon.co.jp URL to short', function () { | |
let asin = document.body.querySelector("input[name^='ASIN']").value; | |
location.href = 'https://amazon.co.jp/dp/' + asin; | |
}); | |
// open surfingkeys.js | |
api.mapkey(',<Space>', 'Open surfingkeys.js', function () { | |
var markInfo = { | |
url: 'https://gist.github.com/chroju/2118c2193fb9892d95b9686eb95189d2/edit', | |
scrollLeft: 0, | |
scrollTop: 0 | |
}; | |
markInfo.tab = { | |
tabbed: true, | |
active: true | |
}; | |
api.RUNTIME("openLink", markInfo); | |
}); | |
// save to booklog | |
api.mapkey(',k', 'Save Amazon.co.jp URL to booklog', function () { | |
var asin = document.body.querySelector("input[name^='ASIN']").value; | |
location.href = 'https://booklog.jp/item/1/' + asin; | |
}); | |
// bookmark to Scrapbox | |
api.mapkey(',b', 'Add current URL to Scrapbox', function () { | |
var project = 'chroju'; | |
var title = window.prompt(`Register to ${project}`, document.title); | |
if (!title) return; | |
var lines = ['', '[' + window.location.href + ' ' + document.title + ']']; | |
var quote = window.getSelection().toString(); | |
if (quote.trim()) lines = lines.concat(quote.split(/\n/g).map(function (line) { return '>' + line; })); | |
lines.push(''); | |
var body = encodeURIComponent(lines.join('\n')); | |
location.href = `https://scrapbox.io/${project}/` + encodeURIComponent(title.trim()) + '?body=' + body; | |
}); | |
// save to Readwise Reader | |
api.mapkey(',r', 'Add current URL to Readwise Reader', function() { | |
open('https://readwise.io/save?title='+encodeURIComponent(document.title)+'&url='+encodeURIComponent(location.href)) | |
}); | |
//// qmark | |
var overlayedGlobalMarks = { | |
'g': 'https://github.com/chroju', | |
'i': 'https://github.com/issues/assigned', | |
'k': 'https://booklog.jp/users/chroju', | |
'y': 'https://gyazo.com/latest', | |
'p': 'https://getpocket.com/a/queue/', | |
'm': 'https://app.mailbrew.com' | |
} | |
// qmarksで設定したURLを新しいタブで開く | |
api.mapkey('gn', '#10Jump to vim-like mark in new tab', function (mark) { | |
var priorityURLs = overlayedGlobalMarks[mark]; | |
if (priorityURLs === undefined) { | |
// fallback to Surfingkeys default jump | |
Normal.jumpVIMark(mark, true); | |
return; | |
} | |
if (typeof priorityURLs == typeof "") { | |
priorityURLs = [priorityURLs] | |
} | |
for (var url of priorityURLs) { | |
var markInfo = { | |
url: url, | |
scrollLeft: 0, | |
scrollTop: 0 | |
}; | |
markInfo.tab = { | |
tabbed: true, | |
active: true | |
}; | |
api.RUNTIME("openLink", markInfo); | |
} | |
}); | |
// qmarksで設定したURLを現在のタブで開く | |
api.mapkey('go', '#10Jump to vim-like mark in current tab', function (mark) { | |
var priorityURLs = overlayedGlobalMarks[mark]; | |
if (priorityURLs === undefined) { | |
// fallback to Surfingkeys default jump | |
Normal.jumpVIMark(mark, true); | |
return; | |
} | |
if (typeof priorityURLs == typeof "") { | |
priorityURLs = [priorityURLs] | |
} | |
for (var url of priorityURLs) { | |
var markInfo = { | |
url: url, | |
scrollLeft: 0, | |
scrollTop: 0 | |
}; | |
markInfo.tab = { | |
tabbed: false, | |
active: false | |
}; | |
api.RUNTIME("openLink", markInfo); | |
} | |
}); | |
// theme | |
settings.theme = ` | |
.sk_theme input { | |
font-family: "Fira Code"; | |
} | |
.sk_theme .url { | |
font-size: 10px; | |
} | |
#sk_omnibarSearchResult li div.url { | |
font-weight: normal; | |
} | |
.sk_theme .omnibar_timestamp { | |
font-size: 11px; | |
font-weight: bold; | |
} | |
.sk_theme .omnibar_visitcount { | |
font-size: 11px; | |
font-weight: bold; | |
} | |
body { | |
font-family: "Fira Code", Consolas, "Liberation Mono", Menlo, Courier, monospace; | |
font-size: 14px; | |
} | |
kbd { | |
font: 11px "Fira Code", Consolas, "Liberation Mono", Menlo, Courier, monospace; | |
} | |
#sk_omnibarSearchArea .prompt, #sk_omnibarSearchArea .resultPage { | |
font-size: 12px; | |
} | |
.sk_theme { | |
background: #282a36; | |
color: #f8f8f2; | |
} | |
.sk_theme tbody { | |
color: #ff5555; | |
} | |
.sk_theme input { | |
color: #ffb86c; | |
} | |
.sk_theme .url { | |
color: #6272a4; | |
} | |
.sk_theme #sk_omnibarSearchResult ul li:nth-child(odd) { | |
background: #303030; | |
} | |
.sk_theme .annotation { | |
color: #6272a4; | |
} | |
.sk_theme .focused { | |
background: #44475a !important; | |
} | |
.sk_theme kbd { | |
background: #f8f8f2; | |
color: #44475a; | |
} | |
.sk_theme .frame { | |
background: #8178DE9E; | |
} | |
.sk_theme .omnibar_highlight { | |
color: #8be9fd; | |
} | |
.sk_theme .omnibar_folder { | |
color: #ff79c6; | |
} | |
.sk_theme .omnibar_timestamp { | |
color: #bd93f9; | |
} | |
.sk_theme .omnibar_visitcount { | |
color: #f1fa8c; | |
} | |
.sk_theme .prompt, .sk_theme .resultPage { | |
color: #50fa7b; | |
} | |
.sk_theme .feature_name { | |
color: #ff5555; | |
} | |
.sk_omnibar_middle #sk_omnibarSearchArea { | |
border-bottom: 1px solid #282a36; | |
} | |
#sk_status { | |
border: 1px solid #282a36; | |
} | |
#sk_richKeystroke { | |
background: #282a36; | |
box-shadow: 0px 2px 10px rgba(40, 42, 54, 0.8); | |
} | |
#sk_richKeystroke kbd>.candidates { | |
color: #ff5555; | |
} | |
#sk_keystroke { | |
background-color: #282a36; | |
color: #f8f8f2; | |
} | |
kbd { | |
border: solid 1px #f8f8f2; | |
border-bottom-color: #f8f8f2; | |
box-shadow: inset 0 -1px 0 #f8f8f2; | |
} | |
#sk_frame { | |
border: 4px solid #ff5555; | |
background: #8178DE9E; | |
box-shadow: 0px 0px 10px #DA3C0DCC; | |
} | |
#sk_banner { | |
border: 1px solid #282a36; | |
background: rgb(68, 71, 90); | |
color: #f8f8f2 | |
} | |
div.sk_tabs_bg { | |
background: #f8f8f2; | |
} | |
div.sk_tab { | |
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#6272a4), color-stop(100%,#44475a)); | |
} | |
div.sk_tab_title { | |
color: #f8f8f2; | |
} | |
div.sk_tab_url { | |
color: #8be9fd; | |
} | |
div.sk_tab_hint { | |
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f1fa8c), color-stop(100%,#ffb86c)); | |
color: #282a36; | |
border: solid 1px #282a36; | |
} | |
#sk_bubble { | |
border: 1px solid #f8f8f2; | |
color: #282a36; | |
background-color: #f8f8f2; | |
} | |
#sk_bubble * { | |
color: #282a36 !important; | |
} | |
div.sk_arrow[dir=down]>div:nth-of-type(1) { | |
border-top: 12px solid #f8f8f2; | |
} | |
div.sk_arrow[dir=up]>div:nth-of-type(1) { | |
border-bottom: 12px solid #f8f8f2; | |
} | |
div.sk_arrow[dir=down]>div:nth-of-type(2) { | |
border-top: 10px solid #f8f8f2; | |
} | |
div.sk_arrow[dir=up]>div:nth-of-type(2) { | |
border-bottom: 10px solid #f8f8f2; | |
} | |
}` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment