-
Notifications
You must be signed in to change notification settings - Fork 3
/
autovim.js
49 lines (42 loc) · 1.36 KB
/
autovim.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// ==UserScript==
// @name Bookmark Launcher
// @description Launches bookmakrs with keyboard shortcuts
// ==/UserScript==
function enable_vim() {
var turn_on = function (e) {
//console.log('Enable vimMode');
// If I receive focus again...
e.CodeMirror.on("focus", function(cm) {
console.log(cm);
e.CodeMirror.setOption("vimMode", true);
e.CodeMirror.options.keyMap = 'vim';
e.CodeMirror.options.showCursorWhenSelecting = 'vim';
});
// In case I already have focus...
setTimeout(function(){
e.CodeMirror.setOption("vimMode", true);
e.CodeMirror.options.keyMap = 'vim';
e.CodeMirror.options.showCursorWhenSelecting = 'vim';
},200);
}
document.querySelectorAll(".CodeMirror").forEach(function(e){ turn_on(e); });
}
CodeMirror.defineInitHook(enable_vim);
console.log('injected...');
setTimeout(enable_vim, 1000);
var bookmarkLauncherSetup = (function() {
var bookmarks = {}, url;
bookmarks['V'] = enable_vim;
window.addEventListener('keyup', function() {
console.log('pressed a key');
if(event.ctrlKey && event.altKey && !event.shiftKey)
if(exec = bookmarks[String.fromCharCode(event.keyCode)]) {
exec();
}
});
}());
document.addEventListener('yourCustomEvent', function (e)
{
var url=e.detail;
console.log("received "+url);
});