Last active
October 25, 2023 23:36
-
-
Save john-walks-slow/dc1658dad8ee0acc057e668619a94992 to your computer and use it in GitHub Desktop.
surfingkeys_pref
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
const { | |
aceVimMap, | |
mapkey, | |
imap, | |
imapkey, | |
getClickableElements, | |
vmapkey, | |
map, | |
unmap, | |
cmap, | |
addSearchAlias, | |
removeSearchAlias, | |
tabOpenLink, | |
readText, | |
Clipboard, | |
Front, | |
Hints, | |
Visual, | |
RUNTIME | |
} = api; | |
Hints.characters = "asdfhjklweryuizxcvbn"; | |
settings.smoothScroll = true; | |
settings.hintShiftNonActive = true; | |
settings.focusFirstCandidate = false; | |
settings.omnibarSuggestion = true; | |
settings.tabsMRUOrder = true; | |
settings.cursorAtEndOfInput = true; | |
settings.stealFocusOnLoad = true; | |
settings.enableAutoFocus = true; | |
// settings.tabsThreshold = 5; | |
settings.scrollStepSize = 160; | |
settings.hintAlign = "left"; | |
settings.newTabPosition = "right"; | |
settings.modeAfterYank = "Normal"; | |
settings.nextLinkRegex = /(>>|\bnext\b|下一页|后一页|下页|后页|下一頁|後一頁|下頁|後頁)/i; | |
settings.prevLinkRegex = /(<<|\bprev(ious)?\b|上一页|前一页|上页|前页|上一頁|前一頁|上頁|前頁)/i; | |
settings.loginLinkRegex = /(\blog\b|\bsign\b|\bjoin\b|登录|注册|加入|登錄|註冊|加入)/i; | |
settings.optionalRegex = /(\b(confirm|okay|ok|understand|g(e|o)t\sit|accept|dismiss|close|continue|cancel|yes|no)\b|确认|关闭|忽略|取消|理解|知道|继续|確認|關閉|忽略|取消|理解|知道|繼續)/i; | |
function login() { | |
var loginLinks = getClickableElements("a, button", settings.loginLinkRegex); | |
loginLinks = filterOverlapElements(loginLinks); | |
if (loginLinks.length) { | |
clickOn(loginLinks); | |
return true; | |
} else { | |
return false; | |
} | |
} | |
function optionalAct() { | |
var optionalLinks = getClickableElements("a, button", settings.optionalRegex); | |
optionalLinks = filterOverlapElements(optionalLinks); | |
if (optionalLinks.length) { | |
clickOn(optionalLinks); | |
return true; | |
} else { | |
return false; | |
} | |
} | |
function newMap(newKey,oldKey){ | |
map(newKey,oldKey) | |
unmap(oldKey) | |
} | |
mapkey("!","Click first search result",()=>{document.querySelector("h3").click()}); | |
mapkey("|","Optional actions",optionalAct); | |
mapkey("\\","Log in or register",login); | |
map("I", "gi"); | |
unmap("x"); | |
// Tab history | |
newMap("ot","H"); | |
mapkey(";q", "cq"); | |
// map("<Ctrl-Z>", "F"); | |
// Open in new tab | |
newMap("F", "af"); | |
// Hover | |
newMap(";h", "<Ctrl-h>"); | |
unmap("<Ctrl-j>"); | |
// mapkey("ot", "#3Choose a tab", function() { | |
// Front.chooseTab(); | |
// }); | |
// Open in current tab | |
newMap("T", "go"); | |
// Open bookmark | |
newMap("ob", "b"); | |
mapkey("gt", "Choose a tab with omnibar", function() { | |
Front.openOmnibar({ type: "Tabs" }); | |
}); | |
mapkey("M", "#10Jump to vim-like mark m", function() { | |
Normal.jumpVIMark("m", false); | |
}); | |
map("<Ctrl-[>", "<Esc>"); | |
imap("<Ctrl-[>", "<Esc>"); | |
vmapkey("<Ctrl-[>", "<Esc>"); | |
cmap("<Ctrl-[>", "<Esc>"); | |
cmap("<Ctrl-j>", "<Ctrl-n>"); | |
cmap("<Ctrl-k>", "<Ctrl-p>"); | |
cmap("<Delete>", "<Ctrl-d>"); | |
cmap("<Ctrl-Delete>", "<Ctrl-D>"); | |
//unmap("<Ctrl-D>");unmap("<Ctrl-d>"); | |
imap("<Alt-B>","<Ctrl-f>"); | |
imap("<Alt-F>","<Ctrl-e>"); | |
// unmap("<Ctrl-f>"); | |
// unmap("<Ctrl-e>"); | |
// unmap("<Ctrl-u>"); | |
// unmap("<Alt-w>"); | |
// unmap("<Alt-d>"); | |
// unmap("<Ctrl-Alt-d>"); | |
vmapkey("<Ctrl-j>", "<Ctrl-d>"); | |
vmapkey("<Ctrl-k>", "<Ctrl-u>"); | |
addSearchAlias( | |
"S", | |
"Google Scholar", | |
"https://scholar.google.com.hk/scholar?hl=zh-CN&as_sdt=0%2C5&q=" | |
); | |
addSearchAlias( | |
"d", | |
"Google Drive", | |
"https://drive.google.com/drive/search?q=" | |
); | |
addSearchAlias( | |
"c", | |
"Web Cache", | |
"http://webcache.googleusercontent.com/search?q=cache:" | |
); | |
addSearchAlias("w", "Describing Words", "http://describingwords.io/for/"); | |
addSearchAlias( | |
"v", | |
"Google Drive Viewer", | |
"https://docs.google.com/viewer?url=" | |
); | |
api.Front.registerInlineQuery({ | |
url: function(q) { | |
return `http://dict.youdao.com/w/eng/${q}/#keyfrom=dict2.index`; | |
}, | |
parseResult: function(res) { | |
var parser = new DOMParser(); | |
var doc = parser.parseFromString(res.text, "text/html"); | |
var collinsResult = doc.querySelector("#collinsResult"); | |
var authTransToggle = doc.querySelector("#authTransToggle"); | |
var examplesToggle = doc.querySelector("#examplesToggle"); | |
if (collinsResult) { | |
collinsResult.querySelectorAll("div>span.collinsOrder").forEach(function(span) { | |
span.nextElementSibling.prepend(span); | |
}); | |
collinsResult.querySelectorAll("div.examples").forEach(function(div) { | |
div.innerHTML = div.innerHTML.replace(/<p/gi, "<span").replace(/<\/p>/gi, "</span>"); | |
}); | |
var exp = collinsResult.innerHTML; | |
return exp; | |
} else if (authTransToggle) { | |
authTransToggle.querySelector("div.via.ar").remove(); | |
return authTransToggle.innerHTML; | |
} else if (examplesToggle) { | |
return examplesToggle.innerHTML; | |
} | |
} | |
}); | |
const hintsCss = `div { font-size: 9pt; font-family: JetBrains Mono NL,SauceCodePro Nerd Font,Consolas,Menlo,monospace; border: 2px solid #ddd; color: #2c363c; background: initial; background-color: #eee; opacity: 1; box-shadow: 0px 2px 3px 0px #33333340; } div.begin { color: steelblue; }` | |
Hints.style(hintsCss); | |
Hints.style(hintsCss, "text"); | |
Visual.style('cursor', 'background-color: steelblue;z-index:99999999;'); | |
settings.theme = ` | |
.sk_theme { | |
color: #444444; | |
background: #fefefe; | |
transition: all, 200ms; | |
} | |
.sk_theme input { | |
color: #333333; | |
} | |
.sk_theme .separator { | |
display: none; | |
} | |
.sk_theme .omnibar_highlight { | |
color: steelblue; | |
text-shadow: none !important; | |
font-style: italic; | |
} | |
.sk_theme .omnibar_folder { | |
color: steelblue; | |
font-weight: 200; | |
} | |
.sk_theme .omnibar_timestamp { | |
color: green; | |
font-weight: 100; | |
} | |
#sk_omnibar { | |
box-shadow: 0 4px 7px #00000025; | |
border-radius: 6px; | |
background: #fefefe; | |
border: 2px solid #ccc; | |
padding: 5px; | |
width: 60%; | |
max-height: 80%; | |
left: 20%; | |
} | |
.sk_omnibar_middle #sk_omnibarSearchArea { | |
margin: 0.5rem 1rem; | |
border-bottom: 2px solid #eeeeee; | |
padding: 0.8rem; | |
} | |
.resultPage { | |
font-weight: 100; | |
} | |
#sk_omnibarSearchResult { | |
font-size: 15px ; | |
} | |
#sk_omnibarSearchResult li div.url { | |
font-weight: normal; | |
white-space: nowrap; | |
} | |
.sk_theme #sk_omnibarSearchResult>ul>li:nth-child(odd) { | |
background: transparent; | |
} | |
#sk_omnibarSearchResult>ul>li { | |
display: block; | |
max-height: 600px; | |
overflow-x: hidden; | |
overflow-y: auto; | |
transition: background 200ms, padding 800ms; | |
padding: 4px; | |
font-size: 13px; | |
} | |
.sk_theme #sk_omnibarSearchResult>ul>li.focused { | |
background: #cef; | |
padding: 4px 20px; | |
transition: background 200ms, padding 300ms; | |
} | |
#sk_omnibarSearchResult li.focused div.url { | |
white-space: nowrap; | |
} | |
#sk_find { | |
border-style: none; | |
outline: none; | |
color: #333333; | |
min-width: 200px; | |
padding: 4px; | |
font-size: 15px; | |
} | |
#sk_status { | |
position: fixed; | |
bottom: 20px; | |
right: -1px; | |
z-index: 2147483000; | |
padding: 8px; | |
border-radius: 4px 0px 0px 4px; | |
border: 1px solid #999; | |
box-shadow: 0 0.5px 2px #00000050; | |
font-size: 12px; | |
} | |
// [mode=text] div.begin { | |
// color: steelblue; | |
// } | |
#sk_status>span { | |
border-right:0 !important; | |
} | |
#sk_banner { | |
padding: 0.5rem; | |
font-size: 14px; | |
border-style: none; | |
background: #fefefe; | |
box-shadow: 0 2px 5px #00000050; | |
box-sizing: border-box; | |
height:2rem; | |
} | |
#sk_keystroke { | |
background: #fefefe; | |
padding: 5px; | |
font-size: 13px; | |
} | |
.sk_theme .annotation { | |
color: inherit; | |
} | |
@keyframes expandRichHints { | |
0% { | |
opacity: 0; | |
} | |
100% { | |
opacity: 1; | |
} | |
} | |
@keyframes collapseRichHints { | |
0% { | |
opacity: 1; | |
} | |
100% { | |
opacity: 0; | |
} | |
} | |
`; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment