- mapkey
- vmapkey
- imapkey
- map
- unmap
- unmapAllExcept
- imap
- iunmap
- cmap
- vmap
- vunmap
- aceVimMap
- addVimMapKey
- addSearchAlias
- removeSearchAlias
- searchSelectedWith
- Clipboard.read
- Clipboard.write
- Hints.setNumeric
- Hints.setCharacters
- Hints.click
- Hints.create
- Hints.dispatchMouseClick
- Hints.style
- Normal.passThrough
- Normal.scroll
- Normal.feedkeys
- Normal.jumpVIMark
- Visual.style
- Front.showEditor
- Front.openOmnibar
- Front.registerInlineQuery
- getBrowserName
- Front.showBanner
- Front.showPopup
- getClickableElements
- tabOpenLink
- insertJS
- RUNTIME
Create a shortcut in normal mode to execute your own action.
keys
string the key sequence for the shortcut.annotation
string a help message to describe the action, which will displayed in help opened by?
.jscode
function a Javascript function to be bound. If the function needs an argument, next pressed key will be fed to the function.options
objectdomain
: regex, a Javascript regex pattern to identify the domains that this mapping works, for example,/github\.com/i
says that this mapping works only for github.com,repeatIgnore
: boolean, whether this action can be repeated by dot command. (optional, defaultnull
)
mapkey("<Space>", "pause/resume on youtube", function() {
var btn = document.querySelector("button.ytp-ad-overlay-close-button") || document.querySelector("button.ytp-ad-skip-button") || document.querySelector('ytd-watch-flexy button.ytp-play-button');
btn.click();
}, {domain: /youtube.com/i});
- See: mapkey
Create a shortcut in visual mode to execute your own action.
keys
string the key sequence for the shortcut.annotation
string a help message to describe the action, which will displayed in help opened by?
.jscode
function a Javascript function to be bound. If the function needs an argument, next pressed key will be fed to the function.options
objectdomain
: regex, a Javascript regex pattern to identify the domains that this mapping works, for example,/github\.com/i
says that this mapping works only for github.com,repeatIgnore
: boolean, whether this action can be repeated by dot command. (optional, defaultnull
)
- See: mapkey
Create a shortcut in insert mode to execute your own action.
keys
string the key sequence for the shortcut.annotation
string a help message to describe the action, which will displayed in help opened by?
.jscode
function a Javascript function to be bound. If the function needs an argument, next pressed key will be fed to the function.options
objectdomain
: regex, a Javascript regex pattern to identify the domains that this mapping works, for example,/github\.com/i
says that this mapping works only for github.com,repeatIgnore
: boolean, whether this action can be repeated by dot command. (optional, defaultnull
)
Map a key sequence to another in normal mode.
new_keystroke
string a key sequence to replaceold_keystroke
string a key sequence to be replaceddomain
regex a Javascript regex pattern to identify the domains that this mapping works. (optional, defaultnull
)new_annotation
string use it instead of the annotation from old_keystroke if provided. (optional, defaultnull
)
map(';d', '<Ctrl-Alt-d>');
Unmap a key sequence in normal mode.
keystroke
string a key sequence to be removed.domain
regex a Javascript regex pattern to identify the domains that this mapping will be removed. (optional, defaultnull
)
unmap("<<", /youtube.com/);
Unmap all keybindings except those specified.
keystrokes
array the keybindings you want to keep.domain
regex a Javascript regex pattern to identify the domains that this mapping will be removed. (optional, defaultnull
)
unmapAllExcept(['E','R','T'], /google.com|twitter.com/);
- See: map
Map a key sequence to another in insert mode.
new_keystroke
string a key sequence to replaceold_keystroke
string a key sequence to be replaceddomain
regex a Javascript regex pattern to identify the domains that this mapping works. (optional, defaultnull
)new_annotation
string use it instead of the annotation from old_keystroke if provided. (optional, defaultnull
)
- See: unmap
Unmap a key sequence in insert mode.
keystroke
string a key sequence to be removed.domain
regex a Javascript regex pattern to identify the domains that this mapping will be removed. (optional, defaultnull
)
- See: map
Map a key sequence to another in omnibar.
new_keystroke
string a key sequence to replaceold_keystroke
string a key sequence to be replaceddomain
regex a Javascript regex pattern to identify the domains that this mapping works. (optional, defaultnull
)new_annotation
string use it instead of the annotation from old_keystroke if provided. (optional, defaultnull
)
- See: map
Map a key sequence to another in visual mode.
new_keystroke
string a key sequence to replaceold_keystroke
string a key sequence to be replaceddomain
regex a Javascript regex pattern to identify the domains that this mapping works. (optional, defaultnull
)new_annotation
string use it instead of the annotation from old_keystroke if provided. (optional, defaultnull
)
- See: unmap
Unmap a key sequence in visual mode.
keystroke
string a key sequence to be removed.domain
regex a Javascript regex pattern to identify the domains that this mapping will be removed. (optional, defaultnull
)
Map the key sequence lhs
to rhs
for mode ctx
in ACE editor.
lhs
string a key sequence to replacerhs
string a key sequence to be replacedctx
string a mode such asinsert
,normal
.
aceVimMap('J', ':bn', 'normal');
Add map key in ACE editor.
objects
object multiple objects to define key map in ACE, see more from ace/keyboard/vim.js
addVimMapKey(
{
keys: 'n',
type: 'motion',
motion: 'moveByCharacters',
motionArgs: {
forward: false
}
},
{
keys: 'e',
type: 'motion',
motion: 'moveByLines',
motionArgs: {
forward: true,
linewise: true
}
}
);
Add a search engine alias into Omnibar.
alias
string the key to trigger this search engine, one or several chars, used as search alias, when you input the string and pressspace
in omnibar, the search engine will be triggered.prompt
string a caption to be placed in front of the omnibar.search_url
string the URL of the search enginesearch_leader_key
string<search_leader_key><alias>
in normal mode will search selected text with this search engine directly without opening the omnibar, for examplesd
. (optional, defaults
)suggestion_url
string the URL to fetch suggestions in omnibar when this search engine is triggered. (optional, defaultnull
)callback_to_parse_suggestion
function a function to parse the response fromsuggestion_url
and return a list of strings as suggestions. Receives two arguments:response
, the first argument, is an object containing a propertytext
which holds the text of the response; andrequest
, the second argument, is an object containing the propertiesquery
which is the text of the query andurl
which is the formatted URL for the request. (optional, defaultnull
)only_this_site_key
string<search_leader_key><only_this_site_key><alias>
in normal mode will search selected text within current site with this search engine directly without opening the omnibar, for examplesod
. (optional, defaulto
)options
objectfavicon_url
URL for favicon for this search engine (optional, defaultnull
)
addSearchAlias('d', 'duckduckgo', 'https://duckduckgo.com/?q=', 's', 'https://duckduckgo.com/ac/?q=', function(response) {
var res = JSON.parse(response.text);
return res.map(function(r){
return r.phrase;
});
});
Remove a search engine alias from Omnibar.
alias
string the alias of the search engine to be removed.search_leader_key
string<search_leader_key><alias>
in normal mode will search selected text with this search engine directly without opening the omnibar, for examplesd
. (optional, defaults
)only_this_site_key
string<search_leader_key><only_this_site_key><alias>
in normal mode will search selected text within current site with this search engine directly without opening the omnibar, for examplesod
. (optional, defaulto
)
removeSearchAlias('d');
Search selected with.
se
string a search engine's search URLonlyThisSite
boolean whether to search only within current site, need support from the provided search engine. (optional, defaultfalse
)interactive
boolean whether to search in interactive mode, in case that you need some small modification on the selected content. (optional, defaultfalse
)alias
string only used with interactive mode, in such case the url fromse
is ignored, SurfingKeys will construct search URL from the alias registered byaddSearchAlias
. (optional, default""
)
searchSelectedWith('https://translate.google.com/?hl=en#auto/en/');
Read from clipboard.
onReady
function a callback function to handle text read from clipboard.
Clipboard.read(function(response) {
console.log(response.data);
});
Write text to clipboard.
text
string the text to be written to clipboard.
Clipboard.write(window.location.href);
Use digits as hint label, with it set you could type text to filter links, this API is to replace original setting like Hints.numericHints = true;
.
Hints.setNumeric();
Set characters for generating hints, this API is to replace original setting like Hints.characters = "asdgqwertzxcvb";
.
characters
string the characters for generating hints.
Hints.setCharacters("asdgqwertzxcvb");
Click element or create hints for elements to click.
links
string or array of HTMLElement
, click on it if there is only one in the array orforce
parameter is true, otherwise hints will be generated for them. Iflinks
is a string, it will be used as css selector forgetClickableElements
.force
boolean force to click the first input element whether there are more than one elements inlinks
or not. (optional, defaultfalse
)
mapkey('zz', 'Hide replies', function() {
Hints.click(document.querySelectorAll("#less-replies:not([hidden])"), true);
});
- See: Hints.dispatchMouseClick
Create hints for elements to click.
cssSelector
string or array of HTMLElement
, iflinks
is a string, it will be used as css selector.onHintKey
function a callback function on hint keys pressed.attrs
objectactive
: whether to activate the new tab when a link is opened,tabbed
: whether to open a link in a new tab,multipleHits
: whether to stay in hints mode after one hint is triggered. (optional, defaultnull
)
mapkey('yA', '#7Copy a link URL to the clipboard', function() {
Hints.create('*[href]', function(element) {
Clipboard.write('[' + element.innerText + '](' + element.href + ')');
});
});
Returns boolean whether any hint is created for target elements.
- See: Hints.create
The default onHintKey
implementation.
element
HTMLElement the element for which the pressed hint is targeted.
mapkey('q', 'click on images', function() {
Hints.create("div.media_box img", Hints.dispatchMouseClick);
}, {domain: /weibo.com/i});
Set styles for hints.
css
string styles for hints.mode
string sub mode for hints, usetext
for hints mode to enter visual mode. (optional, defaultnull
)
Hints.style('border: solid 3px #552a48; color:#efe1eb; background: none; background-color: #552a48;');
Hints.style("div{border: solid 3px #707070; color:#efe1eb; background: none; background-color: #707070;} div.begin{color:red;}", "text");
Enter PassThrough mode.
timeout
number? how many seconds to linger in PassThrough mode, to ignore it will stay in PassThrough mode until an Escape key is pressed.
Scroll within current target.
type
string down | up | pageDown | fullPageDown | pageUp | fullPageUp | top | bottom | left | right | leftmost | rightmost | byRatio
Feed keys into Normal mode.
keys
string the keys to be fed into Normal mode.
Jump to a vim-like mark.
mark
string a vim-like mark.
Set styles for visual mode.
Visual.style('marks', 'background-color: #89a1e2;');
Visual.style('cursor', 'background-color: #9065b7;');
Launch the vim editor.
element
HTMLElement the target element which the vim editor is launched for, this parameter can also be a string, which will be used as default content in vim editor.onWrite
function a callback function to be executed on written back from vim editor.type
string the type for the vim editor, which can beurl
, if not provided, it will be tag name of the target element. (optional, defaultnull
)useNeovim
boolean the vim editor will be the embeded JS implementation, ifuseNeovim
is true, neovim will be used through natvie messaging. (optional, defaultfalse
)
mapkey(';U', '#4Edit current URL with vim editor, and reload', function() {
Front.showEditor(window.location.href, function(data) {
window.location.href = data;
}, 'url');
});
Open the omnibar.
args
objecttype
the sub type for the omnibar, which can beBookmarks
,AddBookmark
,History
,URLs
,RecentlyClosed
,TabURLs
,Tabs
,Windows
,VIMarks
,SearchEngine
,Commands
,OmniQuery
andUserURLs
.
mapkey('ou', '#8Open AWS services', function() {
var services = Array.from(top.document.querySelectorAll('#awsc-services-container li[data-service-href]')).map(function(li) {
return {
title: li.querySelector("span.service-label").textContent,
url: li.getAttribute('data-service-href')
};
});
if (services.length === 0) {
services = Array.from(top.document.querySelectorAll('div[data-testid="awsc-nav-service-list"] li[data-testid]>a')).map(function(a) {
return {
title: a.innerText,
url: a.href
};
});
}
Front.openOmnibar({type: "UserURLs", extra: services});
}, {domain: /console.amazonaws|console.aws.amazon.com/i});
- See: example.
Register an inline query.
args
objecturl
: string or function, the dictionary service url or a function to return the dictionary service url,parseResult
: function, a function to parse result from dictionary service and return a HTML string to render explanation,headers
: object[optional], in case your dictionary service needs authentication.
Get current browser name
Returns string "Chrome" | "Firefox" | "Safari"
Show message in banner.
msg
string the message to be displayed in banner.timeout
number milliseconds after which the banner will disappear. (optional, default1600
)
Front.showBanner(window.location.href);
Show message in popup.
msg
string the message to be displayed in popup.
Front.showPopup(window.location.href);
Get all clickable elements. SurfingKeys has its own logic to identify clickable elements, such as a HTMLAnchorElement
or elements with cursor as pointer. This function provides two parameters to identify those clickable elements that SurfingKeys failed to identify.
selectorString
string extra css selector of those clickable elements.pattern
regex a regular expression that matches text of the clickable elements.
var elms = getClickableElements("[rel=link]", /click this/);
Returns array array of clickable elements.
Open links in new tabs.
str
string links to be opened, the links should be split by\n
if there are more than one.simultaneousness
number how many tabs will be opened simultaneously, the rest will be queued and opened later whenever a tab is closed. (optional, default5
)
mapkey("<Space>", "pause/resume on youtube", function() {
var btn = document.querySelector("button.ytp-ad-overlay-close-button") || document.querySelector("button.ytp-ad-skip-button") || document.querySelector('ytd-watch-flexy button.ytp-play-button');
btn.click();
}, {domain: /youtube.com/i});
Insert javascript code into main world context.
code
(function | string) a javascript function to be executed in main world context, or an URL of js file.onload
function a callback function after requested code executed.
Call background action
with args
, the callback
will be executed with response from background.
action
string a background action to be called.args
object the parameters to be passed to the background action.callback
function a function to be executed with the result from the background action.
RUNTIME('getTabs', {queryInfo: {currentWindow: true}}, response => {
console.log(response);
});