This commit is contained in:
Maciej Caderek
2022-01-13 06:00:00 +01:00
commit f3069d6dd1
48 changed files with 2220 additions and 0 deletions

40
scripts/getPieces.js Normal file
View File

@@ -0,0 +1,40 @@
const getBackgroundUrl = (element, prop) => {
const style = window.getComputedStyle(element);
return style.getPropertyValue(prop).replace('url("', "").replace('")', "");
};
const items = {
kw: "",
qw: "",
rw: "",
bw: "",
nw: "",
pw: "",
kb: "",
qb: "",
rb: "",
bb: "",
nb: "",
pb: "",
};
document.querySelectorAll("cg-board > piece").forEach((item) => {
const color = item.classList.contains("black") ? "b" : "w";
const type = item.classList.contains("pawn")
? "p"
: item.classList.contains("king")
? "k"
: item.classList.contains("queen")
? "q"
: item.classList.contains("bishop")
? "b"
: item.classList.contains("rook")
? "r"
: "n";
const url = getBackgroundUrl(item, "background-image");
items[`${type}${color}`] = url;
});
console.log(JSON.stringify(items, null, 2));