{"id":2946,"date":"2026-02-23T18:20:13","date_gmt":"2026-02-23T17:20:13","guid":{"rendered":"https:\/\/hb9id.ch\/?page_id=2946"},"modified":"2026-02-24T07:10:03","modified_gmt":"2026-02-24T06:10:03","slug":"morsetrainer","status":"publish","type":"page","link":"https:\/\/archiv-24-26.hb9id.ch\/index.php\/morsetrainer\/","title":{"rendered":"HB9ID Morsetrainer"},"content":{"rendered":"    <div id=\"hb9id-morse-plugin\">\n        <style>\n            #hb9id-morse-plugin { font-family: Arial, sans-serif; max-width: 700px; margin: 20px auto; padding: 20px; background-color: #f4f4f9; color: #333; border-radius: 8px; line-height: 1.5; border: 1px solid #ddd; }\n            #hb9id-morse-plugin h1 { font-size: 24px; color: #2c3e50; margin-bottom: 5px; }\n            #hb9id-morse-plugin h5 { font-size: 14px; color: #7f8c8d; margin-top: 0; margin-bottom: 20px; }\n            #hb9id-morse-plugin .control-group { margin-bottom: 15px; }\n            #hb9id-morse-plugin label { display: block; font-weight: bold; margin-bottom: 5px; }\n            #hb9id-morse-plugin input[type=\"range\"] { width: 100%; cursor: pointer; }\n            #hb9id-morse-plugin textarea { width: 100%; height: 80px; padding: 10px; font-size: 16px; border: 1px solid #ccc; border-radius: 4px; resize: vertical; box-sizing: border-box; }\n            #hb9id-morse-plugin input[type=\"text\"] { width: 100%; padding: 10px; font-size: 16px; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; text-transform: uppercase; }\n            \n            #hb9id-morse-plugin .btn-group { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; }\n            #hb9id-morse-plugin button { flex: 1; min-width: 150px; background-color: #3498db; color: white; border: none; padding: 12px 15px; font-size: 16px; border-radius: 4px; cursor: pointer; text-align: center; font-weight: bold; }\n            #hb9id-morse-plugin button:hover { opacity: 0.85; }\n            #hb9id-morse-plugin button.action-btn { background-color: #2ecc71; }\n            #hb9id-morse-plugin button.stop-btn { background-color: #e74c3c; }\n            #hb9id-morse-plugin button.test-btn { background-color: #9b59b6; }\n            #hb9id-morse-plugin button:disabled { background-color: #95a5a6; cursor: not-allowed; }\n\n            #hb9id-morse-plugin .value-display { font-weight: normal; color: #555; float: right; }\n            #hb9id-morse-plugin #karaokeDisplay { font-family: monospace; font-size: 28px; background: #fff; padding: 15px; border: 2px solid #bdc3c7; border-radius: 6px; min-height: 40px; margin-bottom: 15px; text-align: center; letter-spacing: 2px; }\n            #hb9id-morse-plugin .highlight { background-color: #2ecc71 !important; color: white !important; border-radius: 4px; padding: 0 2px; }\n\n            #hb9id-morse-plugin .char-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(60px, 1fr)); gap: 10px; background: #fff; padding: 15px; border: 1px solid #ccc; border-radius: 4px; }\n            #hb9id-morse-plugin #testArea { display: none; background: #e8eaed; padding: 20px; border-radius: 6px; border: 2px dashed #9b59b6; margin-top: 20px; }\n            #hb9id-morse-plugin #countdownDisplay { font-size: 48px; font-weight: bold; text-align: center; color: #e74c3c; margin: 20px 0; }\n            #hb9id-morse-plugin #testResult { margin-top: 15px; padding: 10px; border-radius: 4px; font-weight: bold; }\n        <\/style>\n\n        <h1>Akkustischer Morsecode Trainer<\/h1>\n        <h5>von HB9INE f\u00fcr den Funkverein Iddaburg HB9ID (v.A03-BT-Fix)<\/h5>\n        \n        <div id=\"karaokeDisplay\">BEREIT...<\/div>\n\n        <div class=\"control-group\">\n            <label for=\"textInput\">Dein Text:<\/label>\n            <textarea id=\"textInput\">CQ CQ HB9INE CQ CQ HB9INE<\/textarea>\n        <\/div>\n\n        <div class=\"btn-group\">\n            <button class=\"action-btn\" onclick=\"playMorse()\">\u25b6 Abspielen<\/button>\n            <button class=\"stop-btn\" onclick=\"stopMorse()\">\u25a0 Stopp<\/button>\n        <\/div>\n\n        <div class=\"control-group\">\n            <label>Geschwindigkeit (WPM): <span class=\"value-display\" id=\"wpmVal\">20<\/span><\/label>\n            <input type=\"range\" id=\"wpm\" min=\"5\" max=\"40\" value=\"20\" oninput=\"document.getElementById('wpmVal').innerText = this.value\">\n        <\/div>\n        \n        <div class=\"control-group\">\n            <label>Frequenz (Hz): <span class=\"value-display\" id=\"freqVal\">550<\/span><\/label>\n            <input type=\"range\" id=\"freq\" min=\"450\" max=\"800\" value=\"550\" oninput=\"document.getElementById('freqVal').innerText = this.value\">\n        <\/div>\n\n        <div class=\"control-group\">\n            <label>Zeichen-Abstand: <span class=\"value-display\" id=\"charSpaceVal\">5<\/span><\/label>\n            <input type=\"range\" id=\"charSpace\" min=\"3\" max=\"15\" value=\"5\" oninput=\"document.getElementById('charSpaceVal').innerText = this.value\">\n        <\/div>\n\n        <div class=\"control-group\">\n            <label>Wort-Abstand: <span class=\"value-display\" id=\"wordSpaceVal\">10<\/span><\/label>\n            <input type=\"range\" id=\"wordSpace\" min=\"7\" max=\"25\" value=\"10\" oninput=\"document.getElementById('wordSpaceVal').innerText = this.value\">\n        <\/div>\n\n        <hr>\n\n        <h3>Trainings-Modus<\/h3>\n        <div class=\"control-group\">\n            <label>Max. Zeichen \/ Wort: <span class=\"value-display\" id=\"maxCharsVal\">5<\/span><\/label>\n            <input type=\"range\" id=\"maxChars\" min=\"1\" max=\"9\" value=\"5\" oninput=\"document.getElementById('maxCharsVal').innerText = this.value\">\n        <\/div>\n        <div class=\"control-group\">\n            <label>Anzahl W\u00f6rter: <span class=\"value-display\" id=\"numWordsVal\">8<\/span><\/label>\n            <input type=\"range\" id=\"numWords\" min=\"1\" max=\"20\" value=\"8\" oninput=\"document.getElementById('numWordsVal').innerText = this.value\">\n        <\/div>\n        \n        <div class=\"char-grid\" id=\"charSelection\"><\/div>\n        \n        <div class=\"btn-group\" style=\"margin-top:15px;\">\n            <button onclick=\"toggleAll(true)\">Alle<\/button>\n            <button onclick=\"toggleAll(false)\">Keine<\/button>\n            <button class=\"action-btn\" onclick=\"generateAndPlayTest()\">Generieren & Start<\/button>\n            <button class=\"test-btn\" id=\"startTestBtn\" onclick=\"startBlindTest()\">Blindtest starten<\/button>\n        <\/div>\n\n        <div id=\"testArea\">\n            <h3 style=\"color: #9b59b6; margin-top:0;\">Pr\u00fcfungsmodus<\/h3>\n            <div id=\"countdownDisplay\" style=\"display: none;\">7<\/div>\n            <div id=\"testInputArea\" style=\"display: none;\">\n                <input type=\"text\" id=\"userTestInput\" placeholder=\"Was hast du geh\u00f6rt?\" onkeypress=\"if(event.key==='Enter') checkTestAnswer()\">\n                <div class=\"btn-group\" style=\"margin-top: 15px;\">\n                    <button class=\"action-btn\" onclick=\"checkTestAnswer()\">\u2714 Pr\u00fcfen<\/button>\n                    <button class=\"stop-btn\" onclick=\"stopMorse()\">\u25a0 Abbruch<\/button>\n                <\/div>\n                <div id=\"testResult\"><\/div>\n            <\/div>\n        <\/div>\n\n        <script>\n        (function() {\n            const morseDict = {\n                'A': '.-', 'B': '-...', 'C': '-.-.', 'D': '-..', 'E': '.', 'F': '..-.',\n                'G': '--.', 'H': '....', 'I': '..', 'J': '.---', 'K': '-.-', 'L': '.-..',\n                'M': '--', 'N': '-.', 'O': '---', 'P': '.--.', 'Q': '--.-', 'R': '.-.',\n                'S': '...', 'T': '-', 'U': '..-', 'V': '...-', 'W': '.--', 'X': '-..-',\n                'Y': '-.--', 'Z': '--..', '1': '.----', '2': '..---', '3': '...--',\n                '4': '....-', '5': '.....', '6': '-....', '7': '--...', '8': '---..',\n                '9': '----.', '0': '-----', '\u00c4': '.-.-', '\u00d6': '---.', '\u00dc': '..--'\n            };\n\n            const wordList = [\"DER\", \"DIE\", \"DAS\", \"UND\", \"IST\", \"FUNK\", \"CQ\", \"73\", \"DX\", \"QTH\", \"NAME\", \"WATT\", \"YL\", \"OM\"];\n\n            let audioCtx = null;\n            let activeOscillators = [];\n            let animationFrameId = null;\n            let timings = [];\n            let isPlaying = false;\n            let hiddenTestText = \"\";\n            let countdownTimer = null;\n            let isBlindTestMode = false;\n\n            \/\/ UI Init\n            window.initCharSelection = function() {\n                const container = document.getElementById('charSelection');\n                if(!container) return;\n                container.innerHTML = '';\n                Object.keys(morseDict).forEach(char => {\n                    let div = document.createElement('div');\n                    div.style.display = 'flex';\n                    div.style.alignItems = 'center';\n                    div.innerHTML = `<input type=\"checkbox\" id=\"cb-${char}\" value=\"${char}\" checked style=\"margin-right:5px;\">\n                                     <label for=\"cb-${char}\" style=\"margin:0; font-weight:normal;\">${char}<\/label>`;\n                    container.appendChild(div);\n                });\n            };\n\n            window.toggleAll = function(state) {\n                document.querySelectorAll('#charSelection input[type=\"checkbox\"]').forEach(cb => cb.checked = state);\n            };\n\n            function playTone(startTime, duration, freq) {\n                if(!audioCtx) return;\n                const osc = audioCtx.createOscillator();\n                const gain = audioCtx.createGain();\n                osc.type = 'sine';\n                osc.frequency.value = freq;\n                gain.gain.setValueAtTime(0, startTime);\n                gain.gain.linearRampToValueAtTime(1, startTime + 0.01);\n                gain.gain.setValueAtTime(1, startTime + duration - 0.01);\n                gain.gain.linearRampToValueAtTime(0, startTime + duration);\n                osc.connect(gain);\n                gain.connect(audioCtx.destination);\n                osc.start(startTime);\n                osc.stop(startTime + duration);\n                activeOscillators.push(osc);\n            }\n\n            window.stopMorse = function() {\n                isPlaying = false;\n                if(animationFrameId) cancelAnimationFrame(animationFrameId);\n                if(countdownTimer) clearInterval(countdownTimer);\n                document.getElementById('countdownDisplay').style.display = 'none';\n                document.getElementById('startTestBtn').disabled = false;\n                activeOscillators.forEach(osc => { try { osc.stop(); } catch(e){} });\n                activeOscillators = [];\n                document.querySelectorAll('#karaokeDisplay span').forEach(s => s.classList.remove('highlight'));\n            };\n\n            window.playMorse = function(customText) {\n                stopMorse();\n                if (!audioCtx) audioCtx = new (window.AudioContext || window.webkitAudioContext)();\n                if (audioCtx.state === 'suspended') audioCtx.resume();\n\n                isBlindTestMode = (typeof customText === 'string');\n                const rawText = isBlindTestMode ? customText.toUpperCase() : document.getElementById('textInput').value.toUpperCase();\n                \n                let text = \"\";\n                for(let char of rawText) if(morseDict[char] || char === ' ') text += char;\n                \n                const display = document.getElementById('karaokeDisplay');\n                display.innerHTML = '';\n                if(isBlindTestMode) {\n                    display.innerHTML = '<span style=\"color:#9b59b6;\">[ PR\u00dcFUNG L\u00c4UFT... ]<\/span>';\n                } else {\n                    for(let i=0; i<text.length; i++) {\n                        let span = document.createElement('span');\n                        span.innerText = text[i] === ' ' ? '\\u00A0' : text[i];\n                        span.id = 'char-' + i;\n                        display.appendChild(span);\n                    }\n                }\n\n                const wpm = parseInt(document.getElementById('wpm').value);\n                const freq = parseInt(document.getElementById('freq').value);\n                const dot = 1.2 \/ wpm;\n                const cSpace = parseInt(document.getElementById('charSpace').value);\n                const wSpace = parseInt(document.getElementById('wordSpace').value);\n\n                \/\/ --- BLUETOOTH FIX: 1.2 Sekunden Vorlaufzeit ---\n                let currentTime = audioCtx.currentTime + 1.2;\n                timings = [];\n\n                for (let i = 0; i < text.length; i++) {\n                    const char = text[i];\n                    let start = currentTime;\n                    if (char === ' ') {\n                        currentTime += dot * (wSpace - cSpace);\n                        timings.push({ index: i, start: start, end: currentTime });\n                        continue;\n                    }\n                    const code = morseDict[char];\n                    if (code) {\n                        for (let s of code) {\n                            let d = (s === '.') ? dot : dot * 3;\n                            playTone(currentTime, d, freq);\n                            currentTime += d + dot;\n                        }\n                        currentTime += dot * (cSpace - 1);\n                        timings.push({ index: i, start: start, end: currentTime });\n                    }\n                }\n                isPlaying = true;\n                updateKaraoke();\n            };\n\n            function updateKaraoke() {\n                if (!isPlaying) return;\n                let now = audioCtx.currentTime;\n                let activeIdx = -1;\n                for (let t of timings) if (now >= t.start && now <= t.end) { activeIdx = t.index; break; }\n                \n                if(!isBlindTestMode) {\n                    let spans = document.getElementById('karaokeDisplay').children;\n                    for(let i=0; i<spans.length; i++) {\n                        if(i === activeIdx) spans[i].classList.add('highlight');\n                        else spans[i].classList.remove('highlight');\n                    }\n                }\n                if (timings.length > 0 && now > timings[timings.length-1].end) { isPlaying = false; return; }\n                animationFrameId = requestAnimationFrame(updateKaraoke);\n            }\n\n            window.generateAndPlayTest = function() {\n                const boxes = document.querySelectorAll('#charSelection input:checked');\n                const selected = Array.from(boxes).map(b => b.value);\n                if(!selected.length) return alert(\"W\u00e4hle Zeichen aus!\");\n                \n                const max = parseInt(document.getElementById('maxChars').value);\n                const num = parseInt(document.getElementById('numWords').value);\n                let words = [];\n                for(let i=0; i<num; i++) {\n                    let w = \"\"; for(let j=0; j<max; j++) w += selected[Math.floor(Math.random()*selected.length)];\n                    words.push(w);\n                }\n                document.getElementById('textInput').value = words.join(\" \");\n                playMorse();\n            };\n\n            window.startBlindTest = function() {\n                const boxes = document.querySelectorAll('#charSelection input:checked');\n                const selected = Array.from(boxes).map(b => b.value);\n                if(!selected.length) return;\n                \n                const max = parseInt(document.getElementById('maxChars').value);\n                const num = parseInt(document.getElementById('numWords').value);\n                let words = [];\n                for(let i=0; i<num; i++) {\n                    let w = \"\"; for(let j=0; j<max; j++) w += selected[Math.floor(Math.random()*selected.length)];\n                    words.push(w);\n                }\n                hiddenTestText = words.join(\" \");\n                \n                document.getElementById('testArea').style.display = 'block';\n                document.getElementById('testInputArea').style.display = 'none';\n                document.getElementById('testResult').innerHTML = '';\n                document.getElementById('userTestInput').value = '';\n                document.getElementById('startTestBtn').disabled = true;\n                \n                let count = 7;\n                const cd = document.getElementById('countdownDisplay');\n                cd.style.display = 'block';\n                cd.innerText = count;\n                \n                countdownTimer = setInterval(() => {\n                    count--;\n                    if(count > 0) cd.innerText = count;\n                    else if(count === 0) {\n                        cd.innerText = \"LOS!\";\n                        document.getElementById('testInputArea').style.display = 'block';\n                        document.getElementById('userTestInput').focus();\n                        playMorse(hiddenTestText);\n                    } else { clearInterval(countdownTimer); cd.style.display = 'none'; }\n                }, 1000);\n            };\n\n            window.checkTestAnswer = function() {\n                let u = document.getElementById('userTestInput').value.toUpperCase().trim();\n                let a = hiddenTestText.toUpperCase().trim();\n                let res = document.getElementById('testResult');\n                if(u === a) {\n                    res.style.background = '#d4edda'; res.style.color = '#155724'; res.innerHTML = \"\u2705 Richtig!\";\n                } else {\n                    res.style.background = '#f8d7da'; res.style.color = '#721c24'; res.innerHTML = \"\u274c Falsch! L\u00f6sung: \" + a;\n                }\n            };\n\n            initCharSelection();\n        })();\n        <\/script>\n    <\/div>\n    \n\n\n\n<p class=\"wp-block-paragraph\">(c) by HB9INE<\/p>\n","protected":false},"excerpt":{"rendered":"<p>(c) by HB9INE<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-2946","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/archiv-24-26.hb9id.ch\/index.php\/wp-json\/wp\/v2\/pages\/2946","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/archiv-24-26.hb9id.ch\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/archiv-24-26.hb9id.ch\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/archiv-24-26.hb9id.ch\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/archiv-24-26.hb9id.ch\/index.php\/wp-json\/wp\/v2\/comments?post=2946"}],"version-history":[{"count":4,"href":"https:\/\/archiv-24-26.hb9id.ch\/index.php\/wp-json\/wp\/v2\/pages\/2946\/revisions"}],"predecessor-version":[{"id":2952,"href":"https:\/\/archiv-24-26.hb9id.ch\/index.php\/wp-json\/wp\/v2\/pages\/2946\/revisions\/2952"}],"wp:attachment":[{"href":"https:\/\/archiv-24-26.hb9id.ch\/index.php\/wp-json\/wp\/v2\/media?parent=2946"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}