document.querySelectorAll("#game > div > div").forEach(e => {
const rotation = e.style.transform.match(/(\d+)/)[0];
const clicks = 4-(rotation/90)%4;
[...Array(clicks)].forEach(i=>e.click());
});
It could be optimized to change the rotation direction depending on whether the current rotation is smaller or larger than 180deg, but that's not really necessary since running the script only counts as one click, and generates negative "overspin" numbers ;-)