Skip to content

Commit ed12945

Browse files
authored
Add vimKeyNavigation toggle in dashboard, bugfix for #13
1 parent 9016b3a commit ed12945

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

lemmy-keyboard-navigation.user.js

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// @name lemmy-keyboard-navigation
33
// @match https://*/*
44
// @grant none
5-
// @version 1.9
5+
// @version 2.0
66
// @author vmavromatis
77
// @author howdy@thesimplecorner.org
88
// @author InfinibyteF4
@@ -15,13 +15,15 @@
1515
// @run-at document-end
1616
// ==/UserScript==
1717

18+
19+
1820
//isLemmySite
1921
if (document.querySelectorAll('.lemmy-site').length >= 1){
2022

2123
// Vim key toggle
2224
// Default: true
2325
// Set to false for arrow key navigation
24-
const vimKeyNavigation = true;
26+
var vimKeyNavigation = true;
2527

2628
// Set selected entry colors
2729
const backgroundColor = '#373737';
@@ -54,6 +56,7 @@ const smallerimgKey = 'Minus';
5456
const biggerimgKey = 'Equal';
5557
const userKey = 'KeyU';
5658
const editKey = 'KeyE';
59+
const inputSwitchKey = 'KeyV';
5760

5861
const modalCommentsKey = 'KeyC';
5962
const modalPostsKey = 'KeyP';
@@ -91,7 +94,7 @@ const css = [
9194
let myDialog = document.createElement("dialog");
9295
document.body.appendChild(myDialog);
9396
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';
9598
myDialog.appendChild(para);
9699
let button = document.createElement("button");
97100
button.classList.add('CLOSEBUTTON1');
@@ -148,6 +151,7 @@ const observer = new MutationObserver(() => {
148151
observer.observe(targetNode, config);
149152

150153
function init() {
154+
151155
// If jumping to comments
152156
if (window.location.search.includes("scrollToComments=true") &&
153157
entries.length > 1 &&
@@ -181,7 +185,7 @@ function init() {
181185
}
182186

183187
function handleKeyPress(event) {
184-
if (["TEXTAREA", "INPUT"].indexOf(event.target.tagName) > -1) {
188+
if (["TEXTAREA", "INPUT"].indexOf(event.target.tagName) > -1 || event.metaKey) {
185189
return;
186190
}
187191

@@ -226,10 +230,7 @@ function handleKeyPress(event) {
226230
break;
227231
case replycommKey:
228232
if (window.location.pathname.includes("/post/")) {
229-
// Allow Mac refresh with CMD+R
230-
if (event.key !== 'Meta') {
231233
reply(event);
232-
}
233234
} else {
234235
community(event);
235236
}
@@ -308,6 +309,22 @@ function handleKeyPress(event) {
308309
case popupKey:
309310
gotodialog(0);
310311
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;
311328
case modalSubscribedKey:
312329
let subelement = document.querySelectorAll('[title="Shows the communities you\'ve subscribed to"]')[0];
313330
subelement.click();

0 commit comments

Comments
 (0)