Vim-like Navigation

Use (h,j,k,l) to scroll around. gg to go to top G to to bottom

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Vim-like Navigation
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Use (h,j,k,l) to scroll around.  gg to go to top G to to bottom
// @author       Max Schulte
// @match        http*://*
// @match		 *://*/*
// @match		 *
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
	// Your code here...
	var keyLog = []

	document.onkeypress = function (e) {
		// if user is typing inside of a text box return
		if ( e.target.nodeName == 'INPUT' ) return;
		// event
		e = e || window.event;
		// horizontal and vertical
		var h = 0;
		var v = 0;
		// scroll amount
		keyLog.push(e.keyCode)
		//console.log(keyLog)
		var sa = 100;
		switch (e.keyCode){
			case 104:	// h
				h -= sa;
				keyLog = [];
				break;
			case 106:	// j
				v += sa;
				keyLog = [];
				break;
			case 107:	// k
				v -= sa;
				keyLog = [];
				break;
			case 108:	// l
				h += sa;
				keyLog = [];
				break;
			case 103: // gg
				if (keyLog[keyLog.length-2] != 103) {
					break;
				}
				window.scrollTo(0, 0);
				keyLog = [];
				return;
			case 71:	// G
				console.log(document.documentElement.scrollHeight)
				window.scrollTo(0, document.documentElement.scrollHeight)
				keyLog = [];
				return;
			default:
				keyLog = [];
				break;
		}
		window.scrollBy(h, v);
	};
})();