Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: store muted state in local storage #28

Merged
merged 1 commit into from
Aug 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ function shuffleArray(array: string[]) {
let currentAudio: HTMLAudioElement | null = null;
let isMuted = false;

// Load the mute state from local storage
const savedMuteState = localStorage.getItem("isMuted");
if (savedMuteState !== null) {
isMuted = JSON.parse(savedMuteState);
if (muteIcon) {
muteIcon.className = isMuted ? "fas fa-volume-mute" : "fas fa-volume-up";
}
}

// Function to play music files in order and loop infinitely
function playMusic(files: string[]) {
if (files.length === 0) return;
Expand Down Expand Up @@ -115,6 +124,7 @@ muteButton?.addEventListener("click", () => {
if (muteIcon) {
muteIcon.className = isMuted ? "fas fa-volume-mute" : "fas fa-volume-up";
}
localStorage.setItem("isMuted", JSON.stringify(isMuted));
});

// Start a new game
Expand Down