Hi!
How do you reset a script between cards or contain it to only the front of the card? I have the script below for scrolling automatically (front of card), but it only works for the first card reviewed.
Do you need to use a variable to keep track of if the card has been flipped or not, or what is the proper way to do it?
var isPaused = true;
var scrollInterval;
var scrollSpeed = 3000;
document.addEventListener("keydown", function (event) {
if (event.shiftKey && event.key === "S" && !isPaused) {
clearInterval(scrollInterval);
isPaused = true;
}
else if (event.shiftKey && event.key === "S" && isPaused) {
var speedText = document.createElement("div");
speedText.style.position = "fixed";
speedText.style.top = "20px";
speedText.style.right = "10%";
speedText.style.color = "#555";
speedText.style.fontFamily = "Avenir";
speedText.style.fontSize = "12px";
speedText.style.textAlign = "left";
speedText.innerHTML = "Speed: " + scrollSpeed + "ms";
document.body.appendChild(speedText);
setTimeout(function () {
document.body.removeChild(speedText);
}, 1500);
scrollInterval = setInterval(function () {
window.scrollBy(0, window.innerHeight);
if (window.innerHeight + window.pageYOffset >= document.body.offsetHeight) {
clearInterval(scrollInterval); // Pauses when end of page is reached
}
}, scrollSpeed);
isPaused = false;
}
else if (event.shiftKey && event.key === "I") {
var newScrollSpeed = prompt("Set scrolling (ms):", scrollSpeed);
if (newScrollSpeed !== null) {
scrollSpeed = parseInt(newScrollSpeed);
}
}
});
(For subsequent cards the message is still shown if I press shift + S
, but the scrolling does not start).