Skip to content

Instantly share code, notes, and snippets.

@nozma
Last active November 8, 2024 06:14
Show Gist options
  • Save nozma/c0bbbd3fa6a8c016e248ac8e3c09be1d to your computer and use it in GitHub Desktop.
Save nozma/c0bbbd3fa6a8c016e248ac8e3c09be1d to your computer and use it in GitHub Desktop.
settings for Surfingkeys
// --- setting ---
api.Hints.characters = 'asdfghjklnmvbrtyu';
settings.scrollStepSize = 150;
settings.nextLinkRegex = /((forward|>>|next|次[のへ]|→)+)/i;
settings.prevLinkRegex = /((back|<<|prev(ious)?|前[のへ]|←)+)/i;
settings.aceKeybindings = 'emacs';
settings.omnibarPosition = 'bottom';
settings.hintAlign = 'left';
// --- mapping ---
api.map('H', 'S'); // back in history
api.map('L', 'D'); // forward in history
api.map('h', 'E'); // previous tab
api.map('l', 'R'); // next tab
api.map('zz', 'zr'); // zoom reset
api.map('d', 'x'); // close current tab
api.map('u', 'X'); // restore tab
api.map('o', 'go'); // open a url in current tab
// Googleでgiコマンドの動作を修正する
if (window.location.hostname === 'www.google.com' || window.location.hostname === 'www.google.co.jp') {
api.map('gi', 'i');
}
// --- insert mode ---
api.imap('<Ctrl-[>', '<Esc>');
api.iunmap(':'); // disable emoji completion
api.iunmap('<Ctrl-f>');
api.iunmap('<Ctrl-u>');
api.iunmap('<Ctrl-i>');
// --- search ---
api.addSearchAlias('a', 'Amazon.co.jp', 'https://www.amazon.co.jp/s?k={0}&emi=AN1VRQENFRJN5');
// --- site ---
api.unmapAllExcept(
['h', 'l', 'd', 'u', 'r'],
/irodr.netlify.app/
);
api.unmapAllExcept(
['h', 'l', 'd', 'u', 'r', 't', 'o'],
/scrapbox.io/
);
// --- qmark ---
// cf. https://gist.github.com/chroju/2118c2193fb9892d95b9686eb95189d2
var overlayedGlobalMarks = {
// webservice
'l': 'https://irodr.netlify.app/',
'm': 'https://mail.google.com/mail/u/0/',
'M': 'https://moneyforward.com/',
't': 'https://twitter.com/',
'T': 'https://www.tumblr.com/dashboard',
'B': 'https://bookmeter.com/home',
'g': 'https://gist.github.com',
's': 'https://scrapbox.io/',
'w': 'https://healthmate.withings.com/',
'v': 'https://social.vivaldi.net/home',
'f': 'https://fedibird.com/web/timelines/home',
// personal
'c': 'https://gist.github.com/nozma/c0bbbd3fa6a8c016e248ac8e3c09be1d/edit',
'd': 'http://rion778.hatenablog.com/',
'G': 'https://github.com/nozma',
'q': 'https://www.tumblr.com/blog/nozma-books/new/quote',
'b': 'https://b.hatena.ne.jp/Rion778/bookmark'
};
// qmarksで設定したURLを新しいタブで開く
api.mapkey('gn', '#10Open Quickmark 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', '#10Open Quickmark 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);
}
});
// --- copy ---
// cf. https://github.com/hushin/dotfiles/blob/master/docs/SurfingkeysSetting.js
const copyTitleAndUrl = (format) => {
const text = format
.replace('%URL%', location.href)
.replace('%TITLE%', document.title);
api.Clipboard.write(text);
};
api.mapkey(',u', '#7Copy link', () => {
copyTitleAndUrl('%URL%');
});
api.mapkey(',m', '#7Copy title and link to markdown', () => {
copyTitleAndUrl('[%TITLE%](%URL%)');
});
api.mapkey(',c', '#7Copy title and link to textile', () => {
copyTitleAndUrl('"%TITLE%" - %URL%');
});
api.mapkey(',s', '#7Copy title and link to scrapbox', () => {
copyTitleAndUrl('[%TITLE% %URL%]');
});
api.mapkey(',C', '#7Cpoy title and link to Chatwork', () => {
copyTitleAndUrl('[info][title]%TITLE%[/title]%URL%[/info]');
});
// copy readable url
api.mapkey(',r', '#7Copy readable url', () => {
api.Clipboard.write(decodeURI(location.href));
});
// short Amazon URL
api.mapkey(',a', 'Update Amazon.co.jp URL to short', function(){
var asin=document.body.querySelector("input[name^='ASIN']").value;
location.href='https://amazon.co.jp/dp/'+asin;
});
// copy studyplus info
const copyStudyInfo = () => {
const materialName = document.querySelector('.timeline-event__study-record__material-title').innerText;
const studyTime = document.querySelector('.timeline-event__material__record').innerText;
const text = `${materialName} ${studyTime} ${location.href}`;
api.Clipboard.write(text);
};
api.mapkey(',p', '#7Cpoy Studyplus info', () => {
copyStudyInfo();
});
// --- theme ---
settings.theme = `
.sk_theme {
font-family: Input Sans Condensed, Charcoal, sans-serif;
background: #002B36;
color: #93A1A1;
}
.sk_theme input {
color: #93A1A1;
}
.sk_theme .url {
color: #268BD2;
}
.sk_theme .annotation {
color: #93A1A1;
}
.sk_theme kbd {
background: #EEE8D5;
color: #111;
}
.sk_theme .omnibar_highlight {
color: #CB4B16;
}
.sk_theme .omnibar_folder {
color: #2AA198;
}
.sk_theme .omnibar_timestamp {
color: #657B83;
}
.sk_theme .omnibar_visitcount {
color: #B58900;
}
.sk_theme .prompt, .sk_theme .resultPage {
color: #93A1A1;
}
.sk_theme .feature_name {
color: #859900;
}
.sk_theme .separator {
color: #859900;
}
.sk_theme #sk_omnibarSearchResult ul li:nth-child(odd) {
background: #002F3B;
}
.sk_theme #sk_omnibarSearchResult ul li.focused {
background: #083D4A;
}
#sk_status, #sk_find {
font-size: 12pt;
}
#sk_keystroke {
background: #002B36;
}
/* -- omnibar -- */
#sk_omnibar {
opacity: 0.9;
width: 100%;
left: 0;
}
.sk_theme #sk_omnibarSearchArea input,
.sk_theme #sk_omnibarSearchArea span {
font-size: 12px;
}
.expandRichHints span.annotation {
color: #93A1A1;
}`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment