Skip to content

Instantly share code, notes, and snippets.

@ntnbrtnkv
Last active June 6, 2021 09:05
Show Gist options
  • Save ntnbrtnkv/d4f8164406655be4002c7a62a1d78a84 to your computer and use it in GitHub Desktop.
Save ntnbrtnkv/d4f8164406655be4002c7a62a1d78a84 to your computer and use it in GitHub Desktop.
Chess.com problem to Lichess goto
// ==UserScript==
// @name Chess.com problem to Lichess goto
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Analyse chess.com puzzle with lichess
// @author You
// @match *://*.chess.com/puzzles/problem/*
// @run-at document-end
// @icon https://www.google.com/s2/favicons?domain=tampermonkey.net
// @grant none
// ==/UserScript==
(function() {
'use strict';
function getFEN() {
const el = document.querySelector('[property="og:image"]');
return /fen=([a-zA-Z\d\/]+)/.exec(el.content)[1];
}
function openLichessAnalysis(fen) {
window.open(`https://lichess.org/analysis/standard/${fen}`);
}
function addButton() {
const btn = document.createElement('div');
btn.className = 'icon-font-chess chess-pawn-square play-action-tray-icon';
btn.onclick = () => {
openLichessAnalysis(getFEN());
}
document.querySelector('.play-action-tray-left').appendChild(btn);
}
addButton();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment