Last active
January 27, 2025 15:26
-
-
Save vogler/92c757db63c3bf86deaaa1803ecfb96e 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
// https://github.com/brookhong/Surfingkeys/wiki/Migrate-your-settings-from-0.9.74-to-1.0 | |
const { | |
aceVimMap, | |
mapkey, | |
imap, | |
imapkey, | |
getClickableElements, | |
vmapkey, | |
map, | |
iunmap, | |
unmap, | |
unmapAllExcept, | |
vunmap, | |
cmap, | |
addSearchAlias, | |
removeSearchAlias, | |
tabOpenLink, | |
readText, | |
Clipboard, | |
Front, | |
Hints, | |
Visual, | |
RUNTIME | |
} = api; | |
// for lots of site-specific examples see https://github.com/b0o/surfingkeys-conf | |
// // 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'); | |
// // an example to remove mapkey `Ctrl-i` | |
// unmap('<Ctrl-i>'); | |
// mapkey('zz', 'Choose a tab', function() { | |
// Front.chooseTab(); | |
// }, {domain: /github\.com/i}); | |
// mapkey('zz', 'Show usage', function() { | |
// Front.showUsage(); | |
// }, {domain: /google\.com/i}); | |
// dark theme | |
settings.theme = ` | |
.sk_theme { | |
font-family: Input Sans Condensed, Charcoal, sans-serif; | |
font-size: 10pt; | |
background: #24272e; | |
color: #abb2bf; | |
} | |
.sk_theme tbody { | |
color: #fff; | |
} | |
.sk_theme input { | |
color: #d0d0d0; | |
} | |
.sk_theme .url { | |
color: #61afef; | |
} | |
.sk_theme .annotation { | |
color: #56b6c2; | |
} | |
.sk_theme .omnibar_highlight { | |
color: #528bff; | |
} | |
.sk_theme .omnibar_timestamp { | |
color: #e5c07b; | |
} | |
.sk_theme .omnibar_visitcount { | |
color: #98c379; | |
} | |
.sk_theme #sk_omnibarSearchResult ul li:nth-child(odd) { | |
background: #303030; | |
} | |
.sk_theme #sk_omnibarSearchResult ul li.focused { | |
background: #3e4452; | |
} | |
#sk_status, #sk_find { | |
font-size: 20pt; | |
}`; | |
// settings | |
settings.smoothScroll = false; | |
// settings.omnibarPosition = 'top'; | |
settings.hintAlign = 'left'; | |
settings.newTabPosition = 'right'; // for on; ["left", "right", "first", "last", "default"]; cmd-t will open new tab in last position | |
settings.focusAfterClosed = 'left'; // for x; cmd-w will instead focus opener tab or tab on the right | |
settings.scrollStepSize = 100; // default is 70 | |
// disable Emoji completion after ': + two characters' https://github.com/brookhong/Surfingkeys#emoji-completion | |
iunmap(":"); | |
// shortcuts | |
// move tab left/right | |
map('<', '<<'); | |
map('>', '>>'); | |
// tab left/right | |
map('a', 'E'); // af: link in active tab, ab: bookmark to selected folder | |
map('s', 'R'); // search selected with *, edit url, markdown, show last action... | |
map('`', '<Ctrl-6>'); // RUNTIME("goToLastTab") | |
map('J', '<ArrowLeft>'); | |
map('K', '<ArrowRight>'); // tried on youtube, but still passes through... | |
// issues | |
// open mark in current tab: https://github.com/brookhong/Surfingkeys/issues/957#issuecomment-621938150 | |
mapkey('"', '#10Jump to vim-like mark in current tab', function(mark) { | |
RUNTIME('getSettings', { | |
key: "marks" | |
}, function(response) { | |
var markInfo = response.settings.marks[mark]; | |
if(markInfo) { | |
document.location.href = markInfo.url; | |
} else { | |
Front.showBanner(`No mark of: ${mark}`); | |
} | |
}); | |
}); | |
const markdownLink = (title, url) => { | |
const escapedTitle = title.replace(/[\[\]]/g, "\\$&").replace(/\\$/, ""); | |
return `[${escapedTitle}](${url})`; | |
} | |
mapkey('yM', '#7Copy page URL/title as Markdown link', function() { | |
Clipboard.write(markdownLink(document.title, window.location.href)); | |
}); | |
const getActiveTab = cb => RUNTIME('getTabs', { queryInfo: { active: true, currentWindow: true }, tabsThreshold: 999 }, (r) => r.tabs.length == 1 && cb(r.tabs[0])); | |
// chrome.tabs.query({ currentWindow: true}, console.log); // will output all tabs, but can't call query here (works in Console via 'Ext > Inspect pop-up') | |
// getTabs does some more stuff: https://github.com/brookhong/Surfingkeys/blob/c0b34133cef5f17ef4fda19cd161b1a5a75b88e2/src/background/start.js#L736 | |
// by default it will filter out the currently active tab; setting message.tabsThreshold high to avoid it: | |
const getTabs = cb => RUNTIME('getTabs', { queryInfo: { currentWindow: true }, tabsThreshold: 999 }, (r) => cb(r.tabs)); | |
const lastAccessed = tab => new Date(tab.lastAccessed).toLocaleString(); | |
const formatDuration = ms => new Date(ms).toISOString().substr(11, 8).replace(/^[0:]+/, ""); | |
mapkey('yw', '#7Copy window tabs URLs', function() { | |
getTabs(tabs => { | |
Clipboard.write(tabs.map(tab => tab.url).join('\n')) | |
}) | |
}); | |
mapkey('yW', '#7Copy window tabs Markdown links', function() { | |
getTabs(tabs => { | |
Clipboard.write(tabs.map(tab => markdownLink(tab.title, tab.url) + ` (${lastAccessed(tab)})`).join('\n')) | |
}) | |
}); | |
mapkey('F', '#14Show last accessed time and time since', () => { | |
getActiveTab(function (tab) { | |
const duration = formatDuration(Date.now() - new Date(tab.lastAccessed)); | |
Front.showBanner(`Last accessed: ${lastAccessed(tab)}\nTime since: ${duration}`); | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment