VimKeys Navigation for WeebCentral

hjkl navigation within WeebCentral's reader. <Alt-c> to show reader's settings. <Alt-g> to show page select dialog.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
//
// @name        VimKeys Navigation for WeebCentral
// @namespace   Violentmonkey Scripts
// @match       https://weebcentral.com/chapters/*
// @grant       none
// @version     0.2
// @author      Sadist
// @license     MIT
// @description hjkl navigation within WeebCentral's reader. <Alt-c> to show reader's settings. <Alt-g> to show page select dialog.
// ==/UserScript==

const scrollLines = 35;
const ratioExp = 2.6;
const keyList = ['g','c','h','j','k','l','f'];


function isInputActive() {
	return (document.activeElement.tagName === "INPUT");
}

function noModifierKey(event) {
	return (!((event.altKey) || (event.ctrlKey) || (event.metaKey) || (event.shiftKey)));
}

document.addEventListener("keydown", (event) => {
	if ( isInputActive() ) {
		return;
	}
	if ( !keyList.includes(event.key) ) {
		console.log('key not in list')
		return;
	}
	if ( noModifierKey(event) ) {
		switch (event.key) {
			case 'h':
				document.getElementById('nav-top').querySelector('div > button:nth-child(4)').click();
				break;
			case 'l':
				document.getElementById('nav-top').querySelector('div > button:nth-child(8)').click();
				break;
			case 'k':
				scrollByLines(-scrollLines * Math.pow(window.devicePixelRatio, ratioExp));
				break;
			case 'j':
				scrollByLines(scrollLines * Math.pow(window.devicePixelRatio, ratioExp));
				break;
		}
		return;
	}
	if ( (event.key === 'g') && (event.altKey) ) {
		document.getElementById('nav-top').querySelector('div > button:nth-child(6)').click();
		return;
	}
	if ( (event.key === 'c') && (event.altKey) ) {
		preference_modal.showModal()
		return;
	}
	if ( (event.key === 'f') && (event.ctrlKey) ) {
		event.preventDefault();
		document.getElementById('quick-search-input').focus();
		return;
	}
});