Chess.com Game Preview Styling

Applies custom styling to Chess.com board components.

Από την 11/11/2022. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Chess.com Game Preview Styling
// @namespace    http://tampermonkey.net/
// @version      1.4
// @description  Applies custom styling to Chess.com board components.
// @author       SaberSpeed77
// @match        https://www.chess.com/*
// @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 = "";

/*========= ↑ STYLE / CODE ↓ =========*/

var observer = new MutationObserver((mutations) => {
  let components = document.querySelectorAll(".game-preview-component");
  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 = (window.location.href.includes("home") || components[i]._prevClass.includes("current") ? 0 : 2); 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) == undefined) break;
              if (imgs.get(key) != "") curPiece.src = imgs.get(key);
          }
      }
  }
  if (window.location.href.includes("home")) observer.disconnect();
});

if (window.location.href.includes("home")) {
  observer.observe(document.querySelector(".promo-component"), {
      childList: true,
      subtree: true
  });
} else if (!window.location.href.includes("play")) {
  observer.observe(document, {
      childList: true,
      subtree: true
  });
}