-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
88 lines (83 loc) · 2.8 KB
/
background.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
(function () {
"use strict";
function makeTextPatcher(func) {
return (e) => {
var stream = browser.webRequest.filterResponseData(e.requestId),
dec = new TextDecoder("UTF-8"),
data = [];
stream.ondata = function (e) {
data.push(dec.decode(e.data, { stream: true }));
};
stream.onstop = function () {
var s = data.join(""),
enc = new TextEncoder();
stream.write(enc.encode(func(s)));
stream.close();
};
return {};
};
}
browser.webRequest.onBeforeRequest.addListener(
makeTextPatcher((s) => {
var textFind = "t.prototype.enableVim=function(){",
textAdd =
"g.VimMode.Vim.noremap(';', 'l');" +
"g.VimMode.Vim.noremap('l', 'k');" +
"g.VimMode.Vim.noremap('k', 'j');" +
"g.VimMode.Vim.noremap('j', 'h');" +
"g.VimMode.Vim.noremap('h', ';');";
return s.replace(textFind, "$&" + textAdd);
}),
{
types: ["script"],
urls: ["https://static.ce-cdn.net/main.v*.*.js"],
},
["blocking"],
);
browser.webRequest.onBeforeRequest.addListener(
makeTextPatcher((s) => {
var textFind =
"const t=monacoVim.initVimMode(e,n&&n.current?n.current:void 0);",
textAdd =
"monacoVim.VimMode.Vim.noremap(';', 'l');" +
"monacoVim.VimMode.Vim.noremap('l', 'k');" +
"monacoVim.VimMode.Vim.noremap('k', 'j');" +
"monacoVim.VimMode.Vim.noremap('j', 'h');" +
"monacoVim.VimMode.Vim.noremap('h', ';');";
return s.replace(textFind, "$&" + textAdd);
}),
{
types: ["script"],
urls: [
"https://leetcode.com/_next/static/chunks/8048-f69dccd451f28f1f.js",
],
},
["blocking"],
);
browser.webRequest.onBeforeRequest.addListener(
makeTextPatcher((s) => {
return s
.replace(
'{keys:"h",type:"motion",motion:"moveByCharacters",motionArgs:{forward:!1}}',
'{keys:"j",type:"motion",motion:"moveByCharacters",motionArgs:{forward:!1}}',
)
.replace(
'{keys:"l",type:"motion",motion:"moveByCharacters",motionArgs:{forward:!0}}',
'{keys:";",type:"motion",motion:"moveByCharacters",motionArgs:{forward:!0}}',
)
.replace(
'{keys:"j",type:"motion",motion:"moveByLines",motionArgs:{forward:!0,linewise:!0}}',
'{keys:"k",type:"motion",motion:"moveByLines",motionArgs:{forward:!0,linewise:!0}}',
)
.replace(
'{keys:"k",type:"motion",motion:"moveByLines",motionArgs:{forward:!1,linewise:!0}}',
'{keys:"l",type:"motion",motion:"moveByLines",motionArgs:{forward:!1,linewise:!0}}',
);
}),
{
types: ["script"],
urls: ["https://hrcdn.net/fcore/assets/monacovim-4f9bc0dc.js"],
},
["blocking"],
);
})();