Skip to content

Instantly share code, notes, and snippets.

@chroju chroju/surfingkeys.js
Last active Mar 18, 2020

Embed
What would you like to do?
surfingkeys
// option
settings.smoothScroll = false;
settings.omnibarPosition = 'bottom';
settings.hintAlign = 'left';
settings.focusAfterClosed = 'left';
settings.focusFirstCandidate = false;
// add search
addSearchAliasX('q', 'qwant', 'https://www.qwant.com/?r=JP&sr=ja&l=en_gb&h=0&s=1&a=1&b=0&vt=0&hc=1&smartNews=1&smartSocial=1&theme=1&i=1&donation=1&q=');
settings.defaultSearchEngine = 'q';
// map
iunmap(":");
map('H', 'S');
unmap('S');
map('L', 'D');
unmap('D');
map('F', 'af');
map('b', 'T');
map('@', '<Alt-p>');
map('<Ctrl-h>', '<<');
map('<Ctrl-l>', '>>');
map('#', 'gt');
map('h', 'E');
map('l', 'R');
map('d', 'x');
map('u', 'X');
map('o', 'go');
imap('<Ctrl-w>', '<Alt-w>');
// paste URL
mapkey('p', 'Open URL in clipboard', function() {
Clipboard.read(function(response) {
var markInfo = {
scrollLeft: 0,
scrollTop: 0
};
markInfo.tab = {
tabbed: false,
active: false
};
if (response.data.indexOf("http") != -1) {
markInfo.url = response.data;
} else {
markInfo.url = "https://www.qwant.com/?r=JP&sr=ja&l=en_gb&h=0&s=1&a=1&b=0&vt=0&hc=1&smartNews=1&smartSocial=1&theme=1&i=1&donation=1&q=" + encodeURIComponent(response.data);
}
RUNTIME("openLink", markInfo)
});
});
mapkey('P', 'Open URL in clipboard at new tab', function() {
Clipboard.read(function(response) {
var markInfo = {
scrollLeft: 0,
scrollTop: 0
};
markInfo.tab = {
tabbed: true,
active: true
};
if (response.data.indexOf("http") != -1) {
markInfo.url = response.data;
} else {
markInfo.url = "https://www.qwant.com/?q=" + encodeURIComponent(response.data);
}
RUNTIME("openLink", markInfo)
});
});
//// bookmarklets
// yank
mapkey(',u', 'Copy URL and title', function(){
void(prompt(document.title,document.title+" "+location.href))
});
mapkey(',s', 'Copy URL scrapbox style', function(){
void(prompt(document.title,"["+location.href+" "+document.title.replace(/[\[\]]/g,"\\$&").replace(/\\$/, "")+"]"))
});
mapkey(',m', 'Copy URL markdown style', function(){
void(prompt(document.title,"["+document.title.replace(/[\[\]]/g,"\\$&").replace(/\\$/, "")+"]("+location.href+")"))
});
// short Amazon URL
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;
});
// open surfingkeys.js
mapkey(',<Space><Space>', 'Open surfingkeys.js', function(){
var markInfo = {
url: 'https://gist.github.com/chroju/2118c2193fb9892d95b9686eb95189d2/edit',
scrollLeft: 0,
scrollTop: 0
};
markInfo.tab = {
tabbed: true,
active: true
};
RUNTIME("openLink", markInfo);
});
// save to booklog
mapkey(',k', 'Save Amazon.co.jp URL to booklog', function(){
var asin=document.body.querySelector("input[name^='ASIN']").value;
location.href='https://booklog.jp/item/1/'+asin;
});
// iframely
mapkey(',i', 'iframely', function(){
var encoded=encodeURIComponent(location.href);
location.href='https://iframely.com/embed/'+encoded;
});
// bookmark to Scrapbox
mapkey(',b', 'Add current URL to Scrapbox', function(){
var project='chroju';
var title=window.prompt(`Register to ${project}`,document.title);
if(!title)return;
var lines=['','['+window.location.href+' '+document.title+']'];
var quote=window.getSelection().toString();
if(quote.trim())lines=lines.concat(quote.split(/\n/g).map(function(line){return '>'+line;}));
lines.push('');
var body=encodeURIComponent(lines.join('\n'));
window.open(`https://scrapbox.io/${project}/`+encodeURIComponent(title.trim())+'?body='+body);
});
// save to pocket
mapkey(',p', 'Save to Pocket', function(){
var e=function(t,n,r,i,s){var o=[3543300,4719854,1693250,3297452,4141623,6003426,2443111,6029955,4490809,5536646];var i=i||0,u=0,n=n||[],r=r||0,s=s||0;var a={'a':97,'b':98,'c':99,'d':100,'e':101,'f':102,'g':103,'h':104,'i':105,'j':106,'k':107,'l':108,'m':109,'n':110,'o':111,'p':112,'q':113,'r':114,'s':115,'t':116,'u':117,'v':118,'w':119,'x':120,'y':121,'z':122,'A':65,'B':66,'C':67,'D':68,'E':69,'F':70,'G':71,'H':72,'I':73,'J':74,'K':75,'L':76,'M':77,'N':78,'O':79,'P':80,'Q':81,'R':82,'S':83,'T':84,'U':85,'V':86,'W':87,'X':88,'Y':89,'Z':90,'0':48,'1':49,'2':50,'3':51,'4':52,'5':53,'6':54,'7':55,'8':56,'9':57,'\/':47,':':58,'?':63,'=':61,'-':45,'_':95,'&':38,'$':36,'!':33,'.':46};if(!s||s==0){t=o[0]+t}for(var f=0;f<t.length;f++){var l=function(e,t){return a[e[t]]?a[e[t]]:e.charCodeAt(t)}(t,f);if(!l*1)l=3;var c=l*(o[i]+l*o[u%o.length]);n[r]=(n[r]?n[r]+c:c)+s+u;var p=c%(50*1);if(n[p]){var d=n[r];n[r]=n[p];n[p]=d}u+=c;r=r==50?0:r+1;i=i==o.length-1?0:i+1}if(s==117){var v='';for(var f=0;f<n.length;f++){v+=String.fromCharCode(n[f]%(25*1)+97)}o=function(){};return v+'6967e2ace7'}else{return e(u+'',n,r,i,s+1)}};var t=document,n=t.location.href,r=t.title;var i=e(n);var s=t.createElement('script');s.type='text/javascript';s.src='https://getpocket.com/b/r4.js?h='+i+'&u='+encodeURIComponent(n)+'&t='+encodeURIComponent(r);e=i=function(){};var o=t.getElementsByTagName('head')[0]||t.documentElement;o.appendChild(s)
});
//// qmark
var overlayedGlobalMarks = {
'g': 'https://github.com/chroju',
'p': 'https://getpocket.com/a/queue/'
}
// qmarksで設定したURLを新しいタブで開く
mapkey('gn', '#10Jump to vim-like mark 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
};
RUNTIME("openLink", markInfo);
}
});
// qmarksで設定したURLを現在のタブで開く
mapkey('go', '#10Jump to vim-like mark 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
};
RUNTIME("openLink", markInfo);
}
});
// theme
settings.theme = `
.sk_theme input {
font-family: "Fira Code";
}
.sk_theme .url {
font-size: 10px;
}
#sk_omnibarSearchResult li div.url {
font-weight: normal;
}
.sk_theme .omnibar_timestamp {
font-size: 11px;
font-weight: bold;
}
.sk_theme .omnibar_visitcount {
font-size: 11px;
font-weight: bold;
}
body {
font-family: "Fira Code", Consolas, "Liberation Mono", Menlo, Courier, monospace;
font-size: 14px;
}
kbd {
font: 11px "Fira Code", Consolas, "Liberation Mono", Menlo, Courier, monospace;
}
#sk_omnibarSearchArea .prompt, #sk_omnibarSearchArea .resultPage {
font-size: 12px;
}
.sk_theme {
background: #282a36;
color: #f8f8f2;
}
.sk_theme tbody {
color: #ff5555;
}
.sk_theme input {
color: #ffb86c;
}
.sk_theme .url {
color: #6272a4;
}
#sk_omnibarSearchResult>ul>li {
background: #282a36;
}
#sk_omnibarSearchResult>ul>li:nth-child(odd) {
background: #282a36;
}
.sk_theme .annotation {
color: #6272a4;
}
.sk_theme .focused {
background: #44475a !important;
}
.sk_theme kbd {
background: #f8f8f2;
color: #44475a;
}
.sk_theme .frame {
background: #8178DE9E;
}
.sk_theme .omnibar_highlight {
color: #8be9fd;
}
.sk_theme .omnibar_folder {
color: #ff79c6;
}
.sk_theme .omnibar_timestamp {
color: #bd93f9;
}
.sk_theme .omnibar_visitcount {
color: #f1fa8c;
}
.sk_theme #sk_omnibarSearchResult>ul>li:nth-child(odd) {
background: #282a36;
}
.sk_theme .prompt, .sk_theme .resultPage {
color: #50fa7b;
}
.sk_theme .feature_name {
color: #ff5555;
}
.sk_omnibar_middle #sk_omnibarSearchArea {
border-bottom: 1px solid #282a36;
}
#sk_status {
border: 1px solid #282a36;
}
#sk_richKeystroke {
background: #282a36;
box-shadow: 0px 2px 10px rgba(40, 42, 54, 0.8);
}
#sk_richKeystroke kbd>.candidates {
color: #ff5555;
}
#sk_keystroke {
background-color: #282a36;
color: #f8f8f2;
}
kbd {
border: solid 1px #f8f8f2;
border-bottom-color: #f8f8f2;
box-shadow: inset 0 -1px 0 #f8f8f2;
}
#sk_frame {
border: 4px solid #ff5555;
background: #8178DE9E;
box-shadow: 0px 0px 10px #DA3C0DCC;
}
#sk_banner {
border: 1px solid #282a36;
background: rgb(68, 71, 90);
}
div.sk_tabs_bg {
background: #f8f8f2;
}
div.sk_tab {
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#6272a4), color-stop(100%,#44475a));
}
div.sk_tab_title {
color: #f8f8f2;
}
div.sk_tab_url {
color: #8be9fd;
}
div.sk_tab_hint {
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f1fa8c), color-stop(100%,#ffb86c));
color: #282a36;
border: solid 1px #282a36;
}
#sk_bubble {
border: 1px solid #f8f8f2;
color: #282a36;
background-color: #f8f8f2;
}
#sk_bubble * {
color: #282a36 !important;
}
div.sk_arrow[dir=down]>div:nth-of-type(1) {
border-top: 12px solid #f8f8f2;
}
div.sk_arrow[dir=up]>div:nth-of-type(1) {
border-bottom: 12px solid #f8f8f2;
}
div.sk_arrow[dir=down]>div:nth-of-type(2) {
border-top: 10px solid #f8f8f2;
}
div.sk_arrow[dir=up]>div:nth-of-type(2) {
border-bottom: 10px solid #f8f8f2;
}
}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.