Lichess User 'Enter' Key To Continiue Training

Hooks 'Enter' key and Presses 'Continue Training' Button

目前為 2019-07-20 提交的版本,檢視 最新版本

// ==UserScript==
// @name          Lichess User 'Enter' Key To Continiue Training
// @namespace     http://userstyles.org
// @description   Hooks 'Enter' key and Presses 'Continue Training' Button
// @author        636597
// @include       *://*lichess.org/*
// @run-at        document-start
// @version       0.1
// ==/UserScript==

function try_click() {
	try{
		console.log( "Trying to Click 'Continue Training' Button" );
		var continue_button = document.querySelector( "a.continue" );
		if ( !continue_button ) { return; }
		continue_button.click();
	}
	catch( e ) { console.log( e ); }
}

function hook_enter_key() {
	console.log( "Hooking 'Enter' Key" );
	document.body.addEventListener( "keydown" , function( event ) {
		if ( event.key === "Enter" ) {
			try_click();
		}
	});
}

( function() {
	window.addEventListener ( "load" , hook_enter_key );
})();