Skip to content

Instantly share code, notes, and snippets.

@ChJJin
Last active April 1, 2022 17:29
Show Gist options
  • Save ChJJin/1b356d6c871c05a1a3cabadd46c183a1 to your computer and use it in GitHub Desktop.
Save ChJJin/1b356d6c871c05a1a3cabadd46c183a1 to your computer and use it in GitHub Desktop.
Surfingkeys setting
// scroll setting
unmaps('u, e');
mapkey('u', '#2Scroll a page up', 'Normal.scroll("pageUp")', {repeatIgnore: true});
unmaps('E, R');
mapkey('J', '#3Go one tab left', 'RUNTIME("previousTab")');
mapkey('K', '#3Go one tab right', 'RUNTIME("nextTab")');
unmaps('B, F, S, D, H, L');
mapkey('H', '#4Go back in history', 'history.go(-1)');
mapkey('L', '#4Go forward in history', 'history.go(1)');
mapkey('B', '#4Open tab history in current tab', 'Normal.openOmnibar({type: "URLs", extra: "getTabURLs"})');
// set 'cl' to click on an Image or a button
unmap('q');
mapkey('cl', '#1Click on an Image or a button', 'Hints.create("img, button", Hints.dispatchMouseClick)');
// set 'F' to open a link in new tab
unmap('af');
mapkey('F', '#1Open a link in new tab, press SHIFT to flip hints', 'Hints.create("", Hints.dispatchMouseClick, {tabbed: true})');
// delete the proxy's and session's setting ( cause I don't need it. :) )
(function(){
var proxyReg = /(?:[pP]roxy|[sS]ession)/;
Object.keys(Commands.items).forEach(function(key){
if ( proxyReg.test(key) ) {
delete Commands.items[key];
}
});
delete Commands.items.quit;
unmaps('cp, spa, spb, spd, spi, spr, sps');
unmaps('ZZ, ZR, ZQ');
})();
// set clipboard setting
unmaps('cc, yd, yj, yl, ys, yt, ;p');
mapkey('yt', "#7Copy current page's title", 'Normal.writeClipboard(document.title)');
mapkey('p', '#7Open selected link or link from clipboard in current tab', function(){
if (window.getSelection().toString()) {
openLink(window.getSelection().toString(), false);
} else {
Normal.getContentFromClipboard(function(response) {
openLink(response.data, false);
});
}
});
mapkey('P', '#7Open selected link or link from clipboard in new tab', function(){
if (window.getSelection().toString()) {
openLink(window.getSelection().toString(), true);
} else {
Normal.getContentFromClipboard(function(response) {
openLink(response.data, true);
});
}
});
function openLink(urls, inNewTab) {
var urlReg = /^(?:https?:\/\/)?[\w-_]+(?:\.[\w-_]+)+.*/im,
pReg = /^[\w-]+?:\/\//i;
urls.trim().split('\n').slice(0, 5).forEach(function(url) {
url = url.trim();
if (url.length > 0) {
if (urlReg.test(url)) {
if (!pReg.test(url)) {
url = "http://" + url;
}
} else {
url = 'https://www.google.com/search?q=' + url;
}
RUNTIME("openLink", {
tab: {
tabbed: inNewTab
},
position: runtime.settings.newTabPosition,
url: url
});
}
});
}
// open tabs setting
unmaps('t, on, go, ox, oh, Q, b, ab, gf');
mapkey('t', '#3Open Chrome newtab', 'tabOpenLink("chrome://newtab/")');
mapkey('oo', '#3Open an URL in current tab', 'Normal.openOmnibar({type: "URLs", extra: "getTopSites", tabbed: false})');
mapkey('OO', '#3Open an URL in new tab', 'Normal.openOmnibar({type: "URLs", extra: "getTopSites", tabbed: true})');
mapkey('ox', '#8Open recently closed URL in current tab', 'Normal.openOmnibar({type: "URLs", extra: "getRecentlyClosed", tabbed: false})');
mapkey('oX', '#8Open recently closed URL in new tab', 'Normal.openOmnibar({type: "URLs", extra: "getRecentlyClosed", tabbed: true})');
mapkey('oh', '#8Open URL from history in current tab', 'Normal.openOmnibar({type: "History", tabbed: false})');
mapkey('oH', '#8Open URL from history in new tab', 'Normal.openOmnibar({type: "History", tabbed: true})');
// reset the search engines' setting
(function(){
// bing
unmapAlls('sw, sW, sow, soW, ow');
// baidu
unmapAlls('sb, sB, sob, soB, ob');
// useless interactively
unmapAlls('sG, soG, sS, sos, soS, sH, soh, soH');
// reset google tips
unmap('og');
mapkey('og', '#8Open Search in google', 'Normal.openOmnibar({type: "SearchEngine", extra: "g"})');
// mapkey('oh', '#8Open Search in github', 'Normal.openOmnibar({type: "SearchEngine", extra: "h"})');
// mdn
unmaps('sm, om');
addSearchAliasX('m', 'mdn', 'https://developer.mozilla.org/en-US/search?q=', 's');
unmapAlls('sM, som, soM');
mapkey('om', '#8Open Search in mdn', 'Normal.openOmnibar({type: "SearchEngine", extra: "m"})');
// zhihu
addSearchAliasX('z', 'zhihu', 'https://www.zhihu.com/search?type=content&q=', 's');
unmapAlls('sZ, soz, soZ');
mapkey('oz', '#8Open Search in zhihu', 'Normal.openOmnibar({type: "SearchEngine", extra: "z"})');
// iqiyi
addSearchAliasX('i', 'iqiyi', 'http://so.iqiyi.com/so/q_', 's');
unmapAlls('sI, soi, soI');
mapkey('oi', '#8Open Search in iqiyi', 'Normal.openOmnibar({type: "SearchEngine", extra: "i"})');
})();
unmaps('zi, zo, zr');
// set command
unmaps('ga, gb, gc, gd, ge, gh, gk, gs');
(function(){
var chromeCommands = {
e: 'extensions',
d: 'downloads',
b: 'bookmarks',
c: 'cache',
h: 'help',
k: 'settings/cookies'
}, tips = Object.keys(chromeCommands).map(function(key){
return key + ':' + chromeCommands[key];
}).join(' ');
command('c', 'chrome ' + tips, function(mode){
if (chromeCommands[mode]) {
tabOpenLink("chrome://" + chromeCommands[mode] + "/");
}
});
})();
function unmaps(keys) {
keys.split(/\s*,\s*/g).forEach(function(key){
unmap(key);
});
}
function unmapAlls(keys) {
keys.split(/\s*,\s*/g).forEach(function(key){
unmap(key);
Visual.mappings.remove(key);
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment