rednaz / lichess_puzzle_fen

// ==UserScript==
// @name lichess_puzzle_fen
// @version 1
// @match *://lichess.org/training*
// @grant unsafeWindow
// @run-at document-idle
// @license MIT
// ==/UserScript==

const puzzle_div = document.getElementById("puzzle");
const fen_div = document.createElement("div");
fen_div.innerHTML =
  "<label for=\"fen_rednaz\">FEN</label> <input type=\"text\" value=\"" +
  (array => array[array.length-1])(unsafeWindow.lichess.puzzle.data.game.treeParts).fen +
  "\" id=\"fen_rednaz\" style=\"width:455px\"/>";

const mutation_observer_configuratio = {"childList": true};

const append_div_fen = (mutation, observer) => {
  observer.disconnect();
  fen_div.remove();
  puzzle_div.appendChild(fen_div);
  observer.observe(puzzle_div, mutation_observer_configuratio);
};

const observer_puzzle = new MutationObserver(append_div_fen);
observer_puzzle.observe(puzzle_div, mutation_observer_configuratio);

append_div_fen(undefined, observer_puzzle);