Chess.com Game Preview Styling

Applies custom styling to Chess.com home page.

Verzia zo dňa 31.10.2022. Pozri najnovšiu verziu.

// ==UserScript==
// @name         Chess.com Game Preview Styling
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Applies custom styling to Chess.com home page.
// @author       SaberSpeed77
// @match        https://www.chess.com/home
// @icon         https://www.google.com/s2/favicons?sz=64&domain=chess.com
// @grant        none
// @license      MIT
// ==/UserScript==

const imgs = new Map([
  /* White Pieces */
  ["wp", ""],
  ["wn", ""],
  ["wb", ""],
  ["wr", ""],
  ["wq", ""],
  ["wk", ""],

  /* Black Pieces */
  ["bp", ""],
  ["bn", ""],
  ["bb", ""],
  ["br", ""],
  ["bq", ""],
  ["bk", ""],
]);

/* Background */
const background = "";

/* Game Preview Code */
var t = setInterval(() => {
    let components = document.querySelectorAll("div.game-preview-component.promo-preview");
    if (components) {
        for (let i = 0; i < components.length; i++) {
            if (background != "")
                components[i].style.backgroundImage = "url(" + background + ")";

            let pieces = components[i].children;
            for (let j = 0; j < pieces.length; j++) {
                let curPiece = pieces[j];
                let key = curPiece.src[curPiece.src.indexOf(".png") - 2] + curPiece.src[curPiece.src.indexOf(".png") - 1];
                if (imgs.get(key) != "")
                    curPiece.src = imgs.get(key);
            }
        }
        clearInterval(t);
    }
}, 300);