Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save antonpetrovmain/6c960481b48c79ca2f2387dc7f351929 to your computer and use it in GitHub Desktop.

Select an option

Save antonpetrovmain/6c960481b48c79ca2f2387dc7f351929 to your computer and use it in GitHub Desktop.
Flip the chess board in Chessable exercises more easily.
// ==UserScript==
// @name Flip Chessable Board
// @namespace https://blz777.github.io/
// @version 0.1
// @description Flip the chess board in Chessable exercises more easily.
// @author You
// @match https://*.chessable.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=chessable.com
// @grant none
// @require http://code.jquery.com/jquery-3.4.1.min.js
// ==/UserScript==
/* global $ */
/*
Flips the chess board in Chessable excercises manually or automatically positions white pieces on the bottom of the board (can be disabled).
== How can I use this script? ==
The script is automatically activated by Tampermonkey (a browser extension, e.g. Chrome) in the browser.
The autorotation is initially enabled - after every exercies, click the "space bar" to go to the next one.
The script detects whether the h8 square is on the bottom left of the board and rotates the board if it is so that a1 is on the bottom left.
== Shortcuts ==
To toggle automatic rotation on/off, press 't'. Notice in Chrome's Console a log message is printed to let you know of the state of the autorotation. Enabled by default.
To manually rotate the board, press 'f'.
To manually set the a1 square on the bottom left, press 'b'.
== How can I install this script? ==
The script can be automatically activated by Tampermonkey (a Chrome browser extension) for the Chessable website.
*/
function flipBoard() {
$("button[data-testid='flipButton']")[0].click();
}
function makeWhiteSideBottom() {
if (isAutoRotateEnabled && ($("*[class^='board']").children().filter($('div[class^="row"]')).last().children().first().text() == "h8")) {
// we would like to have the white side always on the bottom.
flipBoard();
}
}
var isAutoRotateEnabled = true
function toggleAutoRotateEnabled() {
isAutoRotateEnabled = !isAutoRotateEnabled;
console.log("Auto rotate is set to: " + isAutoRotateEnabled);
}
$(document).ready(function(){
document.addEventListener('keyup', function(e) {
// The 'f' key
if (e.keyCode == 70) {
flipBoard();
// The 'b' key
} else if (e.keyCode == 66) {
makeWhiteSideBottom();
// The 't' key
} else if (e.keyCode == 84) {
toggleAutoRotateEnabled();
} else {
//console.log(e.keyCode);
}
// The 'space' key
if (e.keyCode == 32) {
setTimeout(makeWhiteSideBottom(), 1000);
}
}, false);
makeWhiteSideBottom();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment