Skip to content

Instantly share code, notes, and snippets.

@958
Last active October 16, 2025 06:54
Show Gist options
  • Select an option

  • Save 958/9f4d93e8308920478159566008c56f8b to your computer and use it in GitHub Desktop.

Select an option

Save 958/9f4d93e8308920478159566008c56f8b to your computer and use it in GitHub Desktop.
api.Hints.setCharacters('asdfgwertzxcvb');
settings.hintAlign = 'left';
settings.nextLinkRegex = /((?!first)(next|older|more|>|›|»|forward|→|次(のページ|へ))+)/i;
settings.prevLinkRegex = /((?!last)(prev(ious)?|newer|back|«|less|<|‹|←|前(のページ|へ))+)/i;
settings.focusAfterClosed = 'right';
settings.scrollStepSize = 70;
settings.smoothScroll = true;
[
'cp', ';cp', ';ap', ';s', 'spa', 'spb', 'spd', 'sps', 'spc', 'sd',
'gr', 'gr', 'gf', 'af', 'sfr', 'C', 'yc', 'yq', 'B', 'F', 'Q',
'<Ctrl-6>', 'S', 'D', 'W', 'cc', 'ys', 'yj', 'yd', 'yf', 'yp', 'yl',
'gs', 'g?', 'gxt', 'gxT', 'gx0', 'gx$', 'ZZ', 'ZR',
'ox', 'ob', 'ow', ';t', 'sw', 'sb', 'ss',
'sm', '<Ctrl-i>', 'I', '<Ctrl-Alt-d>', 'su', ';m', ';j', ';pp', ';q', ';dh', ';db',
'<Ctrl-h>'
].forEach(k => api.unmap(k));
[ 'gr', '<Ctrl-d>', '<Ctrl-u>' ].forEach(k => api.vunmap(k));
api.map('<Ctrl-[>', '<Esc>');
api.cmap('<Ctrl-[>', '<Esc>');
api.imap('<Ctrl-[>', '<Esc>');
api.vmap('<Ctrl-[>', '<Esc>');
api.mapkey('T', 'Choose a tab with omnibar', () =>
api.Front.openOmnibar({type: "Tabs"})
);
api.mapkey('f', '#1Open a link', () => api.Hints.create('', api.Hints.dispatchMouseClick));
api.mapkey('F', '#1Open a link in non-active new tab', () =>
api.Hints.create('', api.Hints.dispatchMouseClick, {tabbed: true, active: false}));
api.mapkey('ya', '#7Copy a link URL to the clipboard', () => api.Hints.create('*[href]', e => api.Clipboard.write(e.href)));
api.mapkey('yma', '#7Copy multiple link URLs to the clipboard', () => {
var linksToYank = [];
api.Hints.create('*[href]', (e) =>
linksToYank.push(e.href) && api.Clipboard.write(linksToYank.join('\n')),
{multipleHits: true});
});
api.mapkey('i', '#1Go to edit box', () => {
api.Hints.create("input:visible, textarea:visible, *[contenteditable=true], select:visible", e =>
(e.tagName === 'SELECT') ? api.Front.showEditor(e) : api.Hints.dispatchMouseClick(e));
});
api.mapkey(';b', 'Open a link URL with Hatena Bookmark', () =>
api.Hints.create('*[href]', e => tabOpenLink(`http://b.hatena.ne.jp/entry?url=${encodeURIComponent(e.href)}`)));
api.mapkey('<Ctrl-b>', 'Open a current URL with Hatena Bookmark', () =>
tabOpenLink(`http://b.hatena.ne.jp/entry?url=${encodeURIComponent(window.location.href)}`));
api.mapkey('^', '#4Go to last used tab', () => RUNTIME('goToLastTab'));
api.mapkey('H', '#4Go back in history', () => history.go(-1), {repeatIgnore: true});
api.mapkey('L', '#4Go forward in history', () => history.go(1), {repeatIgnore: true});
api.mapkey('gX', '#8Open recently closed URL', () => api.Front.openOmnibar({type: 'URLs', extra: 'getRecentlyClosed'}));
const setTranslateQuery = (lang) => {
const render = (res) => res[0].map(r => r[0]).join('');
api.Front.registerInlineQuery({
url: `https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=${lang}&dt=t&dt=bd&q=`,
parseResult: res => [ render(JSON.parse(res.text)) ],
});
};
setTranslateQuery('ja');
api.mapkey('J', '#8Open omnibar for word translation (to Ja)', () => {
api.Front.openOmniquery({ query: Visual.getWordUnderCursor(), style: 'opacity: 0.8;' });
});
api.mapkey('K', '#8Open omnibar for word translation (to En)', () => {
setTranslateQuery('en');
api.Front.openOmniquery({ query: Visual.getWordUnderCursor(), style: 'opacity: 0.8;' });
setTranslateQuery('ja');
});
api.mapkey("<Ctrl-'>", '#10Jump to vim-like mark', api.Normal.jumpVIMark);
api.mapkey("'", '#10Jump to vim-like mark in new tab.', (mark) => api.Normal.jumpVIMark(mark, true));
api.map('`', "'");
api.mapkey('yy', "#7Copy current page's URL", () => api.Clipboard.write(window.location.href));
api.mapkey('yt', "#7Copy current page's title", () => api.Clipboard.write(document.title));
api.mapkey(';e', 'Translate selected text with google', () =>
searchSelectedWith('https://translate.google.com/?hl=en#auto/en/', false, false, ''));
api.mapkey(';j', 'Translate selected text with google', () =>
searchSelectedWith('https://translate.google.com/?hl=en#auto/ja/', false, false, ''));
api.addSearchAlias('b', 'bing', 'http://global.bing.com/search?setmkt=en-us&setlang=en-us&q=', 's', 'http://api.bing.com/osjson.aspx?query=',
(res) => JSON.parse(res.text)[1]);
api.addSearchAlias('h', 'github', 'https://github.com/search?type=Code&utf8=%E2%9C%93&q=');
if (/feedly\.com/.test(window.location.hostname)) {
['j', 'k', 'y', 'v', 's', 'g', 'a', 'l', '?'].forEach(k => unmap(k));
mapkey('a', 'Open a current entry in new tab', () => {
const e = document.querySelector('div.entryHeader a');
if (e) {
RUNTIME("openLink", {
tab: { tabbed: true, active: false },
url: e.href
});
}
});
mapkey('l', 'Add a current entry to pocket', () => {
const e = document.querySelector('div.entryHeader a');
if (e) {
httpRequest(
{'url': `https://getpocket.com/edit?url=${encodeURIComponent(window.location.href)}`},
res => Front.showBanner('Success')
);
}
});
}
if (/(inbox|gmail)\.google.com/.test(window.location.hostname)) {
['j', 'k', 'e', '#', 'o', 'u', 'O', 'n', 'p', 't', 'i', 'r', 'f', 'z', '?'].forEach(k => unmap(k));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment