|
2 | 2 | // @name lemmy-keyboard-navigation |
3 | 3 | // @match https://*/* |
4 | 4 | // @grant none |
5 | | -// @version 1.9 |
| 5 | +// @version 2.0 |
6 | 6 | // @author vmavromatis |
7 | 7 | // @author howdy@thesimplecorner.org |
8 | 8 | // @author InfinibyteF4 |
|
15 | 15 | // @run-at document-end |
16 | 16 | // ==/UserScript== |
17 | 17 |
|
| 18 | + |
| 19 | + |
18 | 20 | //isLemmySite |
19 | 21 | if (document.querySelectorAll('.lemmy-site').length >= 1){ |
20 | 22 |
|
21 | 23 | // Vim key toggle |
22 | 24 | // Default: true |
23 | 25 | // Set to false for arrow key navigation |
24 | | -const vimKeyNavigation = true; |
| 26 | +var vimKeyNavigation = true; |
25 | 27 |
|
26 | 28 | // Set selected entry colors |
27 | 29 | const backgroundColor = '#373737'; |
@@ -54,6 +56,7 @@ const smallerimgKey = 'Minus'; |
54 | 56 | const biggerimgKey = 'Equal'; |
55 | 57 | const userKey = 'KeyU'; |
56 | 58 | const editKey = 'KeyE'; |
| 59 | +const inputSwitchKey = 'KeyV'; |
57 | 60 |
|
58 | 61 | const modalCommentsKey = 'KeyC'; |
59 | 62 | const modalPostsKey = 'KeyP'; |
@@ -91,7 +94,7 @@ const css = [ |
91 | 94 | let myDialog = document.createElement("dialog"); |
92 | 95 | document.body.appendChild(myDialog); |
93 | 96 | let para = document.createElement("p"); |
94 | | -para.innerText = '--- Frontpage Sort ---\nP = posts\nC = comments\n1 = subscribed\n2 = local\n3 = all\n\n--- Everywhere Else ---\nS = saved\nF = frontpage\nU = profile\nI = inbox\n'; |
| 97 | +para.innerText = '--- Frontpage Sort ---\nP = posts\nC = comments\n1 = subscribed\n2 = local\n3 = all\n\n--- Everywhere Else ---\nS = saved\nF = frontpage\nU = profile\nI = inbox\nV = Toggle input style'; |
95 | 98 | myDialog.appendChild(para); |
96 | 99 | let button = document.createElement("button"); |
97 | 100 | button.classList.add('CLOSEBUTTON1'); |
@@ -148,6 +151,7 @@ const observer = new MutationObserver(() => { |
148 | 151 | observer.observe(targetNode, config); |
149 | 152 |
|
150 | 153 | function init() { |
| 154 | + |
151 | 155 | // If jumping to comments |
152 | 156 | if (window.location.search.includes("scrollToComments=true") && |
153 | 157 | entries.length > 1 && |
@@ -181,7 +185,7 @@ function init() { |
181 | 185 | } |
182 | 186 |
|
183 | 187 | function handleKeyPress(event) { |
184 | | - if (["TEXTAREA", "INPUT"].indexOf(event.target.tagName) > -1) { |
| 188 | + if (["TEXTAREA", "INPUT"].indexOf(event.target.tagName) > -1 || event.metaKey) { |
185 | 189 | return; |
186 | 190 | } |
187 | 191 |
|
@@ -226,10 +230,7 @@ function handleKeyPress(event) { |
226 | 230 | break; |
227 | 231 | case replycommKey: |
228 | 232 | if (window.location.pathname.includes("/post/")) { |
229 | | - // Allow Mac refresh with CMD+R |
230 | | - if (event.key !== 'Meta') { |
231 | 233 | reply(event); |
232 | | - } |
233 | 234 | } else { |
234 | 235 | community(event); |
235 | 236 | } |
@@ -308,6 +309,22 @@ function handleKeyPress(event) { |
308 | 309 | case popupKey: |
309 | 310 | gotodialog(0); |
310 | 311 | break; |
| 312 | + case inputSwitchKey: |
| 313 | + vimKeyNavigation = !vimKeyNavigation; |
| 314 | + //Repeat definitions |
| 315 | + if (vimKeyNavigation) { |
| 316 | + nextKey = 'KeyJ'; |
| 317 | + prevKey = 'KeyK'; |
| 318 | + nextPageKey = 'KeyL'; |
| 319 | + prevPageKey = 'KeyH'; |
| 320 | + }else{ |
| 321 | + nextKey = 'ArrowDown'; |
| 322 | + prevKey = 'ArrowUp'; |
| 323 | + nextPageKey = 'ArrowRight'; |
| 324 | + prevPageKey = 'ArrowLeft'; |
| 325 | + } |
| 326 | + gotodialog(0); |
| 327 | + break; |
311 | 328 | case modalSubscribedKey: |
312 | 329 | let subelement = document.querySelectorAll('[title="Shows the communities you\'ve subscribed to"]')[0]; |
313 | 330 | subelement.click(); |
|
0 commit comments