Aichatbot12321 commited on
Commit
c5efb50
Β·
verified Β·
1 Parent(s): 6ce6df1

Update search.html via HF Space Commander

Browse files
Files changed (1) hide show
  1. search.html +817 -47
search.html CHANGED
@@ -1150,6 +1150,7 @@ body html mjx-container[jax="CHTML"][display="true"]::-webkit-scrollbar-thumb {
1150
  <button class="menu-item" onclick="togglePdfCompMode()">πŸ“‰ PDF Compressor</button>
1151
  <button class="menu-item" onclick="toggleEditImageMode()">πŸ–ŒοΈ Edit Image</button>
1152
  <button class="menu-item" onclick="mtOpen('qr')">πŸ”³ QR Code Maker</button>
 
1153
  </div>
1154
  </div>
1155
 
@@ -10177,7 +10178,8 @@ window.__quizMemo = function(answerHtml){
10177
  function start(txt){
10178
  if (txt.dataset.w) return; txt.dataset.w = '1';
10179
  if (!txt.animate) return;
10180
- var base = getComputedStyle(txt).color, hi = accent();
 
10181
  var words = wrap(txt), n = words.length; if (!n) return;
10182
  var D = (n - 1) * STEP + PEAK + REST; // wave length + 0.5 s rest
10183
  words.forEach(function(el, i){
@@ -10189,7 +10191,7 @@ window.__quizMemo = function(answerHtml){
10189
  ], { duration: D * 1000, delay: i * STEP * 1000, iterations: Infinity, easing: 'linear' });
10190
  });
10191
  }
10192
- function scan(){ document.querySelectorAll('.tk-step.active .tk-txt:not([data-w])').forEach(start); }
10193
  function init(){ new MutationObserver(scan).observe(document.body, { childList: true, subtree: true }); scan(); }
10194
  if (document.body) init(); else document.addEventListener('DOMContentLoaded', init);
10195
  })();
@@ -17600,54 +17602,29 @@ body.ai-dark-thinking .fill-empty-fill {
17600
  display: none !important;
17601
  }
17602
 
17603
- /* Flashing Live Thinking Summary Heading shown directly below "Thinking" */
17604
- @keyframes tkHeadingFlashShimmer {
17605
- 0% { background-position: -220% 0; opacity: 0.72; }
17606
- 50% { background-position: 0% 0; opacity: 1; }
17607
- 100% { background-position: 220% 0; opacity: 0.72; }
17608
- }
17609
- @keyframes tkWordFlashIn {
17610
- 0% { opacity: 0.15; filter: brightness(1.9); transform: translateY(2px); }
17611
- 45% { opacity: 1; filter: brightness(1.45); transform: translateY(0); }
17612
- 100% { opacity: 1; filter: brightness(1); transform: translateY(0); }
17613
- }
17614
  @keyframes tkCursorBlink {
17615
  0%, 49% { opacity: 1; }
17616
  50%, 100% { opacity: 0; }
17617
  }
17618
  .tk-live-heading-flash {
17619
- margin: 5px 0 4px 22px;
17620
- padding: 5px 10px;
17621
- border-radius: 8px;
17622
- background: rgba(59, 130, 246, 0.11);
17623
- border: 1px solid rgba(59, 130, 246, 0.28);
17624
- font-size: 12.5px;
17625
- font-weight: 800;
17626
- line-height: 1.4;
17627
- display: flex;
17628
- align-items: center;
17629
- gap: 6px;
17630
- flex-wrap: wrap;
17631
- }
17632
- .tk-live-heading-flash-text {
17633
- background: linear-gradient(90deg, var(--primary, #3b82f6) 0%, #60a5fa 28%, #ffffff 50%, #60a5fa 72%, var(--primary, #3b82f6) 100%);
17634
- background-size: 240% 100%;
17635
- -webkit-background-clip: text;
17636
- background-clip: text;
17637
- color: transparent;
17638
- animation: tkHeadingFlashShimmer 1.65s linear infinite;
17639
- display: inline-flex;
17640
- flex-wrap: wrap;
17641
- gap: 4px;
17642
  }
17643
- .tk-flash-word {
17644
- display: inline-block;
17645
- animation: tkWordFlashIn 0.48s ease-out both;
17646
  }
17647
  .tk-stream-cursor {
17648
  display: inline-block;
17649
  margin-left: 2px;
17650
- color: var(--primary, #3b82f6);
17651
  font-weight: 900;
17652
  animation: tkCursorBlink 0.75s step-end infinite;
17653
  }
@@ -18407,15 +18384,12 @@ body.ai-dark-thinking .fill-empty-fill {
18407
  if (thoughtsText) {
18408
  const latestHeading = extractHeading(thoughtsText);
18409
  if (latestHeading) {
18410
- headingBox.style.display = "flex";
18411
  if (headingBox.dataset.lastHeading !== latestHeading) {
18412
  headingBox.dataset.lastHeading = latestHeading;
18413
- const safeWords = latestHeading
18414
- .replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;")
18415
- .split(/\s+/).filter(Boolean)
18416
- .map((w, idx) => `<span class="tk-flash-word" style="animation-delay:${Math.min(idx * 55, 450)}ms">${w}</span>`)
18417
- .join(" ");
18418
- headingBox.innerHTML = `<span style="font-size:12px;">✨</span><span class="tk-live-heading-flash-text">${safeWords}</span>`;
18419
  }
18420
  }
18421
  underBox.innerHTML = window.formatThinkingHtmlWithBold(thoughtsText) + `<span class="tk-stream-cursor">▍</span>`;
@@ -19646,5 +19620,801 @@ body.ai-dark-thinking .fill-empty-fill {
19646
  })();
19647
  </script>
19648
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19649
  </body>
19650
  </html>
 
1150
  <button class="menu-item" onclick="togglePdfCompMode()">πŸ“‰ PDF Compressor</button>
1151
  <button class="menu-item" onclick="toggleEditImageMode()">πŸ–ŒοΈ Edit Image</button>
1152
  <button class="menu-item" onclick="mtOpen('qr')">πŸ”³ QR Code Maker</button>
1153
+ <button class="menu-item" onclick="openAiAudioDownloaderModal()" style="color:#10b981; font-weight:800;">🎡 AI Downloader</button>
1154
  </div>
1155
  </div>
1156
 
 
10178
  function start(txt){
10179
  if (txt.dataset.w) return; txt.dataset.w = '1';
10180
  if (!txt.animate) return;
10181
+ var base = getComputedStyle(txt).color;
10182
+ var hi = txt.closest('.tk-live-heading-flash') ? '#8b5cf6' : accent();
10183
  var words = wrap(txt), n = words.length; if (!n) return;
10184
  var D = (n - 1) * STEP + PEAK + REST; // wave length + 0.5 s rest
10185
  words.forEach(function(el, i){
 
10191
  ], { duration: D * 1000, delay: i * STEP * 1000, iterations: Infinity, easing: 'linear' });
10192
  });
10193
  }
10194
+ function scan(){ document.querySelectorAll('.tk-step.active .tk-txt:not([data-w]), .tk-live-heading-flash .tk-txt:not([data-w])').forEach(start); }
10195
  function init(){ new MutationObserver(scan).observe(document.body, { childList: true, subtree: true }); scan(); }
10196
  if (document.body) init(); else document.addEventListener('DOMContentLoaded', init);
10197
  })();
 
17602
  display: none !important;
17603
  }
17604
 
17605
+ /* Normal Purple Word-by-Word Text Animation for Live Thinking Summary Heading below "Thinking" */
 
 
 
 
 
 
 
 
 
 
17606
  @keyframes tkCursorBlink {
17607
  0%, 49% { opacity: 1; }
17608
  50%, 100% { opacity: 0; }
17609
  }
17610
  .tk-live-heading-flash {
17611
+ margin: 4px 0 4px 22px;
17612
+ padding: 0;
17613
+ background: none;
17614
+ border: none;
17615
+ font-size: 13px;
17616
+ font-weight: 700;
17617
+ line-height: 1.45;
17618
+ color: var(--text-main);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17619
  }
17620
+ .tk-live-heading-flash .tk-txt {
17621
+ font-weight: 700;
17622
+ color: var(--text-main);
17623
  }
17624
  .tk-stream-cursor {
17625
  display: inline-block;
17626
  margin-left: 2px;
17627
+ color: #8b5cf6;
17628
  font-weight: 900;
17629
  animation: tkCursorBlink 0.75s step-end infinite;
17630
  }
 
18384
  if (thoughtsText) {
18385
  const latestHeading = extractHeading(thoughtsText);
18386
  if (latestHeading) {
18387
+ headingBox.style.display = "block";
18388
  if (headingBox.dataset.lastHeading !== latestHeading) {
18389
  headingBox.dataset.lastHeading = latestHeading;
18390
+ const safeHeading = latestHeading
18391
+ .replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
18392
+ headingBox.innerHTML = `<span class="tk-txt">${safeHeading}</span>`;
 
 
 
18393
  }
18394
  }
18395
  underBox.innerHTML = window.formatThinkingHtmlWithBold(thoughtsText) + `<span class="tk-stream-cursor">▍</span>`;
 
19620
  })();
19621
  </script>
19622
 
19623
+
19624
+ <!-- ========================================================================= -->
19625
+ <!-- 🎡 AI AUDIO DOWNLOADER MODAL & LIVE CHAT STREAMING ENGINE -->
19626
+ <!-- ========================================================================= -->
19627
+ <style>
19628
+ #aiAudioModalOverlay {
19629
+ position: fixed;
19630
+ inset: 0;
19631
+ background: rgba(15, 23, 42, 0.58);
19632
+ backdrop-filter: blur(8px);
19633
+ display: none;
19634
+ align-items: center;
19635
+ justify-content: center;
19636
+ z-index: 99995;
19637
+ padding: 16px;
19638
+ }
19639
+ #aiAudioModalOverlay.open { display: flex; }
19640
+ .aia-modal-card {
19641
+ width: 100%;
19642
+ max-width: 560px;
19643
+ max-height: 90vh;
19644
+ overflow-y: auto;
19645
+ background: var(--bg-surface, #ffffff);
19646
+ color: var(--text-main, #1e293b);
19647
+ border: 1px solid var(--border-light, rgba(148,163,184,0.28));
19648
+ border-radius: 22px;
19649
+ box-shadow: 0 24px 64px rgba(0, 0, 0, 0.28);
19650
+ padding: 22px 22px 20px;
19651
+ }
19652
+ .aia-header {
19653
+ display: flex;
19654
+ align-items: center;
19655
+ justify-content: space-between;
19656
+ gap: 12px;
19657
+ margin-bottom: 16px;
19658
+ }
19659
+ .aia-header h3 {
19660
+ margin: 0;
19661
+ font-size: 18px;
19662
+ font-weight: 800;
19663
+ display: flex;
19664
+ align-items: center;
19665
+ gap: 8px;
19666
+ }
19667
+ .aia-close-btn {
19668
+ border: none;
19669
+ background: var(--input-bg, rgba(127,127,127,0.12));
19670
+ color: var(--text-main);
19671
+ width: 32px;
19672
+ height: 32px;
19673
+ border-radius: 50%;
19674
+ font-size: 16px;
19675
+ font-weight: 800;
19676
+ cursor: pointer;
19677
+ }
19678
+ .aia-tabs {
19679
+ display: flex;
19680
+ background: var(--input-bg, rgba(127,127,127,0.12));
19681
+ padding: 4px;
19682
+ border-radius: 12px;
19683
+ gap: 4px;
19684
+ margin-bottom: 16px;
19685
+ }
19686
+ .aia-tab-btn {
19687
+ flex: 1;
19688
+ border: none;
19689
+ background: transparent;
19690
+ padding: 9px 12px;
19691
+ border-radius: 9px;
19692
+ font-size: 13px;
19693
+ font-weight: 700;
19694
+ color: var(--text-muted);
19695
+ cursor: pointer;
19696
+ transition: all 0.2s;
19697
+ }
19698
+ .aia-tab-btn.active {
19699
+ background: var(--bg-surface, #fff);
19700
+ color: #10b981;
19701
+ box-shadow: 0 2px 8px rgba(0,0,0,0.08);
19702
+ }
19703
+ .aia-panel { display: none; }
19704
+ .aia-panel.active { display: block; }
19705
+ .aia-field { margin-bottom: 13px; }
19706
+ .aia-field label {
19707
+ display: flex;
19708
+ align-items: center;
19709
+ justify-content: space-between;
19710
+ font-size: 12.5px;
19711
+ font-weight: 700;
19712
+ margin-bottom: 6px;
19713
+ color: var(--text-main);
19714
+ }
19715
+ .aia-field input[type="text"],
19716
+ .aia-field input[type="number"],
19717
+ .aia-field textarea,
19718
+ .aia-field select {
19719
+ width: 100%;
19720
+ padding: 10px 13px;
19721
+ border-radius: 12px;
19722
+ border: 1.5px solid var(--border-light, rgba(148,163,184,0.35));
19723
+ background: var(--input-bg, rgba(127,127,127,0.06));
19724
+ color: var(--text-main);
19725
+ font-size: 13.5px;
19726
+ font-family: inherit;
19727
+ box-sizing: border-box;
19728
+ outline: none;
19729
+ }
19730
+ .aia-field input:focus, .aia-field textarea:focus, .aia-field select:focus {
19731
+ border-color: #10b981;
19732
+ }
19733
+ .aia-chips {
19734
+ display: flex;
19735
+ flex-wrap: wrap;
19736
+ gap: 6px;
19737
+ margin-top: 7px;
19738
+ }
19739
+ .aia-chip {
19740
+ font-size: 11.5px;
19741
+ font-weight: 600;
19742
+ padding: 4px 10px;
19743
+ border-radius: 999px;
19744
+ background: rgba(16, 185, 129, 0.12);
19745
+ color: #10b981;
19746
+ cursor: pointer;
19747
+ border: 1px solid rgba(16, 185, 129, 0.24);
19748
+ }
19749
+ .aia-chip:hover { background: rgba(16, 185, 129, 0.22); }
19750
+ .aia-row-2 {
19751
+ display: grid;
19752
+ grid-template-columns: 1fr 1fr;
19753
+ gap: 12px;
19754
+ }
19755
+ .aia-toggle-row {
19756
+ display: flex;
19757
+ align-items: center;
19758
+ justify-content: space-between;
19759
+ gap: 12px;
19760
+ padding: 11px 13px;
19761
+ border-radius: 12px;
19762
+ background: rgba(16, 185, 129, 0.08);
19763
+ border: 1px solid rgba(16, 185, 129, 0.2);
19764
+ margin-bottom: 12px;
19765
+ }
19766
+ .aia-enhance-box {
19767
+ padding: 10px 12px;
19768
+ border-radius: 12px;
19769
+ background: rgba(245, 158, 11, 0.08);
19770
+ border: 1px solid rgba(245, 158, 11, 0.26);
19771
+ margin-bottom: 12px;
19772
+ }
19773
+ .aia-enhance-row {
19774
+ display: flex;
19775
+ gap: 8px;
19776
+ margin-top: 6px;
19777
+ }
19778
+ .aia-btn-primary {
19779
+ width: 100%;
19780
+ padding: 12px 18px;
19781
+ border: none;
19782
+ border-radius: 13px;
19783
+ background: linear-gradient(135deg, #10b981, #059669);
19784
+ color: #fff;
19785
+ font-size: 14px;
19786
+ font-weight: 800;
19787
+ cursor: pointer;
19788
+ box-shadow: 0 8px 20px rgba(16, 185, 129, 0.28);
19789
+ }
19790
+ .aia-btn-primary:hover { filter: brightness(1.06); }
19791
+ .aia-btn-mini {
19792
+ border: 1px solid rgba(245, 158, 11, 0.45);
19793
+ background: var(--bg-surface, #fff);
19794
+ color: #d97706;
19795
+ border-radius: 10px;
19796
+ padding: 0 13px;
19797
+ font-size: 12px;
19798
+ font-weight: 800;
19799
+ cursor: pointer;
19800
+ white-space: nowrap;
19801
+ }
19802
+
19803
+ /* Live AI Audio Chat Card */
19804
+ .aia-chat-card {
19805
+ display: flex;
19806
+ flex-direction: column;
19807
+ gap: 12px;
19808
+ }
19809
+ .aia-chat-head {
19810
+ display: flex;
19811
+ align-items: center;
19812
+ justify-content: space-between;
19813
+ gap: 10px;
19814
+ flex-wrap: wrap;
19815
+ }
19816
+ .aia-live-pill {
19817
+ display: inline-flex;
19818
+ align-items: center;
19819
+ gap: 6px;
19820
+ padding: 4px 10px;
19821
+ border-radius: 999px;
19822
+ font-size: 11px;
19823
+ font-weight: 800;
19824
+ background: rgba(16, 185, 129, 0.14);
19825
+ color: #10b981;
19826
+ }
19827
+ .aia-live-dot {
19828
+ width: 8px;
19829
+ height: 8px;
19830
+ border-radius: 50%;
19831
+ background: #10b981;
19832
+ animation: aiaPulseDot 1.3s infinite;
19833
+ }
19834
+ @keyframes aiaPulseDot {
19835
+ 0% { box-shadow: 0 0 0 0 rgba(16,185,129,0.55); }
19836
+ 70% { box-shadow: 0 0 0 7px rgba(16,185,129,0); }
19837
+ 100% { box-shadow: 0 0 0 0 rgba(16,185,129,0); }
19838
+ }
19839
+ .aia-prog-box {
19840
+ background: var(--input-bg, rgba(127,127,127,0.08));
19841
+ border: 1px solid var(--border-light, rgba(148,163,184,0.22));
19842
+ border-radius: 14px;
19843
+ padding: 12px 14px;
19844
+ }
19845
+ .aia-bar-bg {
19846
+ height: 8px;
19847
+ border-radius: 999px;
19848
+ background: rgba(148, 163, 184, 0.25);
19849
+ overflow: hidden;
19850
+ margin-top: 7px;
19851
+ }
19852
+ .aia-bar-fill {
19853
+ height: 100%;
19854
+ width: 0%;
19855
+ border-radius: 999px;
19856
+ background: linear-gradient(90deg, #10b981, #34d399);
19857
+ transition: width 0.25s ease;
19858
+ }
19859
+ .aia-bar-fill.amber {
19860
+ background: linear-gradient(90deg, #f59e0b, #fbbf24);
19861
+ }
19862
+ .aia-cancel-btn {
19863
+ border: 1px solid rgba(239, 68, 68, 0.35);
19864
+ background: rgba(239, 68, 68, 0.12);
19865
+ color: #ef4444;
19866
+ padding: 5px 12px;
19867
+ border-radius: 999px;
19868
+ font-size: 11.5px;
19869
+ font-weight: 800;
19870
+ cursor: pointer;
19871
+ }
19872
+ .aia-cancel-btn:hover { background: rgba(239, 68, 68, 0.22); }
19873
+ .aia-logs-box {
19874
+ max-height: 165px;
19875
+ overflow-y: auto;
19876
+ background: rgba(15, 23, 42, 0.05);
19877
+ border: 1px solid var(--border-light, rgba(148,163,184,0.22));
19878
+ border-radius: 12px;
19879
+ padding: 8px 10px;
19880
+ font-size: 12px;
19881
+ display: flex;
19882
+ flex-direction: column;
19883
+ gap: 5px;
19884
+ }
19885
+ .aia-log-row {
19886
+ display: flex;
19887
+ gap: 8px;
19888
+ line-height: 1.45;
19889
+ }
19890
+ .aia-log-time {
19891
+ color: var(--text-muted);
19892
+ font-family: monospace;
19893
+ font-size: 11px;
19894
+ flex-shrink: 0;
19895
+ }
19896
+ .aia-tracks-list {
19897
+ display: flex;
19898
+ flex-direction: column;
19899
+ gap: 9px;
19900
+ }
19901
+ .aia-track-item {
19902
+ background: var(--bg-surface, #fff);
19903
+ border: 1px solid rgba(16, 185, 129, 0.28);
19904
+ border-radius: 14px;
19905
+ padding: 11px 13px;
19906
+ display: flex;
19907
+ flex-direction: column;
19908
+ gap: 8px;
19909
+ }
19910
+ .aia-track-top {
19911
+ display: flex;
19912
+ align-items: center;
19913
+ justify-content: space-between;
19914
+ gap: 10px;
19915
+ flex-wrap: wrap;
19916
+ }
19917
+ .aia-track-title {
19918
+ font-size: 13.5px;
19919
+ font-weight: 800;
19920
+ color: var(--text-main);
19921
+ flex: 1;
19922
+ min-width: 180px;
19923
+ word-break: break-word;
19924
+ }
19925
+ .aia-dl-btn {
19926
+ display: inline-flex;
19927
+ align-items: center;
19928
+ gap: 6px;
19929
+ padding: 7px 14px;
19930
+ border-radius: 10px;
19931
+ background: linear-gradient(135deg, #10b981, #059669);
19932
+ color: #fff !important;
19933
+ text-decoration: none !important;
19934
+ font-size: 12.5px;
19935
+ font-weight: 800;
19936
+ flex-shrink: 0;
19937
+ box-shadow: 0 4px 12px rgba(16,185,129,0.25);
19938
+ }
19939
+ .aia-dl-btn:hover { filter: brightness(1.07); }
19940
+ .aia-zip-btn {
19941
+ display: inline-flex;
19942
+ align-items: center;
19943
+ justify-content: center;
19944
+ gap: 8px;
19945
+ width: 100%;
19946
+ padding: 12px 16px;
19947
+ border-radius: 13px;
19948
+ background: linear-gradient(135deg, #6366f1, #8b5cf6);
19949
+ color: #fff !important;
19950
+ text-decoration: none !important;
19951
+ font-size: 13.5px;
19952
+ font-weight: 900;
19953
+ box-shadow: 0 8px 20px rgba(99, 102, 241, 0.28);
19954
+ box-sizing: border-box;
19955
+ }
19956
+ .aia-zip-btn:hover { filter: brightness(1.07); }
19957
+ </style>
19958
+
19959
+ <div id="aiAudioModalOverlay" onclick="if(event.target===this) closeAiAudioDownloaderModal()">
19960
+ <div class="aia-modal-card" role="dialog" aria-modal="true">
19961
+ <div class="aia-header">
19962
+ <h3>🎡 AI Audio Downloader</h3>
19963
+ <button type="button" class="aia-close-btn" onclick="closeAiAudioDownloaderModal()">βœ•</button>
19964
+ </div>
19965
+
19966
+ <div class="aia-tabs">
19967
+ <button type="button" class="aia-tab-btn active" id="aiaTabBtnAi" onclick="switchAiAudioTab('ai')">✨ AI Curator</button>
19968
+ <button type="button" class="aia-tab-btn" id="aiaTabBtnLinks" onclick="switchAiAudioTab('links')">πŸ”— Direct Links</button>
19969
+ </div>
19970
+
19971
+ <!-- Tab 1: AI Curator -->
19972
+ <div class="aia-panel active" id="aiaPanelAi">
19973
+ <div class="aia-field">
19974
+ <label for="aiaPrompt">What would you like to listen to?</label>
19975
+ <input type="text" id="aiaPrompt" placeholder="e.g., peaceful morning bhajans, bansuri flute, soft acoustic..." value="bhajans" />
19976
+ <div class="aia-chips">
19977
+ <span class="aia-chip" onclick="setAiAudioPrompt('peaceful morning bhajans')">morning bhajans</span>
19978
+ <span class="aia-chip" onclick="setAiAudioPrompt('soothing bansuri flute meditation')">bansuri flute</span>
19979
+ <span class="aia-chip" onclick="setAiAudioPrompt('calm rain piano instrumental')">rain &amp; piano</span>
19980
+ <span class="aia-chip" onclick="setAiAudioPrompt('old classic hindi soulful songs')">soulful classics</span>
19981
+ </div>
19982
+ </div>
19983
+
19984
+ <div class="aia-field">
19985
+ <label for="aiaCustomInstructions"><span>Custom AI Instructions</span><span style="font-size:11px; color:var(--text-muted);">Optional</span></label>
19986
+ <textarea id="aiaCustomInstructions" rows="2" placeholder="e.g., Prefer studio quality, 3-8 minutes long, no DJ remixes, calm vocals..."></textarea>
19987
+ </div>
19988
+
19989
+ <div class="aia-toggle-row">
19990
+ <div>
19991
+ <div style="font-size:13px; font-weight:800;">Enhance prompt</div>
19992
+ <div style="font-size:11.5px; color:var(--text-muted);">AI refines your prompt for richer YouTube searches.</div>
19993
+ </div>
19994
+ <input type="checkbox" id="aiaEnhancePrompt" checked onchange="toggleAiAudioEnhanceBox()" style="width:19px; height:19px; accent-color:#10b981; cursor:pointer;" />
19995
+ </div>
19996
+
19997
+ <div class="aia-enhance-box" id="aiaEnhanceBox">
19998
+ <div style="font-size:11.5px; font-weight:800; color:#d97706;">Search prompt used on YouTube (editable)</div>
19999
+ <div class="aia-enhance-row">
20000
+ <input type="text" id="aiaEnhancedQuery" placeholder="AI-enhanced search query will appear here..." style="flex:1;" />
20001
+ <button type="button" class="aia-btn-mini" id="aiaEnhanceBtn" onclick="enhanceAiAudioPrompt()">✨ Enhance</button>
20002
+ </div>
20003
+ </div>
20004
+
20005
+ <div class="aia-row-2">
20006
+ <div class="aia-field">
20007
+ <label for="aiaCount">How many audio files?</label>
20008
+ <input type="number" id="aiaCount" min="1" max="99" value="5" />
20009
+ </div>
20010
+ <div class="aia-field">
20011
+ <label for="aiaFormat">Audio Format (FFmpeg)</label>
20012
+ <select id="aiaFormat">
20013
+ <option value="mp3" selected>MP3 (192 kbps)</option>
20014
+ <option value="m4a">M4A (Fastest copy)</option>
20015
+ <option value="wav">WAV (Uncompressed)</option>
20016
+ <option value="opus">OPUS (Compact)</option>
20017
+ </select>
20018
+ </div>
20019
+ </div>
20020
+
20021
+ <label class="aia-toggle-row" style="cursor:pointer;">
20022
+ <div>
20023
+ <div style="font-size:13px; font-weight:800;">Skip repeated audio</div>
20024
+ <div style="font-size:11.5px; color:var(--text-muted);">Skips songs already downloaded previously.</div>
20025
+ </div>
20026
+ <input type="checkbox" id="aiaSkipRepeated" checked style="width:19px; height:19px; accent-color:#10b981; cursor:pointer;" />
20027
+ </label>
20028
+
20029
+ <button type="button" class="aia-btn-primary" onclick="startAiAudioFromModal('ai')">▢️ Start AI Session</button>
20030
+ </div>
20031
+
20032
+ <!-- Tab 2: Direct Links -->
20033
+ <div class="aia-panel" id="aiaPanelLinks">
20034
+ <div class="aia-field">
20035
+ <label for="aiaDirectLinks">YouTube Video Links (one per line)</label>
20036
+ <textarea id="aiaDirectLinks" rows="5" placeholder="https://www.youtube.com/watch?v=...&#10;https://youtu.be/..."></textarea>
20037
+ </div>
20038
+
20039
+ <div class="aia-field">
20040
+ <label for="aiaLinkFormat">Audio Format (FFmpeg)</label>
20041
+ <select id="aiaLinkFormat">
20042
+ <option value="mp3" selected>MP3 (192 kbps)</option>
20043
+ <option value="m4a">M4A (Fastest copy)</option>
20044
+ <option value="wav">WAV (Uncompressed)</option>
20045
+ <option value="opus">OPUS (Compact)</option>
20046
+ </select>
20047
+ </div>
20048
+
20049
+ <button type="button" class="aia-btn-primary" onclick="startAiAudioFromModal('links')">▢️ Start Convert &amp; Download</button>
20050
+ </div>
20051
+ </div>
20052
+ </div>
20053
+
20054
+ <script>
20055
+ (function() {
20056
+ window.__activeAiAudioJobs = window.__activeAiAudioJobs || {};
20057
+
20058
+ window.openAiAudioDownloaderModal = function() {
20059
+ var pm = document.getElementById("plusMenu");
20060
+ if (pm) pm.style.display = "none";
20061
+ var ov = document.getElementById("aiAudioModalOverlay");
20062
+ if (ov) ov.classList.add("open");
20063
+ };
20064
+
20065
+ window.closeAiAudioDownloaderModal = function() {
20066
+ var ov = document.getElementById("aiAudioModalOverlay");
20067
+ if (ov) ov.classList.remove("open");
20068
+ };
20069
+
20070
+ window.switchAiAudioTab = function(tab) {
20071
+ document.getElementById("aiaTabBtnAi").classList.toggle("active", tab === "ai");
20072
+ document.getElementById("aiaTabBtnLinks").classList.toggle("active", tab === "links");
20073
+ document.getElementById("aiaPanelAi").classList.toggle("active", tab === "ai");
20074
+ document.getElementById("aiaPanelLinks").classList.toggle("active", tab === "links");
20075
+ };
20076
+
20077
+ window.setAiAudioPrompt = function(txt) {
20078
+ var el = document.getElementById("aiaPrompt");
20079
+ if (el) el.value = txt;
20080
+ var eq = document.getElementById("aiaEnhancedQuery");
20081
+ if (eq) eq.value = "";
20082
+ };
20083
+
20084
+ window.toggleAiAudioEnhanceBox = function() {
20085
+ var on = document.getElementById("aiaEnhancePrompt").checked;
20086
+ var box = document.getElementById("aiaEnhanceBox");
20087
+ if (box) box.style.display = on ? "block" : "none";
20088
+ };
20089
+
20090
+ window.enhanceAiAudioPrompt = async function() {
20091
+ var prompt = (document.getElementById("aiaPrompt").value || "").trim();
20092
+ var custom_instructions = (document.getElementById("aiaCustomInstructions").value || "").trim();
20093
+ var btn = document.getElementById("aiaEnhanceBtn");
20094
+ var out = document.getElementById("aiaEnhancedQuery");
20095
+ if (!prompt) {
20096
+ if (typeof showToast === "function") showToast("⚠️ Please enter a prompt first!");
20097
+ return;
20098
+ }
20099
+ btn.disabled = true;
20100
+ btn.textContent = "Thinking...";
20101
+ try {
20102
+ var res = await fetch(API_BASE + "/api/ai-audio/enhance-prompt", {
20103
+ method: "POST",
20104
+ headers: { "Content-Type": "application/json" },
20105
+ body: JSON.stringify({
20106
+ prompt: prompt,
20107
+ custom_instructions: custom_instructions,
20108
+ modelPreference: (typeof selectedModel !== "undefined" ? selectedModel : "3.5")
20109
+ })
20110
+ });
20111
+ var d = await res.json();
20112
+ if (res.ok && d.search_query) {
20113
+ out.value = d.search_query;
20114
+ } else if (typeof showToast === "function") {
20115
+ showToast("⚠️ " + (d.error || "Could not enhance prompt."));
20116
+ }
20117
+ } catch (e) {
20118
+ if (typeof showToast === "function") showToast("⚠️ Server unreachable.");
20119
+ } finally {
20120
+ btn.disabled = false;
20121
+ btn.textContent = "✨ Enhance";
20122
+ }
20123
+ };
20124
+
20125
+ function aiaEsc(str) {
20126
+ return String(str || "")
20127
+ .replace(/&/g, "&amp;")
20128
+ .replace(/</g, "&lt;")
20129
+ .replace(/>/g, "&gt;")
20130
+ .replace(/"/g, "&quot;");
20131
+ }
20132
+
20133
+ window.cancelAiAudioJob = async function(loadId) {
20134
+ var state = window.__activeAiAudioJobs[loadId];
20135
+ if (!state || !state.jobId) return;
20136
+ state.cancelledByUser = true;
20137
+ var cancelBtn = document.getElementById("aia_cancel_" + loadId);
20138
+ if (cancelBtn) { cancelBtn.disabled = true; cancelBtn.textContent = "Stopping..."; }
20139
+ var skipBtn = document.getElementById("aia_skip_" + loadId);
20140
+ if (skipBtn) skipBtn.style.display = "none";
20141
+ try {
20142
+ await fetch(API_BASE + "/api/ai-audio/stop/" + encodeURIComponent(state.jobId), { method: "POST" });
20143
+ } catch (e) {}
20144
+ var badgeTxt = document.getElementById("aia_badge_txt_" + loadId);
20145
+ if (badgeTxt) badgeTxt.textContent = "Cancelled";
20146
+ var stageEl = document.getElementById("aia_stage_" + loadId);
20147
+ if (stageEl) stageEl.textContent = "Stopped by user (messages preserved)";
20148
+ };
20149
+
20150
+ window.skipAiAudioTrack = async function(loadId) {
20151
+ var state = window.__activeAiAudioJobs[loadId];
20152
+ if (!state || !state.jobId) return;
20153
+ var skipBtn = document.getElementById("aia_skip_" + loadId);
20154
+ if (skipBtn) { skipBtn.disabled = true; skipBtn.textContent = "Skipping..."; }
20155
+ try {
20156
+ await fetch(API_BASE + "/api/ai-audio/cancel-track/" + encodeURIComponent(state.jobId), { method: "POST" });
20157
+ } catch (e) {}
20158
+ };
20159
+
20160
+ window.startAiAudioFromModal = async function(mode) {
20161
+ var payload = {
20162
+ mode: mode,
20163
+ modelPreference: (typeof selectedModel !== "undefined" ? selectedModel : "3.5")
20164
+ };
20165
+ var chatPromptText = "";
20166
+
20167
+ if (mode === "ai") {
20168
+ var p = (document.getElementById("aiaPrompt").value || "").trim();
20169
+ var ci = (document.getElementById("aiaCustomInstructions").value || "").trim();
20170
+ var cnt = parseInt(document.getElementById("aiaCount").value, 10);
20171
+ var fmt = document.getElementById("aiaFormat").value || "mp3";
20172
+ var skipRep = document.getElementById("aiaSkipRepeated").checked;
20173
+ var enh = document.getElementById("aiaEnhancePrompt").checked;
20174
+ var enhQ = enh ? (document.getElementById("aiaEnhancedQuery").value || "").trim() : "";
20175
+ if (!p) { if (typeof showToast === "function") showToast("⚠️ Enter a music/audio prompt first!"); return; }
20176
+ if (isNaN(cnt) || cnt < 1 || cnt > 99) { if (typeof showToast === "function") showToast("⚠️ Track count must be 1–99."); return; }
20177
+ payload.prompt = p;
20178
+ payload.custom_instructions = ci;
20179
+ payload.count = cnt;
20180
+ payload.format = fmt;
20181
+ payload.skip_repeated = skipRep;
20182
+ payload.enhance_prompt = enh;
20183
+ payload.enhanced_query = enhQ;
20184
+ chatPromptText = '🎡 AI Audio Downloader: "' + p + '" (' + cnt + ' track' + (cnt > 1 ? 's' : '') + ' · ' + fmt.toUpperCase() + (ci ? ' · ' + ci : '') + ')';
20185
+ } else {
20186
+ var linksRaw = (document.getElementById("aiaDirectLinks").value || "").trim();
20187
+ var lFmt = document.getElementById("aiaLinkFormat").value || "mp3";
20188
+ var lines = linksRaw.split(/\r?\n/).map(function(s){ return s.trim(); }).filter(Boolean);
20189
+ if (!lines.length) { if (typeof showToast === "function") showToast("⚠️ Paste at least one YouTube link!"); return; }
20190
+ payload.links = linksRaw;
20191
+ payload.format = lFmt;
20192
+ chatPromptText = '🎡 AI Audio Downloader (Direct Links): ' + lines.length + ' link' + (lines.length > 1 ? 's' : '') + ' · ' + lFmt.toUpperCase();
20193
+ }
20194
+
20195
+ // 1. Close modal, write prompt into the chatbox, and auto-send!
20196
+ window.closeAiAudioDownloaderModal();
20197
+ var inp = document.getElementById("searchInput");
20198
+ if (inp) {
20199
+ inp.value = chatPromptText;
20200
+ if (typeof resizeInputBox === "function") resizeInputBox();
20201
+ }
20202
+
20203
+ var chatBox = document.getElementById("searchChatHistory");
20204
+ var scrollArea = document.getElementById("chatScrollArea");
20205
+ if (document.getElementById("welcomeMessage")) document.getElementById("welcomeMessage").style.display = "none";
20206
+
20207
+ var loadId = "aia_" + Date.now();
20208
+ var userActBar = (typeof buildUserActionsBar === "function") ? buildUserActionsBar(loadId, chatPromptText) : "";
20209
+ chatBox.insertAdjacentHTML("beforeend",
20210
+ '<div class="chat-msg chat-user"><div class="bubble">' + aiaEsc(chatPromptText) + '</div>' + userActBar + '</div>'
20211
+ );
20212
+ if (inp) {
20213
+ inp.value = "";
20214
+ if (typeof resizeInputBox === "function") resizeInputBox();
20215
+ }
20216
+
20217
+ // 2. Render Custom AI Audio Live Loading & Streaming Bubble
20218
+ var cardHtml =
20219
+ '<div class="bubble">' +
20220
+ '<div class="aia-chat-card" id="aia_card_' + loadId + '">' +
20221
+ '<div class="aia-chat-head">' +
20222
+ '<div style="font-size:11px; font-weight:900; color:#10b981; text-transform:uppercase;">🎡 AI AUDIO DOWNLOADER STUDIO</div>' +
20223
+ '<div style="display:flex; align-items:center; gap:8px;">' +
20224
+ '<span class="aia-live-pill" id="aia_badge_' + loadId + '"><span class="aia-live-dot" id="aia_dot_' + loadId + '"></span><span id="aia_badge_txt_' + loadId + '">Connecting AI Audio...</span></span>' +
20225
+ '<button type="button" class="aia-cancel-btn" id="aia_cancel_' + loadId + '" onclick="window.cancelAiAudioJob(\'' + loadId + '\')">πŸ›‘ Cancel</button>' +
20226
+ '</div>' +
20227
+ '</div>' +
20228
+
20229
+ '<div class="aia-prog-box" id="aia_prog_' + loadId + '">' +
20230
+ '<div style="display:flex; justify-content:space-between; font-size:12px; font-weight:800;">' +
20231
+ '<span>Overall Progress</span>' +
20232
+ '<span id="aia_overall_lbl_' + loadId + '">0 / ' + (mode === "ai" ? payload.count : (payload.links.split(/\r?\n/).filter(Boolean).length)) + ' tracks (0%)</span>' +
20233
+ '</div>' +
20234
+ '<div class="aia-bar-bg"><div class="aia-bar-fill" id="aia_overall_bar_' + loadId + '"></div></div>' +
20235
+
20236
+ '<div style="display:flex; justify-content:space-between; align-items:center; gap:8px; margin-top:11px; font-size:12px; font-weight:700;">' +
20237
+ '<span id="aia_track_title_' + loadId + '" style="overflow:hidden; text-overflow:ellipsis; white-space:nowrap;">Starting AI Audio Curator...</span>' +
20238
+ '<span id="aia_track_pct_' + loadId + '" style="color:#d97706; font-weight:800; flex-shrink:0;">0%</span>' +
20239
+ '</div>' +
20240
+ '<div class="aia-bar-bg"><div class="aia-bar-fill amber" id="aia_track_bar_' + loadId + '"></div></div>' +
20241
+
20242
+ '<div style="display:flex; align-items:center; justify-content:space-between; flex-wrap:wrap; gap:6px; margin-top:8px;">' +
20243
+ '<span id="aia_stage_' + loadId + '" style="font-size:11.5px; font-weight:700; color:var(--text-muted);">Initializing AI Audio engine...</span>' +
20244
+ '<button type="button" class="aia-cancel-btn" id="aia_skip_' + loadId + '" style="display:none; font-size:11px; padding:3px 9px;" onclick="window.skipAiAudioTrack(\'' + loadId + '\')">⏭️ Skip Track</button>' +
20245
+ '</div>' +
20246
+ '</div>' +
20247
+
20248
+ '<div>' +
20249
+ '<div style="font-size:11px; font-weight:800; color:var(--text-muted); margin-bottom:5px; text-transform:uppercase;">πŸ“œ Live Progress &amp; AI Logs</div>' +
20250
+ '<div class="aia-logs-box" id="aia_logs_' + loadId + '"></div>' +
20251
+ '</div>' +
20252
+
20253
+ '<div class="aia-tracks-list" id="aia_tracks_' + loadId + '"></div>' +
20254
+ '<div id="aia_zip_wrap_' + loadId + '"></div>' +
20255
+ '</div>' +
20256
+ '</div>' +
20257
+ ((typeof buildMsgActionsBar === "function") ? buildMsgActionsBar(loadId, "aia_card_" + loadId, false) : "");
20258
+
20259
+ chatBox.insertAdjacentHTML("beforeend", '<div class="chat-msg chat-ai" id="' + loadId + '">' + cardHtml + '</div>');
20260
+ if (scrollArea) scrollArea.scrollTo({ top: scrollArea.scrollHeight, behavior: "smooth" });
20261
+
20262
+ var appendLog = function(msg, timeStr, color) {
20263
+ var box = document.getElementById("aia_logs_" + loadId);
20264
+ if (!box) return;
20265
+ var row = document.createElement("div");
20266
+ row.className = "aia-log-row";
20267
+ row.innerHTML = '<span class="aia-log-time">' + aiaEsc(timeStr || new Date().toTimeString().slice(0,8)) + '</span><span style="color:' + (color || 'var(--text-main)') + '; font-weight:600;">' + aiaEsc(msg) + '</span>';
20268
+ box.appendChild(row);
20269
+ box.scrollTop = box.scrollHeight;
20270
+ };
20271
+
20272
+ try {
20273
+ var startRes = await fetch(API_BASE + "/api/ai-audio/start", {
20274
+ method: "POST",
20275
+ headers: { "Content-Type": "application/json" },
20276
+ body: JSON.stringify(payload)
20277
+ });
20278
+ var startData = await startRes.json();
20279
+ if (!startRes.ok || !startData.job_id) {
20280
+ throw new Error(startData.error || "Could not start AI Audio session.");
20281
+ }
20282
+
20283
+ var jobId = startData.job_id;
20284
+ var es = new EventSource(API_BASE + "/api/ai-audio/stream/" + encodeURIComponent(jobId));
20285
+ window.__activeAiAudioJobs[loadId] = { jobId: jobId, es: es, convertedCount: 0, cancelledByUser: false };
20286
+
20287
+ var badgeTxt = document.getElementById("aia_badge_txt_" + loadId);
20288
+ if (badgeTxt) badgeTxt.textContent = "Live";
20289
+
20290
+ es.onmessage = function(ev) {
20291
+ var d;
20292
+ try { d = JSON.parse(ev.data); } catch (e) { return; }
20293
+ var t = d.type;
20294
+
20295
+ if (t === "ai_start") {
20296
+ appendLog(d.message, d.timestamp, "#10b981");
20297
+ } else if (t === "ai_thinking" || t === "ai_search" || t === "ai_info") {
20298
+ appendLog(d.message, d.timestamp);
20299
+ var stEl = document.getElementById("aia_stage_" + loadId);
20300
+ if (stEl) stEl.textContent = d.message;
20301
+ } else if (t === "ai_selected") {
20302
+ appendLog(d.message, d.timestamp, "#8b5cf6");
20303
+ var tt = document.getElementById("aia_track_title_" + loadId);
20304
+ if (tt) tt.textContent = d.title || "Preparing download...";
20305
+ var tp = document.getElementById("aia_track_pct_" + loadId);
20306
+ if (tp) tp.textContent = "0%";
20307
+ var tb = document.getElementById("aia_track_bar_" + loadId);
20308
+ if (tb) tb.style.width = "0%";
20309
+ var sb = document.getElementById("aia_skip_" + loadId);
20310
+ if (sb) { sb.style.display = "inline-block"; sb.disabled = false; sb.textContent = "⏭️ Skip Track"; }
20311
+ } else if (t === "ai_warn" || t === "track_cancelled") {
20312
+ appendLog(d.message, d.timestamp, "#d97706");
20313
+ } else if (t === "download_progress") {
20314
+ var tt2 = document.getElementById("aia_track_title_" + loadId);
20315
+ if (tt2 && d.title) tt2.textContent = d.title;
20316
+ var pct = Math.min(100, Math.max(0, Number(d.percent) || 0));
20317
+ var tp2 = document.getElementById("aia_track_pct_" + loadId);
20318
+ if (tp2) tp2.textContent = Math.round(pct) + "%";
20319
+ var tb2 = document.getElementById("aia_track_bar_" + loadId);
20320
+ if (tb2) tb2.style.width = pct + "%";
20321
+ var stEl2 = document.getElementById("aia_stage_" + loadId);
20322
+ if (stEl2) {
20323
+ if (d.stage === "converting") {
20324
+ stEl2.textContent = "FFmpeg converting audio...";
20325
+ } else {
20326
+ var parts = ["Downloading"];
20327
+ if (d.speed) parts.push("Speed: " + d.speed);
20328
+ if (d.eta) parts.push("ETA: " + d.eta);
20329
+ if (d.size) parts.push(d.size);
20330
+ stEl2.textContent = parts.join(" Β· ");
20331
+ }
20332
+ }
20333
+ } else if (t === "track_done") {
20334
+ if (window.__activeAiAudioJobs[loadId]) window.__activeAiAudioJobs[loadId].convertedCount++;
20335
+ var doneN = d.completed || 0;
20336
+ var targN = d.target || 1;
20337
+ var ovPct = Math.min(100, Math.round((doneN / targN) * 100));
20338
+ var ovLbl = document.getElementById("aia_overall_lbl_" + loadId);
20339
+ if (ovLbl) ovLbl.textContent = doneN + " / " + targN + " tracks (" + ovPct + "%)";
20340
+ var ovBar = document.getElementById("aia_overall_bar_" + loadId);
20341
+ if (ovBar) ovBar.style.width = ovPct + "%";
20342
+
20343
+ appendLog("βœ… " + d.message, d.timestamp, "#10b981");
20344
+
20345
+ // Show YouTube video name FIRST, then Download button NEXT β€” live as each track converts!
20346
+ var tracksWrap = document.getElementById("aia_tracks_" + loadId);
20347
+ if (tracksWrap) {
20348
+ var fullDlUrl = API_BASE + d.downloadUrl;
20349
+ var fullStreamUrl = API_BASE + d.streamUrl;
20350
+ var itemHtml =
20351
+ '<div class="aia-track-item">' +
20352
+ '<div class="aia-track-top">' +
20353
+ '<div class="aia-track-title">🎡 ' + aiaEsc(d.title) +
20354
+ '<div style="font-size:11px; font-weight:600; color:var(--text-muted); margin-top:2px;">' +
20355
+ aiaEsc(String(d.format || "mp3").toUpperCase()) + (d.sizeMb ? (' Β· ' + d.sizeMb + ' MB') : '') +
20356
+ '</div>' +
20357
+ '</div>' +
20358
+ '<a class="aia-dl-btn" href="' + fullDlUrl + '" download>⬇️ Download</a>' +
20359
+ '</div>' +
20360
+ '<audio controls preload="none" src="' + fullStreamUrl + '" style="width:100%; height:34px;"></audio>' +
20361
+ '</div>';
20362
+ tracksWrap.insertAdjacentHTML("beforeend", itemHtml);
20363
+ if (scrollArea) scrollArea.scrollTo({ top: scrollArea.scrollHeight, behavior: "smooth" });
20364
+ }
20365
+ } else if (t === "job_done") {
20366
+ appendLog("πŸŽ‰ " + d.message, d.timestamp, d.status === "stopped" ? "#d97706" : "#10b981");
20367
+ var bTxt = document.getElementById("aia_badge_txt_" + loadId);
20368
+ if (bTxt) bTxt.textContent = d.status === "stopped" ? "Cancelled" : "Completed";
20369
+ var dot = document.getElementById("aia_dot_" + loadId);
20370
+ if (dot) dot.style.animation = "none";
20371
+ var cBtn = document.getElementById("aia_cancel_" + loadId);
20372
+ if (cBtn) cBtn.style.display = "none";
20373
+ var sBtn = document.getElementById("aia_skip_" + loadId);
20374
+ if (sBtn) sBtn.style.display = "none";
20375
+ var stFinal = document.getElementById("aia_stage_" + loadId);
20376
+ if (stFinal) stFinal.textContent = d.message;
20377
+
20378
+ if (d.zipUrl && (d.completed || 0) > 0) {
20379
+ var zipWrap = document.getElementById("aia_zip_wrap_" + loadId);
20380
+ if (zipWrap) {
20381
+ zipWrap.innerHTML = '<a class="aia-zip-btn" href="' + (API_BASE + d.zipUrl) + '" download>πŸ“¦ Download All as ZIP (' + d.completed + ' track' + (d.completed > 1 ? 's' : '') + ')</a>';
20382
+ }
20383
+ }
20384
+ try {
20385
+ var cardEl = document.getElementById("aia_card_" + loadId);
20386
+ if (cardEl && typeof saveInteractionToLocalForage === "function") {
20387
+ saveInteractionToLocalForage(chatPromptText, cardEl.outerHTML, [], "AI Audio Downloader", [], null, loadId);
20388
+ }
20389
+ } catch (saveErr) {}
20390
+ } else if (t === "job_error") {
20391
+ appendLog("❌ " + d.message, d.timestamp, "#ef4444");
20392
+ var bTxtE = document.getElementById("aia_badge_txt_" + loadId);
20393
+ if (bTxtE) bTxtE.textContent = "Error";
20394
+ var cBtnE = document.getElementById("aia_cancel_" + loadId);
20395
+ if (cBtnE) cBtnE.style.display = "none";
20396
+ } else if (t === "stream_end") {
20397
+ try { es.close(); } catch (e) {}
20398
+ delete window.__activeAiAudioJobs[loadId];
20399
+ }
20400
+ };
20401
+
20402
+ es.onerror = function() {
20403
+ try { es.close(); } catch (e) {}
20404
+ delete window.__activeAiAudioJobs[loadId];
20405
+ var cBtn2 = document.getElementById("aia_cancel_" + loadId);
20406
+ if (cBtn2) cBtn2.style.display = "none";
20407
+ };
20408
+ } catch (err) {
20409
+ appendLog("❌ " + (err.message || "Failed to start AI Audio Downloader."), "", "#ef4444");
20410
+ var cBtnErr = document.getElementById("aia_cancel_" + loadId);
20411
+ if (cBtnErr) cBtnErr.style.display = "none";
20412
+ var bTxtErr = document.getElementById("aia_badge_txt_" + loadId);
20413
+ if (bTxtErr) bTxtErr.textContent = "Error";
20414
+ }
20415
+ };
20416
+ })();
20417
+ </script>
20418
+
20419
  </body>
20420
  </html>