VimKeys Navigation for WeebCentral

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

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==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;
	}
});