const detailsElements = document.getElementsByTagName('details');
const save = () => {
    Array.from(detailsElements).forEach((details, i) => {
        localStorage.setItem(`details${i}`, details.hasAttribute('open'));
    });
};
Array.from(detailsElements).forEach((details, i) => {
    details.toggleAttribute('open', JSON.parse(localStorage.getItem(`details${i}`)) || false);
    details.addEventListener('toggle', save);
});