const controls = document.querySelector(".controls");
const song = document.querySelector("iframe.song").contentWindow;

// Autoscroll
var scroll;
function pageScroll() {
	song.scrollBy(0, 1);
	scroll = setTimeout(pageScroll, 80);
}

document.querySelector("#autoscroll").addEventListener("click", function() {
	if (this.classList.contains("active")) {
		clearTimeout(scroll);
	} else {
		pageScroll();
	}
	this.classList.toggle("active");
});

// Scaling
function pageScale(value) {
	if (value === 0) {
		song.document.body.style.transform = "scale(1)";
		return;
	}
	const currentScale = parseFloat(song.document.body.style.transform.split("scale(")[1]) || 1;
	song.document.body.style.transform = "scale(" + (currentScale + value) + ")";
}

controls.querySelector("#font-size-increase").addEventListener("click", () => pageScale(0.1));
controls.querySelector("#font-size-decrease").addEventListener("click", () => pageScale(-0.1));
controls.querySelector("#font-size-reset").addEventListener("click", () => pageScale(0));

// Display the controls on JS-enabled browsers
window.addEventListener("load", () => controls.classList.remove = "hidden");
