lichess.org
Donate

Anyone know JAVASCRIPT that could make a very short but extremely useful user script for lichess?

I want to simply go to the next chapter when in a study by pressing a shortcut key.
I like to jump between chapters a lot and on my screen setup I gotta scroll down the page first to see the chapters then hunt and click then scroll up.
This would make things a lot easier for me. If you can help thanks!!
@PizzaChess61

I made one for you. It can be found in the following link with syntax highlighting, or just as plain text below:

gist.github.com/Xatenev/aa919c93fc3e284c266648c15bba6b0f

Press 'p' to go to the previous chapter.
Press 'n' to go to the next chapter.

PS: If you prefer different keys, you can visit keycode.info/ and press the respective key. It will display their "keycode". Replace the numbers 78 and 80 with the keys you want to use. For example, an alternative usage of <left arrow> and <right arrow> would have the keys 37 and 39, so you would replace 80 with 37 and 78 with 39.

-------------------

// ==UserScript==
// @name Lichess study enhancement
// @author Xatenev
// @match https://*.lichess.org/*
// ==/UserScript==

(function() {
'use strict';
console.log("Lichess study userscript loaded");

document.addEventListener('keydown', onKeyDown);

function onKeyDown(e) {
const activeElement = document.querySelector('.study__chapters .active');
if(activeElement) {
if(e.keyCode === 78) { // press n
const next = activeElement.nextSibling;
if(next) {
next.click();
}
}
if(e.keyCode === 80) { // press p
const previous = activeElement.previousSibling;
if(previous) {
previous.click();
}
}
}
}
})();
You are my hero lol. This works perfectly I can't believe it I've been wanting this for so long. Thank you so very much. What's even better is I'm just starting out trying to learn how to tweak websites with user scripts and I'm going to be pouring all over your example and I'm sure it will be very helpful for my understanding. I can see you're probably a pro at this by your style. Gave me a fish and taught me a little about fishing.

I think this definitely deserves to be mentioned on lichess.org/team/css-javascript-coding-on-lichess so with your permission , if it's alright with you, I will post your script there , giving you credit of course. Or if you want to join and post it yourself I'll let you.

This topic has been archived and can no longer be replied to.