Last active
October 2, 2023 06:30
-
-
Save jiahut/8bc60aa1071adce989d283748a902f71 to your computer and use it in GitHub Desktop.
surfingkeys settings
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
// vim: set syntax=typescript: | |
// an example to create a new mapping `ctrl-y` | |
// mapkey('<Ctrl-y>', 'Show me the money', function() { | |
// Front.showPopup('a well-known phrase uttered by characters in the 1996 film Jerry Maguire (Escape to close).'); | |
// }); | |
// an example to replace `T` with `gt`, click `Default mappings` to see how `T` works. | |
// map('gt', 'T'); | |
//reference | |
// https://github.com/b0o/surfingkeys-conf | |
// https://github.com/brookhong/Surfingkeys/wiki/Migrate-your-settings-from-0.9.74-to-1.0 | |
const { | |
aceVimMap, | |
mapkey, | |
imap, | |
imapkey, | |
getClickableElements, | |
vmapkey, | |
map, | |
unmap, | |
cmap, | |
addSearchAlias, | |
removeSearchAlias, | |
tabOpenLink, | |
readText, | |
Clipboard, | |
Front, | |
Hints, | |
Visual, | |
RUNTIME | |
} = api; | |
map('<Ctrl-d>','d') | |
map('<Ctrl-u>','u') | |
unmap('d') | |
unmap('u') | |
mapkey('g;', '#4Go to last used tab', function() { | |
RUNTIME("goToLastTab"); | |
}); | |
mapkey('[[', '#4Go to next tab', function() { | |
RUNTIME("nextTab"); | |
}); | |
mapkey(']]', '#4Go to previous tab', function() { | |
RUNTIME("previousTab"); | |
}); | |
map('H','S'); // history <- | |
unmap('S') | |
map('L','D'); // histroy -> | |
unmap('D') | |
map('J','B'); // tab <- | |
unmap('B') | |
map('K','F'); // tab -> | |
unmap('F') | |
mapkey('F', '#3Toggle fullscreen', ( ) => document.fullscreenElement ? document.exitFullscreen() : document.documentElement.requestFullscreen() ) | |
// unmap('t') | |
// mapkey('t', '#3Choose a tab', function() { | |
// // Front.chooseTab(); | |
// Front.openOmnibar({type: "Tabs"}); | |
// }); | |
// unmap('T') | |
// mapkey('T', '#8Open a URL', function() { | |
// Front.openOmnibar({type: "URLs", extra: "getAllSites"}); | |
// }); | |
// an example to remove mapkey `Ctrl-i` | |
// unmap('<Ctrl-i>'); | |
// set theme | |
settings.theme = ` | |
.sk_theme { | |
background: #100a14dd; | |
color: #4f97d7; | |
} | |
.sk_theme tbody { | |
color: #292d; | |
} | |
.sk_theme input { | |
color: #d9dce0; | |
} | |
.sk_theme .url { | |
color: #2d9574; | |
} | |
.sk_theme .annotation { | |
color: #a31db1; | |
} | |
.sk_theme .omnibar_highlight { | |
color: #333; | |
background: #ffff00aa; | |
} | |
.sk_theme #sk_omnibarSearchResult ul li:nth-child(odd) { | |
background: #5d4d7a55; | |
} | |
.sk_theme #sk_omnibarSearchResult ul li.focused { | |
background: #5d4d7aaa; | |
} | |
.sk_theme #sk_omnibarSearchResult .omnibar_folder { | |
color: #a31db1; | |
} | |
`; | |
// --- Site-specific mappings ---// | |
const siteleader = "," | |
function mapsitekey(domainRegex, key, desc, f, opts = {}) { | |
const o = Object.assign({}, { | |
leader: siteleader, | |
}, opts) | |
mapkey(`${o.leader}${key}`, desc, f, { domain: domainRegex }) | |
} | |
function mapsitekeys(d, maps, opts = {}) { | |
const domain = d.replace(".", "\\.") | |
const domainRegex = new RegExp(`^http(s)?://(([a-zA-Z0-9-_]+\\.)*)(${domain})(/.*)?`) | |
maps.forEach((map) => { | |
const [ | |
key, | |
desc, | |
f, | |
subOpts = {}, | |
] = map | |
mapsitekey(domainRegex, key, desc, f, Object.assign({}, opts, subOpts)) | |
}) | |
} | |
const ytFullscreen = () => document | |
.querySelector(".ytp-fullscreen-button.ytp-button") | |
.click() | |
const Hint = (selector, action = Hints.dispatchMouseClick) => () => Hints.create(selector, action) | |
const copyURLPath = (count, domain) => () => Clipboard.write(getURLPath(count, domain)) | |
const ghStar = toggle => () => { | |
const repo = window.location.pathname.slice(1).split("/").slice(0, 2).join("/") | |
const container = document.querySelector("div.starring-container") | |
const status = container.classList.contains("on") | |
let star = "★" | |
let statusMsg = "starred" | |
let verb = "is" | |
if ((status && toggle) || (!status && !toggle)) { | |
statusMsg = `un${statusMsg}` | |
star = "☆" | |
} | |
if (toggle) { | |
verb = "has been" | |
if (status) { | |
container.querySelector(".starred button").click() | |
} else { | |
container.querySelector(".unstarred button").click() | |
} | |
} | |
} | |
mapsitekeys("github.com", [ | |
["s", "Toggle Star", ghStar(true)], | |
["S", "Check Star", ghStar(false)], | |
["y", "Copy Project Path", copyURLPath(2)], | |
["Y", "Copy Project Path (including domain)", copyURLPath(2, true)], | |
]) | |
mapsitekeys("gitlab.com", [ | |
["y", "Copy Project Path", copyURLPath(2)], | |
["Y", "Copy Project Path (including domain)", copyURLPath(2, true)], | |
]) | |
mapsitekeys("youtube.com", [ | |
["A", "Open video", Hint("*[id='video-title']")], | |
["C", "Open channel", Hint("*[id='byline']")], | |
["gH", "Goto homepage", () => window.location.assign("https://www.youtube.com/feed/subscriptions?flow=2")], | |
["F", "Toggle fullscreen", ytFullscreen], | |
["<Space>", "Play/pause", Hint(".ytp-play-button")], | |
], { leader: "" }) | |
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; | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment