Last active
April 20, 2022 04:34
-
-
Save Stvad/02d3d40b08e9505c548e00bba05ccea0 to your computer and use it in GitHub Desktop.
Surfingkeys config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/brookhong/Surfingkeys/wiki/Migrate-your-settings-from-0.9.74-to-1.0 | |
const { | |
aceVimMap, | |
mapkey, | |
imap, | |
imapkey, | |
vmap, | |
getClickableElements, | |
vmapkey, | |
map, | |
unmap, | |
cmap, | |
addSearchAlias, | |
removeSearchAlias, | |
tabOpenLink, | |
readText, | |
Clipboard, | |
Front, | |
Hints, | |
Visual, | |
unmapAllExcept, | |
iunmap, | |
RUNTIME | |
} = api; | |
var command_map = {}; | |
function _parseAnnotation(ag) { | |
var annotations = ag.annotation.match(/#(\d+)(.*)/); | |
if (annotations !== null) { | |
ag.feature_group = parseInt(annotations[1]); | |
ag.annotation = annotations[2]; | |
} | |
return ag; | |
} | |
function command(cmd, annotation, jscode) { | |
var cmd_code = { | |
code: jscode | |
}; | |
var ag = _parseAnnotation({annotation: annotation, feature_group: 14}); | |
cmd_code.feature_group = ag.feature_group; | |
cmd_code.annotation = ag.annotation; | |
command_map[cmd] = cmd_code; | |
} | |
mapkey('<Ctrl-s>', 'Print all mappings to console', function () { | |
const feature_groups = [ | |
'Help', // 0 | |
'Mouse Click', // 1 | |
'Scroll Page / Element', // 2 | |
'Tabs', // 3 | |
'Page Navigation', // 4 | |
'Sessions', // 5 | |
'Search selected with', // 6 | |
'Clipboard', // 7 | |
'Omnibar', // 8 | |
'Visual Mode', // 9 | |
'vim-like marks', // 10 | |
'Settings', // 11 | |
'Chrome URLs', // 12 | |
'Proxy', // 13 | |
'Misc', // 14 | |
'Insert Mode', // 15 | |
]; | |
let keyMappings = [Normal.mappings, | |
Visual.mappings, | |
Insert.mappings | |
].map(getAnnotations).reduce(function (a, b) { | |
return a.concat(b); | |
}); | |
keyMappings = keyMappings.map(annotation => { | |
let category_name = feature_groups[annotation.feature_group]; | |
return { | |
category: category_name, | |
trigger: KeyboardUtils.decodeKeystroke(annotation.word) + ` (${category_name})`, | |
description: annotation.annotation | |
}; | |
}); | |
console.log(command_map); | |
let commands = Object.keys(command_map).map((commandName) => { | |
console.log("processing: " + commandName); | |
let cmd = command_map[commandName]; | |
let category_name = feature_groups[cmd.feature_group]; | |
return { | |
category: category_name, | |
trigger: `:${commandName} (${category_name})`, | |
description: cmd.annotation | |
} | |
}); | |
console.log(keyMappings.concat(commands)); | |
console.log(JSON.stringify(keyMappings.concat(commands))); | |
}); | |
//------------ | |
(function remapColemak() { | |
//Tab navigation (prev/next) | |
map('K', 'R'); | |
map('H', 'E'); | |
//Standard mode | |
// todo saving things into temp mapping should help with remapping https://github.com/brookhong/Surfingkeys/issues/351 | |
map('h', 'k'); | |
map('k', 'j'); | |
// map('j', 'h'); | |
mapkey('j', "Scroll left", () => { | |
Normal.scroll("left"); | |
}); | |
//visual mode | |
vmap('h', 'k'); | |
vmap('k', 'j'); | |
// vmap('j', 'h'); | |
// vmapkey('j', "Scroll left", () => { | |
// Normal.scroll("left"); | |
// }); | |
// vim editor | |
// Examples: | |
// https://github.com/kalbasit/shabka/commit/bf237a504ff7070b489d86ea352bac412dc84fe1 | |
// addVimMapKey( | |
// // up | |
// { | |
// keys: 'h', | |
// type: 'motion', | |
// motion: 'moveByLines', | |
// motionArgs: { | |
// forward: false, | |
// linewise: true | |
// } | |
// }, | |
// // down | |
// { | |
// keys: 'k', | |
// type: 'motion', | |
// motion: 'moveByLines', | |
// motionArgs: { | |
// forward: true, | |
// linewise: true | |
// } | |
// }) | |
})(); | |
(function updateSearchAliases() { | |
// //google to ss, stackoverflow to st | |
// map('ss', 'sg'); | |
// map('st', 'ss'); | |
addSearchAlias('s', 'google', 'https://www.google.com/search?q=', 's', 'https://www.google.com/complete/search?client=chrome-omni&gs_ri=chrome-ext&oit=1&cp=1&pgcl=7&q=', function (response) { | |
var res = JSON.parse(response.text); | |
return res[1]; | |
}); | |
addSearchAlias('t', 'stackoverflow', 'http://stackoverflow.com/search?q='); | |
addSearchAlias('i', 'Internal Search', 'https://is.amazon.com/search/all?q='); | |
})(); | |
//swap edit url things, as I seem to be wanting edit and reload more then other one | |
map('su', 'sU'); | |
// map('sU', 'su'); | |
mapkey('sU', '#4Edit current URL with vim editor, and open in new tab', function () { | |
Front.showEditor(window.location.href, function (data) { | |
tabOpenLink(data); | |
}, 'url'); | |
}); | |
// map('F', 'af'); //back to good ol' cVim days | |
// seems like F is independantly useful :p | |
// Hints.characters = 'asdfgqwertzxcvbyuiophjklnm'; //both hands | |
// Hints.characters = 'arstdqwfpgzxcvb'; //colemak left hand | |
// Hints.characters = 'arstdqwfpgzxcvbhneiojluykm'; | |
// colemak all with scroll keys removed | |
// Hints.setCharacters('arstdqwfpgzxcvbhneiojluykm') | |
Hints.setCharacters('arstdqwfpgzxcvbneiouym') | |
mapkey('ye', "#7Copy last part of page URL", function () { | |
let parts = window.location.pathname.split('/'); | |
let lastSegment = parts.pop() || parts.pop(); // to handle case with trailing '/' | |
Clipboard.write(lastSegment); | |
}); | |
// Clean out "select to trigger inline query" list. Very annoying | |
settings.mouseSelectToQuery = []; | |
// Disable emoji popup. I can see it being potentially useful, but most of the time it's annoying and I already have this via Alfred | |
iunmap(":"); | |
// https://twitter.com/VladyslavSitalo/status/1494865628762497033 | |
mapkey('sb', 'Backlink search', () => { | |
const query = `"${window.location.hostname}${window.location.pathname}"` | |
tabOpenLink(constructSearchURL("https://www.google.com/search?q=", encodeURIComponent(query))); | |
}); | |
mapkey('zh', 'Activate Hypothes.is', () => { | |
// inject bookmarklet with shortcut | |
window.hypothesisConfig = function() { | |
return { | |
showHighlights:true, | |
appType:'bookmarklet' | |
} | |
}; | |
var d=document,s=d.createElement('script');s.setAttribute('src','https://hypothes.is/embed.js') | |
d.body.appendChild(s) | |
}); | |
mapkey('yu', 'Copy link without query', () => { | |
const url = new URL(window.location.href) | |
url.search = "" | |
navigator.clipboard.writeText(url.href) | |
}); | |
//Roam stuff | |
settings.clickableSelector = "*.roam-block, *.rm-block-ref, *.rm-title-display, *.rm-caret, *.rm-block-ref, *.rm-paren"; | |
const simulateMouseEvent = function(element, eventNames, { x, y } = {}, shiftKey = false) { | |
if (typeof eventNames === 'string') eventNames = [eventNames]; | |
eventNames.forEach(eventName => { | |
element.dispatchEvent( | |
// synchronous | |
new MouseEvent(eventName, { | |
view: window, | |
bubbles: true, | |
cancelable: true, | |
clientX: x, | |
clientY: y, | |
button: 0, | |
shiftKey | |
}) | |
); | |
}); | |
}; | |
unmapAllExcept(['f', '/', 'C', '?', '<Ctrl-h>'], /roamresearch\.com/i); | |
mapkey('<Ctrl-f>', 'Roamclick', function () { | |
Hints.create("", function (element, event) { | |
simulateMouseEvent(element, ['mousedown', 'mouseup', 'click'], {x:0,y:0}, true); | |
}); | |
}, {domain: /roamresearch\.com/i}); |
@MD7GIT I presume you refer to part that makes hints show up for all elements in Roam? If so - yes, but you'd need to update selectors on line 165 to match Remnote elements
Yes I'm trying to use this on Remnote but I don't know how. I'm not a programmer. I saw your video on Youtube 👍
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i wonder if this would work also for Remnote