document.addEventListener('DOMContentLoaded',()=>{const selectMajorScaleElement=document.getElementById('majorscale');const selectMinorScaleElement=document.getElementById('minorscale');const selectMajorElement=document.getElementById('majorchord');const selectMinorElement=document.getElementById('minorchord');const selectDiminishedElement=document.getElementById('diminishedchord');const selectAugmentedElement=document.getElementById('augmentedchord');var showchord=document.getElementById('showchord');const pianoKeys=document.querySelectorAll('.piano-keys .key');const solfegeMap={'C':'Do','C#':'Do#','D':'Re','D#':'Re#','E':'Mi','F':'Fa','F#':'Fa#','G':'So','G#':'So#','A':'La','A#':'La#','B':'Ti'};const indianMap={'C':'सा','C#':'रे♭','D':'रे','D#':'गा♭','E':'गा','F':'मा','F#':'मा#','G':'प','G#':'धा♭','A':'धा','A#':'नि♭','B':'नि'};function matchNote(keyElement,noteLetter){const keyNote=keyElement.dataset.note;if(keyNote===noteLetter){return!0}
const noteLabelSpan=keyElement.querySelector('.note-label');if(!noteLabelSpan)return!1;const label=noteLabelSpan.textContent;return(label===solfegeMap[noteLetter]||label===indianMap[noteLetter])}
const majorChords={'C':['C','E','G'],'C#':['C#','F','G#'],'D':['D','F#','A'],'D#':['D#','G','A#'],'E':['E','G#','B'],'F':['F','A','C'],'F#':['F#','A#','C#'],'G':['G','B','D'],'G#':['G#','C','D#'],'A':['A','C#','E'],'A#':['A#','D','F'],'B':['B','D#','F#']};selectMajorElement.addEventListener('change',(event)=>{const selectedChord=event.target.value;selectMinorElement.selectedIndex=0;selectDiminishedElement.selectedIndex=0;selectAugmentedElement.selectedIndex=0;selectMajorScaleElement.selectedIndex=0;selectMinorScaleElement.selectedIndex=0;pianoKeys.forEach(keyElement=>keyElement.classList.remove('mark'));if(majorChords[selectedChord]){const notes=majorChords[selectedChord];pianoKeys.forEach(keyElement=>{if(notes.some(note=>matchNote(keyElement,note))){keyElement.classList.add('mark')}});showchord.value=`${selectedChord} MAJOR`}})})