VimKeys Navigation for WeebCentral

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

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

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