Raw Source
salsan / Customize Chessboard

// ==UserScript==
// @name         Customize Chessboard
// @namespace    https://github.com/salsan/customizechessboard
// @version      0.7
// @updateURL    https://raw.githubusercontent.com/salsan/customizechessboard/master/customizechessboard.user.js
// @description  Customize Chessboard of internet chess server
// @author       salsan
// @copyright    2020, Salvatore Santagati (https://blog.salsan.dev/)
// @license      GPL-3.0-or-later; http://www.gnu.org/licenses/gpl-3.0.txt
// @match        https://lichess.org/*
// @match        https://www.chess.com/*
// @run-at       document-end
// @grant        GM_addStyle
// ==/UserScript==

function isRotated() {
  const website = window.location.hostname;

  if (website === 'lichess.org') {
    if (document.getElementsByClassName('orientation-black').length > 0) {
      return true;
    }
    else {
      return false;
    }
  }
  else if (website === 'www.chess.com') {
    if (document.getElementsByClassName("letter")[0].innerText === 'h') {
      return true;
    }
    else {
      return false;
    }
  }
}

function setPieces(pieces) {
  const website = window.location.hostname;

  if (website === 'lichess.org') {
    if (isRotated()) {
      GM_addStyle('piece.black.king {background-image:' + pieces + ' !important;}');
    }
    else {
      GM_addStyle('piece.white.king {background-image:' + pieces + ' !important;}');

    }
  }
  else if (website === 'www.chess.com') {
    if (isRotated()) {
      GM_addStyle('div#piece-29 { background-image:' + pieces + ' !important}');
    }
    else {
      GM_addStyle('div#piece-5 { background-image:' + pieces + ' !important}');
    }
  }
}

(function () {
  'use strict';

  // Convert Image to base64 https://www.base64-image.de/
  const yourKing = "url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAMAAABHPGVmAAABhGlDQ1BJQ0MgcHJvZmlsZQAAKJF9kT1Iw1AUhU9TpSIVBztIEcxQnSyIijhqFYpQIdQKrTqYvPQPmjQkKS6OgmvBwZ/FqoOLs64OroIg+APi5Oik6CIl3pcUWsT44PI+znvncN99gNCoMM3qGgc03TbTyYSYza2KoVeEEKQaRlRmljEnSSn4rq97BPh+F+dZ/vf+XH1q3mJAQCSeZYZpE28QT2/aBud94ggrySrxOfGYSQ0SP3Jd8fiNc9FlgWdG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