(no title)
seanwessmith | 3 years ago
// Get all square elements
squareElements = [...document.querySelectorAll("[data-testid='white-square']"), ...document.querySelectorAll("[data-testid='black-square']")];
// create array of elements that have been landed on
// these need to be set to red every time because the board resets every move
let modifiedElements = [];
observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
if (mutation.addedNodes.length > 0) {
mutation.addedNodes.forEach(function(addedNode) {
key = addedNode.getAttribute('data-testid').split('-')[1];
if (!modifiedElements.includes(key)) {
modifiedElements.push(key);
}
for (let i = 0; i < modifiedElements.length; i++) {
el = squareElements.find(e => {
return e.getAttribute('data-squareid') === modifiedElements[i]
})
el.style.backgroundColor = 'red';
}
});
}
});
});
// observe all square elements
for (let i = 0; i < squareElements.length; i++) {
observer.observe(squareElements[i], { childList: true, subtree: true });
}
// replace instructions with more accurate instructions
instructions = document.querySelector('section p')
instructions.innerHTML = 'Move to the square indicated below the board without moving to a square the queen can capture and without capturing the queen. Once accomplished a new square will be indicated. Repeat until all possible squares are done.';
wglass|3 years ago
seanwessmith|3 years ago