-
Notifications
You must be signed in to change notification settings - Fork 2
/
surfingkeys.js
377 lines (349 loc) · 9.19 KB
/
surfingkeys.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
const {
map,
unmap,
iunmap,
mapkey,
removeSearchAlias,
addSearchAlias,
vmapkey,
Hints,
RUNTIME,
Normal,
Visual
} = api;
// Vimium/cVim
map('u', 'e');
unmap('p');
mapkey('p', "Open the clipboard's URL in the current tab", function () {
Front.getContentFromClipboard(function (response) {
window.location.href = response.data;
});
});
map('P', 'cc');
map('gi', 'i');
map('_F', 'F');
map('_C', 'C');
map('F', '_C');
map('C', '_F');
map('gf', 'w');
map('`', '\'');
map('_H', 'H');
map('_S', 'S');
map('_D', 'D');
map('_L', 'L');
map('H', '_S');
map('S', '_H')
map('D', '_L');
map('L', '_D');
map('gt', 'R');
map('gT', 'E');
map('K', 'R');
map('J', 'E');
// Unmap temporary keys
unmap('_F');
unmap('_C');
unmap('_S');
unmap('_H');
unmap('_D');
unmap('_L');
// Unmap emoji input
iunmap(':');
// settings.hintAlign = "left"
//Add shift-toggle for background hints
settings.hintShiftNonActive = true;
// Smart Page Boundary
settings.smartPageBoundary = true;
// Search aliases
removeSearchAlias('b', 's') // Get rid of baidu
removeSearchAlias('w', 's') // Get rid of bing
removeSearchAlias('g', 's') // Get rid of Google, I use kagi
// Wikipedia search alias
addSearchAlias(
'w', // Alias
'wikipedia', // Prompt
'https://en.wikipedia.org/w/index.php?title=Special:Search&search=', // search url
's', // leader key
'https://en.wikipedia.org/w/api.php?action=opensearch&format=json&formatversion=2&namespace=0&limit=20&suggest=true&search=', // suggestion url
(response) => JSON.parse(response.text)[1] // Response parser
);
addSearchAlias(
'g',
'kagi',
'https://kagi.com/search?q=',
's',
"https://kagi.com/api/autosuggest?q=",
(response) => JSON.parse(response.text)[1]
);
addSearchAlias('G', '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=', (response) => JSON.parse(response.text)[1]);
// Change open detected URL to new tab
unmap("O");
mapkey('O', '#1Open detected links from text', function () {
Hints.create(runtime.conf.clickablePat, function (element) {
window.open(element[2]);
}, { statusLine: "Open detected links from text" });
});
// Improve default remove query/fragment
mapkey('g?', '#4Reload current page without query', function () {
window.location.href = window.location.href.replace(/\?[^?#]*/, '');
});
mapkey('g#', '#4Reload current page without hash fragment', function () {
window.location.href = window.location.href.replace(/\#[^#]*/, '');
});
mapkey('gB', '#4Reload current page without query or hash fragment', function () {
window.location.href = window.location.href.replace(/[#?].*/, '');
});
// Add copy without query/fragment
mapkey('y?', "#7Copy current page's URL without query", function () {
Clipboard.write(window.location.href.replace(/\?[^?#]*/, ''))
});
mapkey('y#', "#7Copy current page's URL without hash fragment", function () {
Clipboard.write(window.location.href.replace(/#[^#]*/, ''))
});
mapkey('yb', "#7Copy current page's URL without query or hash fragment", function () {
Clipboard.write(window.location.href.replace(/[#?].*$/, ''))
});
// Base64 stuff
vmapkey("dy", "#9Base64 decode and copy selection", function () {
const text = window.getSelection().toString()
Clipboard.write(atob(text))
Visual.toggle();
});
vmapkey("do", "#9Base64 decode selection and open as URL", function () {
const text = window.getSelection().toString()
window.open(atob(text));
Visual.toggle()
});
// Passthrough key
mapkey('p', '#0enter ephemeral PassThrough mode to temporarily suppress SurfingKeys', function () {
Normal.passThrough(1500);
});
// Copy image url key
mapkey(';yi', "#7Copy image URL", function () {
Hints.create('img', function (element) {
Clipboard.write(element.src);
});
});
// Download url
mapkey(';df', "#1Download link", function () {
Hints.create("*[href]", function (element) {
RUNTIME('download', { url: element.href })
})
});
mapkey(';dm', "#1Download multiple links", function () {
Hints.create("*[href]", function (element) {
RUNTIME('download', { url: element.href })
}, { multipleHits: true })
});
mapkey('sx', "#6Open current page in kagi summary page in a new tab", function () {
window.open(`https://kagi.com/summarizer/index.html?target_language=&summary=takeaway&url=${window.location.href}`)
});
mapkey('sX', "#6Open selected hint with Kagi summarizer", function () {
Hints.create("*[href]", function (element) {
window.open(`https://kagi.com/summarizer/index.html?target_language=&summary=takeaway&url=${element[2]}`)
});
});
// Bottom-style omnibar
settings.omnibarPosition = 'bottom';
// Neovim hasn't ever worked for me, because it whines about websocket
// security. I use firenvim for large inputs anyways, which seems to have
// better performance, so this is mostly about editing single line inputs and
// multiselects
settings.useNeovim = false;
settings.newTabPosition = "last";
// Tomorrow night style hints
Hints.style('font-family: system-ui;');
Hints.style("font-family: system-ui;", "text");
// set theme
settings.theme = `
/* Edit these variables for easy theme making */
:root {
/* Font */
--font: system-ui;
--font-size: 12;
--font-weight: bold;
--fg: #C5C8C6;
--bg: #282A2E;
--bg-dark: #1D1F21;
--border: #373b41;
--main-fg: #52C196;
--accent-fg: #81A2BE;
--info-fg: #AC7BBA;
--select: #585858;
/* Unused Alternate Colors */
/* --cyan: #4CB3BC; */
/* --orange: #DE935F; */
/* --red: #CC6666; */
/* --yellow: #CBCA77; */
}
/* ---------- Generic ---------- */
.sk_theme {
background: var(--bg);
color: var(--fg);
background-color: var(--bg);
border-color: var(--border);
font-family: var(--font);
font-size: var(--font-size);
font-weight: var(--font-weight);
}
input {
font-family: var(--font);
font-weight: var(--font-weight);
}
.sk_theme tbody {
color: var(--fg);
}
.sk_theme input {
color: var(--fg);
}
/* Hints */
#sk_hints .begin {
color: var(--accent-fg) !important;
}
#sk_tabs .sk_tab {
background: var(--bg-dark);
border: 1px solid var(--border);
color: var(--fg);
}
#sk_tabs .sk_tab_title {
color: var(--fg);
}
#sk_tabs .sk_tab_url {
color: var(--accent-fg);
}
#sk_tabs .sk_tab_hint {
background: var(--bg);
border: 1px solid var(--border);
color: var(--accent-fg);
}
.sk_theme #sk_frame {
background: var(--bg);
opacity: 0.2;
color: var(--accent-fg);
}
/* ---------- Omnibar ---------- */
/* Uncomment this and use settings.omnibarPosition = 'bottom' for Pentadactyl/Tridactyl style bottom bar */
.sk_theme#sk_omnibar {
width: 100%;
left: 0;
}
.sk_theme .title {
color: var(--accent-fg);
}
.sk_theme .url {
color: var(--main-fg);
}
.sk_theme .annotation {
color: var(--accent-fg);
}
.sk_theme .omnibar_highlight {
color: var(--accent-fg);
}
.sk_theme .omnibar_timestamp {
color: var(--info-fg);
}
.sk_theme .omnibar_visitcount {
color: var(--accent-fg);
}
.sk_theme #sk_omnibarSearchResult ul li:nth-child(odd) {
background: var(--bg-dark);
}
.sk_theme #sk_omnibarSearchResult ul li.focused {
background: var(--border);
}
.sk_theme #sk_omnibarSearchArea {
border-top-color: var(--border);
border-bottom-color: var(--border);
}
.sk_theme #sk_omnibarSearchArea input,
.sk_theme #sk_omnibarSearchArea span {
font-size: var(--font-size);
}
.sk_theme .separator {
color: var(--accent-fg);
}
/* ---------- Popup Notification Banner ---------- */
#sk_banner {
font-family: var(--font);
font-size: var(--font-size);
font-weight: var(--font-weight);
background: var(--bg);
border-color: var(--border);
color: var(--fg);
opacity: 0.9;
}
/* ---------- Popup Keys ---------- */
#sk_keystroke {
background-color: var(--bg);
}
.sk_theme kbd .candidates {
color: var(--info-fg);
}
.sk_theme span.annotation {
color: var(--accent-fg);
}
/* ---------- Popup Translation Bubble ---------- */
#sk_bubble {
background-color: var(--bg) !important;
color: var(--fg) !important;
border-color: var(--border) !important;
}
#sk_bubble * {
color: var(--fg) !important;
}
#sk_bubble div.sk_arrow div:nth-of-type(1) {
border-top-color: var(--border) !important;
border-bottom-color: var(--border) !important;
}
#sk_bubble div.sk_arrow div:nth-of-type(2) {
border-top-color: var(--bg) !important;
border-bottom-color: var(--bg) !important;
}
/* ---------- Search ---------- */
#sk_status,
#sk_find {
font-size: var(--font-size);
border-color: var(--border);
}
.sk_theme kbd {
background: var(--bg-dark);
border-color: var(--border);
box-shadow: none;
color: var(--fg);
}
.sk_theme .feature_name span {
color: var(--main-fg);
}
/* ---------- ACE Editor ---------- */
#sk_editor {
background: var(--bg-dark) !important;
height: 50% !important;
/* Remove this to restore the default editor size */
}
.ace_dialog-bottom {
border-top: 1px solid var(--bg) !important;
}
.ace-chrome .ace_print-margin,
.ace_gutter,
.ace_gutter-cell,
.ace_dialog {
background: var(--bg) !important;
}
.ace-chrome {
color: var(--fg) !important;
}
.ace_gutter,
.ace_dialog {
color: var(--fg) !important;
}
.ace_cursor {
color: var(--fg) !important;
}
.normal-mode .ace_cursor {
background-color: var(--fg) !important;
border: var(--fg) !important;
opacity: 0.7 !important;
}
.ace_marker-layer .ace_selection {
background: var(--select) !important;
}
`;