function collapse() {
	this.innerHTML = "expand"
	this.parentElement.nextElementSibling.style.display = "none"
	this.onclick = expand
	let cid = this.parentElement.parentElement.id
	if (!collapsedSet[cid]) {
		collapsedSet[cid] = true
		localStorage.setItem("collapsed", Object.keys(collapsedSet).join(" "))
	}
}
function expand() {
	this.innerHTML = "collapse"
	this.parentElement.nextElementSibling.style.display = "block"
	this.onclick = collapse
	let cid = this.parentElement.parentElement.id
	delete collapsedSet[cid]
	localStorage.setItem("collapsed", Object.keys(collapsedSet).join(" "))
}

let collapsedSet = {}

function domdone() {
	let collapsed = localStorage.getItem("collapsed") || ""
	let carr = collapsed.split(" ")
	if (carr.length > 64) {
		carr = carr.slice(-64)
	}
	carr.forEach(cid => collapsedSet[cid] = true)
	let els = document.getElementsByClassName("collapselink")
	for (let i = 0; i < els.length; i++) {
		var el = els[i]
		let cid = el.parentElement.parentElement.id
		if (collapsedSet[cid]) {
			collapse.call(el)
		} else {
			el.onclick = collapse
		}
	}
}

document.addEventListener("DOMContentLoaded", domdone);
