N Nam Hoai Dat Motech.ksmart.com.es

Amazon Music and Alexa: Metadata That Voice Search Can Hear

How Alexa resolves a spoken request for your song, which metadata fields it reads, and the naming mistakes that make a speaker play the wrong track.

🇻🇳 Đọc bài viết này bằng Tiếng Việt nguyên bản: Đọc bản Tiếng Việt →

Spoken search is stricter than typed search, and that difference is where most releases quietly fail. When a listener types, the app shows a list and lets them pick; when they speak, the speaker has to commit to one answer within a second or admit it has nothing. Your metadata is the only thing it has to go on.

This is what the assistant actually matches against, and how to stop it from choosing someone else's song.

Typed search and spoken search do not match the same way

Typing is forgiving. Half a title is enough, the interface shows ten candidates, and the listener scrolls until they recognise cover art. Voice has no list to scroll, so the system works from the words as they were said: a short title, an artist name, maybe an album, and whatever the listener bothered to add. The usual utterances are brutally simple — "play that song", "play ", "play <title> by <artist>" — and each extra clause is a filter your metadata either passes or fails.</p> <h2 id="how-alexa-resolves-play-that-song-by-her">How Alexa resolves "play that song by her"</h2> <p>The request is compared against the music catalogue your distributor delivered: track titles, artist names, album titles, playlist names, and the credits attached to each. If your title is one of a hundred songs called "Sunrise", the artist clause is the only thing that breaks the tie, which means the artist field has to match the string attached to your profile exactly. Features are the weak point. A credit written as two names joined by a comma reads differently from the way a person says it out loud, and version text sitting inside the title ("Live", "Remix") often gets treated as part of the name rather than as a descriptor.</p><div class="ad-wrap"><a href='https://music.ksmart.com.es/' style='display:flex;align-items:center;gap:16px;width:100%;padding:16px 22px;border-radius:18px;background:linear-gradient(120deg,rgba(0,235,255,.14),rgba(0,229,117,.10));border:1px solid rgba(0,235,255,.35);color:inherit;text-decoration:none;box-sizing:border-box'><span style='width:44px;height:44px;border-radius:12px;background:linear-gradient(135deg,#00EBFF,#00E575);color:#070B11;display:flex;align-items:center;justify-content:center;font-weight:800;font-size:18px;flex-shrink:0'>M</span><span style='flex:1;min-width:0'><b style='display:block;font-size:15.5px;color:var(--head,#F8FAFC)'>Ksmart Music — Dự án âm nhạc AI</b><span style='font-size:13.5px;color:var(--muted,#94A3B8)'>Album AI 5 ngôn ngữ · stream miễn phí trên music.ksmart.com.es</span></span><span style='font-weight:700;font-size:14px;color:var(--cyan,#00EBFF);white-space:nowrap'>Nghe ngay →</span></a></div> <h2 id="the-metadata-fields-that-decide-the-match">The metadata fields that decide the match</h2> <table> <thead> <tr> <th>Field</th> <th>What it should contain</th> </tr> </thead> <tbody> <tr> <td>Track title</td> <td>The song name only, no version text</td> </tr> <tr> <td>Artist</td> <td>The exact name on your artist profile</td> </tr> <tr> <td>Featuring</td> <td>Credited artists in the proper credit field</td> </tr> <tr> <td>Album</td> <td>A stable album name, not a campaign slogan</td> </tr> <tr> <td>Language and flag</td> <td>Correct language, explicit flag set honestly</td> </tr> </tbody> </table> <p>Symbols, emoji and decorative punctuation in any of these fields give the matcher something it cannot pronounce. The same applies to your artist name: if it is spelled one way on the profile and another way in the delivery, the two never link.</p> <h2 id="testing-your-own-release-on-a-speaker">Testing your own release on a speaker</h2> <ol> <li>Ask for the title alone, then the title plus your artist name.</li> <li>Ask for the album by name.</li> <li>Ask for it inside a playlist you control.</li> <li>Compare all three with typed search in the phone app.</li> </ol> <p>If voice returns something else entirely, write down exactly what it played. That wrong answer tells you which field is ambiguous: wrong artist means the credit is malformed, wrong version means version text leaked into the title, and no result at all usually means ingestion has not finished.</p> <h2 id="metadata-mistakes-that-break-voice-playback">Metadata mistakes that break voice playback</h2> <p>The failures I see repeatedly are all administrative: version text folded into the title field, featured artists crammed into the title instead of the credit field, an artist name that changes spelling between releases, duplicated releases fighting over the same identifiers, and an explicit flag set wrong so household filters silently drop the track. Every one of these is invisible in a dashboard preview and obvious the moment you say the command out loud.</p> <h2 id="pre-release-checklist-for-amazon-music">Pre-release checklist for Amazon Music</h2> <ol> <li>Fix one spelling of your artist name and use it everywhere.</li> <li>Keep the title field free of version and campaign text.</li> <li>Put features in the credit field, not in the title.</li> <li>Claim your artist profile so the catalogue links to you.</li> <li>Run the three voice tests after ingestion, not before.</li> </ol> <p>Voice interfaces reward plain, boring, consistent metadata. Nobody has ever corrected a speaker by arguing with it — you fix the data it read.</p> <p>— <em>Nam Hoai (Nam Hoài Đất Mỏ)</em></p></div> <div class="post-tags"><a href="/tag/tech/">#tech</a></div> <div class="share-row"> <span class="share-label">Share Article</span> <a class="share-btn fb" target="_blank" rel="noopener" href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Ftech.ksmart.com.es%2Fposts%2Fdsp-real-07-amazon-music-alexa-voice-optimization%2F">Facebook</a> <a class="share-btn zalo" target="_blank" rel="noopener" href="https://social.zalo.me/share?link=https%3A%2F%2Ftech.ksmart.com.es%2Fposts%2Fdsp-real-07-amazon-music-alexa-voice-optimization%2F">Zalo</a> <a class="share-btn tg" target="_blank" rel="noopener" href="https://t.me/share/url?url=https%3A%2F%2Ftech.ksmart.com.es%2Fposts%2Fdsp-real-07-amazon-music-alexa-voice-optimization%2F&text=Amazon%20Music%20and%20Alexa%3A%20Metadata%20That%20Voice%20Search%20Can%20Hear">Telegram</a> <a class="share-btn x" target="_blank" rel="noopener" href="https://twitter.com/intent/tweet?url=https%3A%2F%2Ftech.ksmart.com.es%2Fposts%2Fdsp-real-07-amazon-music-alexa-voice-optimization%2F&text=Amazon%20Music%20and%20Alexa%3A%20Metadata%20That%20Voice%20Search%20Can%20Hear">X</a> <button class="share-btn copy" type="button" data-copy="https://tech.ksmart.com.es/posts/dsp-real-07-amazon-music-alexa-voice-optimization/">Copy link</button> </div> <div class="author-box"><div class="ava">N</div><div> <strong>Nam Hoai Dat Mo</strong> <div class="spec">AI & DATA ENGINEERING</div> <p>AI & Data enthusiast who loves explaining complex tech in plain English. Sharing practical tool reviews, prompt guides, and digital creation workflows.</p> </div></div> <aside class="series-nav" aria-label="Dsp Real"><div class="series-head">Series: Dsp Real — Part 7/10</div><div class="series-links"><a class="s-prev" href="/posts/dsp-real-06-tidal-hifi-flac-streaming-specs/"><span>← Previous in series</span><b>TIDAL Delivery Specs and Where Your Master Actually Ends Up</b></a><a class="s-next" href="/posts/dsp-real-08-deezer-flow-regional-dsp-licensing/"><span>Next in series →</span><b>Regional DSPs: Deezer Flow, Boomplay and Anghami Explained</b></a></div><div class="series-parts"><a href="/posts/dsp-real-01-apple-music-lossless-spatial-audio/" title="Apple Music Delivery: Lossless, Digital Masters, Spatial">1</a><a href="/posts/dsp-real-02-youtube-oac-channel-merging/" title="Get A YouTube Official Artist Channel And Merge Topic Tracks">2</a><a href="/posts/dsp-real-03-tiktok-sound-distribution-cut-timing/" title="Set The Perfect Cut Point For TikTok And Instagram">3</a><a href="/posts/dsp-real-04-instagram-music-stickers-troubleshooting/" title="Why Your Song Is Missing From Instagram Music Stickers">4</a><a href="/posts/dsp-real-05-shazam-recognition-database-sync/" title="How Shazam Recognizes Your Track: Fingerprint Delivery">5</a><a href="/posts/dsp-real-06-tidal-hifi-flac-streaming-specs/" title="TIDAL Delivery Specs and Where Your Master Actually Ends Up">6</a><a class="cur" href="/posts/dsp-real-07-amazon-music-alexa-voice-optimization/">7</a><a href="/posts/dsp-real-08-deezer-flow-regional-dsp-licensing/" title="Regional DSPs: Deezer Flow, Boomplay and Anghami Explained">8</a><a href="/posts/dsp-real-09-asian-dsp-distribution-netease-qq/" title="Selling Music in China: NetEase, QQ Music, Kugou and Kuwo">9</a><a href="/posts/dsp-real-10-beatport-traxsource-electronic-release/" title="Electronic Releases on Beatport, Traxsource and Juno">10</a></div></aside> <div class="pager"><a href="/posts/dsp-real-06-tidal-hifi-flac-streaming-specs/"><div class="lbl">← Newer Post</div><div class="t">TIDAL Delivery Specs and Where Your Master Actually Ends Up</div></a><a class="next" href="/posts/dsp-real-08-deezer-flow-regional-dsp-licensing/"><div class="lbl">Older Post →</div><div class="t">Regional DSPs: Deezer Flow, Boomplay and Anghami Explained</div></a></div> <div class="ad-wrap"><a href='https://music.ksmart.com.es/' style='display:flex;align-items:center;gap:16px;width:100%;padding:16px 22px;border-radius:18px;background:linear-gradient(120deg,rgba(0,235,255,.14),rgba(0,229,117,.10));border:1px solid rgba(0,235,255,.35);color:inherit;text-decoration:none;box-sizing:border-box'><span style='width:44px;height:44px;border-radius:12px;background:linear-gradient(135deg,#00EBFF,#00E575);color:#070B11;display:flex;align-items:center;justify-content:center;font-weight:800;font-size:18px;flex-shrink:0'>M</span><span style='flex:1;min-width:0'><b style='display:block;font-size:15.5px;color:var(--head,#F8FAFC)'>Ksmart Music — Dự án âm nhạc AI</b><span style='font-size:13.5px;color:var(--muted,#94A3B8)'>Album AI 5 ngôn ngữ · stream miễn phí trên music.ksmart.com.es</span></span><span style='font-weight:700;font-size:14px;color:var(--cyan,#00EBFF);white-space:nowrap'>Nghe ngay →</span></a></div> </article> <aside class="sidebar"><div class="ad-wrap"><a href='/posts/metas-muse-nhan-1-ty-token/' style='display:block;width:100%;padding:20px 18px;border-radius:18px;background:linear-gradient(160deg,rgba(0,235,255,.12),rgba(167,139,250,.10));border:1px solid rgba(0,235,255,.35);color:inherit;text-decoration:none;box-sizing:border-box'><div style='font-family:JetBrains Mono,monospace;font-size:10.5px;letter-spacing:.18em;color:var(--emerald,#00E575);text-transform:uppercase'>PR · META MUSE</div><div style='font-weight:800;font-size:18.5px;line-height:1.3;margin-top:10px;color:var(--head,#F8FAFC);font-family:Space Grotesk,sans-serif'>Nhận 1 tỷ token Muse AI miễn phí</div><div style='font-size:13.5px;line-height:1.6;margin-top:8px;color:var(--muted,#94A3B8)'>Không fake IP, không add thẻ. Hướng dẫn 4 bước.</div><div style='margin-top:14px;background:#0A0F18;border:1px dashed rgba(0,235,255,.5);border-radius:12px;padding:10px 12px;text-align:center'><div style='font-size:10px;color:#94A3B8;letter-spacing:.14em'>MÃ REDEEM</div><div style='font-family:JetBrains Mono,monospace;font-size:20px;font-weight:600;color:#00EBFF;letter-spacing:.2em;margin-top:4px'>D0IWUW</div></div><div style='margin-top:12px;font-size:13.5px;font-weight:700;color:#00EBFF;text-align:center'>Xem hướng dẫn →</div></a></div><div class="ad-wrap"><a href='https://distrokid.com/vip/seven/13561145' target='_blank' rel='noopener' style='display:block;width:100%;padding:20px 18px;border-radius:18px;background:linear-gradient(160deg,rgba(251,191,36,.14),rgba(0,235,255,.08));border:1px solid rgba(251,191,36,.4);color:inherit;text-decoration:none;box-sizing:border-box'><div style='font-family:JetBrains Mono,monospace;font-size:10.5px;letter-spacing:.18em;color:var(--gold,#FBBF24);text-transform:uppercase'>DISTROKID · ĐỐI TÁC VIP</div><div style='font-weight:800;font-size:18.5px;line-height:1.3;margin-top:10px;color:var(--head,#F8FAFC);font-family:Space Grotesk,sans-serif'>Phát hành nhạc số quốc tế</div><div style='font-size:13.5px;line-height:1.6;margin-top:8px;color:var(--muted,#94A3B8)'>Đưa nhạc lên Spotify, Apple Music, TikTok giữ 100% tiền bản quyền.</div><div style='margin-top:14px;background:#0A0F18;border:1px dashed rgba(251,191,36,.55);border-radius:12px;padding:10px 12px;text-align:center'><div style='font-size:10px;color:#94A3B8;letter-spacing:.14em'>ƯU ĐÃI THÀNH VIÊN</div><div style='font-family:JetBrains Mono,monospace;font-size:18px;font-weight:700;color:#FBBF24;letter-spacing:.12em;margin-top:4px'>GIẢM 7% — 50%</div></div><div style='margin-top:12px;font-size:13.5px;font-weight:700;color:#FBBF24;text-align:center'>Đăng ký nhận ưu đãi →</div></a></div><div class="sidebar-sec"><div class="sidebar-title">Table of Contents</div><div class="toc"> <ul> <li><a href="#typed-search-and-spoken-search-do-not-match-the-same-way">Typed search and spoken search do not match the same way</a></li> <li><a href="#how-alexa-resolves-play-that-song-by-her">How Alexa resolves "play that song by her"</a></li> <li><a href="#the-metadata-fields-that-decide-the-match">The metadata fields that decide the match</a></li> <li><a href="#testing-your-own-release-on-a-speaker">Testing your own release on a speaker</a></li> <li><a href="#metadata-mistakes-that-break-voice-playback">Metadata mistakes that break voice playback</a></li> <li><a href="#pre-release-checklist-for-amazon-music">Pre-release checklist for Amazon Music</a></li> </ul> </div></div><div class="sidebar-sec"><div class="sidebar-title">Related Articles</div><div class="mini-list"><a href="/posts/ai-sound-01-eliminating-high-frequency-mush/">Removing Harsh High-Frequency Mud From AI Audio Stems<span class="d">Oct 01, 2026 · 3 min read</span></a><a href="/posts/ai-sound-02-fixing-sudden-vocal-cutoffs/">Fixing Abrupt Endings and Sudden Vocal Cutoffs<span class="d">Oct 01, 2026 · 3 min read</span></a><a href="/posts/ai-sound-03-multi-language-pronunciation-tricks/">Phonetic Spelling Tricks for Non-English AI Vocals<span class="d">Oct 01, 2026 · 4 min read</span></a></div></div><div class="sidebar-sec"><div class="sidebar-title">Topics</div><div class="mini-tags"><a href="/tag/tech/">#tech</a><a href="/tag/ai/">#ai</a><a href="/tag/data/">#data</a><a href="/tag/programming/">#programming</a><a href="/tag/cloud/">#cloud</a><a href="/tag/tips/">#tips</a><a href="/tag/opensource/">#opensource</a><a href="/tag/review/">#review</a><a href="/tag/software/">#software</a><a href="/tag/release/">#release</a><a href="/tag/bestmusic/">#bestmusic</a><a href="/tag/thumbnail/">#thumbnail</a><a href="/tag/copyright/">#copyright</a><a href="/tag/prompting/">#prompting</a><a href="/tag/vocal/">#vocal</a><a href="/tag/workflow/">#workflow</a><a href="/tag/troubleshoot/">#troubleshoot</a><a href="/tag/monetize/">#monetize</a><a href="/tag/mureka/">#mureka</a><a href="/tag/udio/">#udio</a><a href="/tag/googlemusic/">#googlemusic</a><a href="/tag/promotion/">#promotion</a><a href="/tag/minimax/">#minimax</a><a href="/tag/yuemusic/">#yuemusic</a><a href="/tag/acestep/">#acestep</a></div></div></aside> </div> <footer class="site"><div class="wrap"> <div class="foot-top"> <nav class="foot-nav"> <a class="hide-sm" href="/">Home</a><a class="hide-sm" href="/#topics">Topics</a><a class="hide-sm" href="/rss.xml">RSS</a><a href="/#about">About</a> </nav> <div class="mini-tags foot-tags"><a href="/tag/acestep/">ACE-Step AI</a><a href="/tag/yuemusic/">YuE AI Music</a><a href="/tag/minimax/">MiniMax Music</a><a href="/tag/promotion/">Music Outreach</a><a href="/tag/googlemusic/">Google Music</a><a href="/tag/udio/">Udio AI</a><a href="/tag/mureka/">Mureka AI</a><a href="/tag/copyright/">Copyright Guide</a><a href="/tag/thumbnail/">Thumbnail Design</a><a href="/tag/bestmusic/">Suno Creation</a><a href="/tag/prompting/">Prompt Engineering</a><a href="/tag/vocal/">AI Vocals</a><a href="/tag/workflow/">Workflows</a><a href="/tag/troubleshoot/">Troubleshooting</a><a href="/tag/monetize/">Monetization</a><a href="/tag/release/">Music Release</a><a href="https://www.youtube.com/@ksmartmusic">Video Channel</a><a href="/tag/tips/">Practical Tips</a><a href="https://music.ksmart.com.es/">Audio Hub</a><a href="#about">About Me</a></div> </div> <div class="foot-bottom"> <span>© 2026 Nam Hoai Dat Mo — personal tech blog & practical engineering notes</span> <span class="mono"><a href="rss.xml">RSS</a> · <a href="/sitemap.xml">Sitemap</a> · <a href="https://tech.ksmart.com.es/">tech.ksmart.com.es</a></span> </div> </div></footer> <script> var LANG_MAP = { en: { code: "en", label: "EN", flag: "🇺🇸", name: "English" }, vi: { code: "vi", label: "VI", flag: "🇻🇳", name: "Tiếng Việt" }, "zh-CN": { code: "zh-CN", label: "ZH", flag: "🇨🇳", name: "中文" }, ja: { code: "ja", label: "JA", flag: "🇯🇵", name: "日本語" }, ko: { code: "ko", label: "KO", flag: "🇰🇷", name: "한국어" }, es: { code: "es", label: "ES", flag: "🇪🇸", name: "Español" }, fr: { code: "fr", label: "FR", flag: "🇫🇷", name: "Français" }, de: { code: "de", label: "DE", flag: "🇩🇪", name: "Deutsch" }, ru: { code: "ru", label: "RU", flag: "🇷🇺", name: "Русский" }, pt: { code: "pt", label: "PT", flag: "🇵🇹", name: "Português" }, id: { code: "id", label: "ID", flag: "🇮🇩", name: "Bahasa Indo" }, th: { code: "th", label: "TH", flag: "🇹🇭", name: "ภาษาไทย" } }; function clearGoogleTranslateCookie() { var domain = window.location.hostname; document.cookie = 'googtrans=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'; document.cookie = 'googtrans=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/; domain=' + domain + ';'; document.cookie = 'googtrans=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/; domain=.' + domain + ';'; var parts = domain.split('.'); if (parts.length > 2) { var rootDomain = parts.slice(1).join('.'); document.cookie = 'googtrans=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/; domain=.' + rootDomain + ';'; } } function googleTranslateElementInit() { new google.translate.TranslateElement({ pageLanguage: 'en', includedLanguages: 'en,vi,zh-CN,ja,ko,es,fr,de,ru,pt,id,th', autoDisplay: false }, 'google_translate_element'); } function triggerTranslate(targetLang) { var googleCombo = document.querySelector('.goog-te-combo'); if (googleCombo) { googleCombo.value = (targetLang === 'en' || targetLang === 'vi') ? '' : targetLang; googleCombo.dispatchEvent(new Event('change')); } } function applyOtherLang(targetLang) { try { localStorage.setItem('site_lang', targetLang); } catch(e){} if (targetLang === 'en' || targetLang === 'vi') { clearGoogleTranslateCookie(); triggerTranslate(targetLang); return; } if (!window.google || !window.google.translate) { var s = document.createElement('script'); s.src = 'https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit'; s.async = true; document.body.appendChild(s); var checkTimer = setInterval(function(){ var combo = document.querySelector('.goog-te-combo'); if (combo) { clearInterval(checkTimer); triggerTranslate(targetLang); } }, 250); } else { triggerTranslate(targetLang); } } function initGridPaginationAndSearch(isVi) { var grid = document.getElementById('posts-grid'); if (!grid) return; var allCards = Array.from(grid.querySelectorAll('.post-item')); var searchInput = document.getElementById('search-input'); var searchClear = document.getElementById('search-clear'); var searchStats = document.getElementById('search-stats'); var searchCountText = document.getElementById('search-count-text'); var searchEmpty = document.getElementById('search-empty'); var loadMoreBtn = document.getElementById('load-more-btn'); var sentinel = document.getElementById('scroll-sentinel'); var PAGE_SIZE = 30; var currentVisibleCount = 0; var activeCards = allCards.slice(); function stripVn(s) { if (!s) return ''; return s.normalize('NFD').replace(/[̀-ͯ]/g, '').toLowerCase().replace(/đ/g, 'd').replace(/Đ/g, 'd'); } function updateButtonUI() { var total = activeCards.length; if (loadMoreBtn) { if (total === 0) { loadMoreBtn.style.display = 'none'; } else if (currentVisibleCount >= total) { loadMoreBtn.style.display = 'inline-flex'; loadMoreBtn.classList.add('is-disabled'); loadMoreBtn.innerHTML = '<span>' + (isVi ? ('Đã hiển thị toàn bộ ' + total + ' bài viết ✓') : ('All ' + total + ' articles displayed ✓')) + '</span>'; } else { loadMoreBtn.style.display = 'inline-flex'; loadMoreBtn.classList.remove('is-disabled'); loadMoreBtn.innerHTML = '<span>' + (isVi ? ('Xem thêm bài viết (' + currentVisibleCount + ' / ' + total + ')') : ('Load more articles (' + currentVisibleCount + ' / ' + total + ')')) + '</span> ↓'; } } if (searchStats && searchCountText && searchInput && searchInput.value.trim()) { searchCountText.textContent = isVi ? ('Tìm thấy ' + activeCards.length + ' bài viết phù hợp') : ('Found ' + activeCards.length + ' matching articles'); } } function renderBatch() { var total = activeCards.length; var nextCount = Math.min(currentVisibleCount + PAGE_SIZE, total); allCards.forEach(function(c) { c.classList.remove('is-visible'); c.classList.add('is-hidden'); }); for (var i = 0; i < nextCount; i++) { activeCards[i].classList.remove('is-hidden'); activeCards[i].classList.add('is-visible'); } currentVisibleCount = nextCount; if (searchEmpty) { searchEmpty.style.display = total === 0 ? 'block' : 'none'; } updateButtonUI(); } function applySearch(query) { var q = stripVn(query.trim()); var featured = document.querySelector('.featured'); var latestSec = document.querySelector('.sec-latest'); var picksSec = document.querySelector('.sec-picks'); var trendingSec = document.querySelector('.sec-trending'); var allPostsSec = document.getElementById('all-posts'); if (!q) { activeCards = allCards.slice(); if (searchStats) searchStats.style.display = 'none'; if (searchClear) searchClear.style.display = 'none'; if (featured) featured.style.display = ''; if (latestSec) latestSec.style.display = ''; if (picksSec) picksSec.style.display = ''; if (trendingSec) trendingSec.style.display = ''; } else { activeCards = allCards.filter(function(card) { var t = card.getAttribute('data-title') || ''; var e = card.getAttribute('data-excerpt') || ''; var tags = card.getAttribute('data-tags') || ''; return t.indexOf(q) !== -1 || e.indexOf(q) !== -1 || tags.indexOf(q) !== -1; }); if (searchStats) { searchStats.style.display = 'flex'; if (searchCountText) { searchCountText.textContent = isVi ? ('Tìm thấy ' + activeCards.length + ' bài viết phù hợp') : ('Found ' + activeCards.length + ' matching articles'); } } if (searchClear) searchClear.style.display = 'inline-block'; if (featured) featured.style.display = 'none'; if (latestSec) latestSec.style.display = 'none'; if (picksSec) picksSec.style.display = 'none'; if (trendingSec) trendingSec.style.display = 'none'; if (allPostsSec) { allPostsSec.scrollIntoView({ behavior: 'smooth', block: 'start' }); } } currentVisibleCount = 0; renderBatch(); } renderBatch(); if (searchInput) { searchInput.addEventListener('input', function() { applySearch(this.value); }); } if (searchClear) { searchClear.addEventListener('click', function() { if (searchInput) { searchInput.value = ''; searchInput.focus(); } applySearch(''); }); } if (loadMoreBtn) { loadMoreBtn.addEventListener('click', function() { if (currentVisibleCount < activeCards.length) { renderBatch(); } }); } } document.addEventListener('DOMContentLoaded',function(){ var isVi = document.documentElement.lang === 'vi'; var btn = document.getElementById('theme-btn'); if (btn) { btn.addEventListener('click',function(){ var d = document.documentElement; var next = d.getAttribute('data-theme') === 'light' ? 'dark' : 'light'; d.setAttribute('data-theme', next); try { localStorage.setItem('theme', next); } catch(e){} btn.textContent = next === 'light' ? '☀' : '☾'; }); btn.textContent = document.documentElement.getAttribute('data-theme') === 'light' ? '☀' : '☾'; } var langBtn = document.getElementById('lang-btn'); var langMenu = document.getElementById('lang-menu'); if (langBtn && langMenu) { langBtn.addEventListener('click', function(e){ e.stopPropagation(); langMenu.classList.toggle('show'); }); document.addEventListener('click', function(){ langMenu.classList.remove('show'); }); document.querySelectorAll('.lang-item[data-trans]').forEach(function(item){ item.addEventListener('click', function(){ var l = this.getAttribute('data-lang'); applyOtherLang(l); langMenu.classList.remove('show'); }); }); document.querySelectorAll('.lang-item[href]').forEach(function(a){ a.addEventListener('click', function(){ var p = new URL(a.href, location.href).pathname; var v = (p === '/vi' || p.indexOf('/vi/') === 0) ? 'vi' : 'en'; document.cookie = 'lang=' + v + '; Path=/; Max-Age=31536000; SameSite=Lax'; }); }); } initGridPaginationAndSearch(isVi); var bar = document.getElementById('progress'); if (bar) { window.addEventListener('scroll', function(){ var h = document.documentElement.scrollHeight - innerHeight; bar.style.width = (h > 0 ? (scrollY / h * 100) : 0) + '%'; }, {passive: true}); } document.querySelectorAll('.prose pre').forEach(function(pre){ if (pre.querySelector('.copy-btn')) return; var b = document.createElement('button'); b.className = 'copy-btn'; b.textContent = 'copy'; b.addEventListener('click', function(){ var code = pre.querySelector('code'); if (!code) return; navigator.clipboard.writeText(code.innerText).then(function(){ b.textContent = 'copied ✓'; setTimeout(function(){ b.textContent = 'copy'; }, 1500); }); }); pre.appendChild(b); }); document.querySelectorAll('[data-copy]').forEach(function(b){ b.addEventListener('click', function(){ navigator.clipboard.writeText(b.getAttribute('data-copy')).then(function(){ var o = b.textContent; b.textContent = isVi ? 'Đã copy ✓' : 'Copied ✓'; setTimeout(function(){ b.textContent = o; }, 1500); }); }); }); }); </script> </body> </html>