Skip to content

Instantly share code, notes, and snippets.

@modess
Created April 25, 2023 08:17
Show Gist options
  • Select an option

  • Save modess/f9df93137481c02c23314ac0cf459767 to your computer and use it in GitHub Desktop.

Select an option

Save modess/f9df93137481c02c23314ac0cf459767 to your computer and use it in GitHub Desktop.
Chessable userscript
// ==UserScript==
// @name Chessable Enhancer
// @match *://*chessable.com/*
// @version 0.0.0
// @author modess
// @require https://cdn.jsdelivr.net/combine/npm/@violentmonkey/dom@2,npm/@violentmonkey/[email protected]
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant GM_addStyle
// @grant GM_setClipboard
// ==/UserScript==
(function () {
'use strict';
function makePgn() {
const fen = document.getElementById('inputFEN').getAttribute('value');
const movesWrapper = document.getElementById("theOpeningMoves");
const moveElements = movesWrapper.getElementsByTagName("div");
const moves = [...moveElements].map(el => {
return el.innerText;
});
const pgn = moves.join(" ");
return VM.h(VM.Fragment, null, VM.h("div", {
class: "colTitle colTtitleWrapper",
style: "margin-top: 20px;"
}, VM.h("strong", null, "PGN")), VM.h("div", {
class: "colContent"
}, "[Variant \"\"]", VM.h("br", null), "[FEN \"", fen, "\"]", VM.h("br", null), VM.h("br", null), pgn));
}
function addPgn() {
document.getElementsByClassName('board-setup__label').item(0).after(VM.m(makePgn()));
}
// @ts-ignore
waitForKeyElements('.board-setup__label', addPgn);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment