bep40 commited on
Commit
15b83bc
·
verified ·
1 Parent(s): 11bf901

Upload static/vtv_recorder_inject.js

Browse files
Files changed (1) hide show
  1. static/vtv_recorder_inject.js +111 -0
static/vtv_recorder_inject.js ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * VTV Recorder Inject
3
+ * - Auto-inject recorder UI vào home view
4
+ * - Thêm tab/button "🎬 Record VTV" trên cat-bar
5
+ * - Nhận diện khi user mở tab recorder
6
+ */
7
+ (function(){
8
+ 'use strict';
9
+
10
+ // ===== Inject recorder section into home view =====
11
+ function injectRecorderSection() {
12
+ const homeEl = document.getElementById('view-home');
13
+ if (!homeEl) return;
14
+
15
+ // Check if already injected
16
+ if (document.getElementById('vtv-recorder-injected')) return;
17
+
18
+ // Find the featured area and insert recorder after it
19
+ const featuredArea = document.getElementById('home-featured-area');
20
+ if (featuredArea && featuredArea.parentNode) {
21
+ const recSection = document.createElement('div');
22
+ recSection.id = 'vtv-recorder-injected';
23
+ recSection.className = 'slider-wrap';
24
+ recSection.style.marginTop = '6px';
25
+ recSection.innerHTML = `
26
+ <div style="display:flex;align-items:center;justify-content:space-between;padding:4px 10px 2px">
27
+ <span class="slider-label" style="color:#e74c3c">🎬 Record LIVE VTV</span>
28
+ <button id="rec-expand-btn" style="background:#2a1a4a;border:1px solid #6a3a9a;color:#9b59b6;border-radius:14px;padding:3px 10px;font-size:10px;cursor:pointer;font-weight:700">
29
+ Mở ▶
30
+ </button>
31
+ </div>
32
+ <div id="rec-section-mini" style="padding:4px 10px 8px">
33
+ <div style="display:flex;gap:6px;flex-wrap:wrap" id="rec-mini-channels">
34
+ <span style="color:#666;font-size:10px">Chọn kênh để record video ngắn (max 60s)...</span>
35
+ </div>
36
+ </div>
37
+ `;
38
+ featuredArea.parentNode.insertBefore(recSection, featuredArea.nextSibling);
39
+
40
+ // Mini channel buttons
41
+ const channels = [
42
+ {id:'vtv1',name:'VTV1'},{id:'vtv2',name:'VTV2'},{id:'vtv3',name:'VTV3'},
43
+ {id:'vtv4',name:'VTV4'},{id:'vtv5',name:'VTV5'},{id:'vtv6',name:'VTV6'},
44
+ {id:'vtv7',name:'VTV7'},{id:'vtv8',name:'VTV8'},{id:'vtv9',name:'VTV9'},
45
+ ];
46
+ const miniWrap = document.getElementById('rec-mini-channels');
47
+ if (miniWrap) {
48
+ let h = '';
49
+ channels.forEach(ch => {
50
+ h += `<button class="hot-chip" style="cursor:pointer" onclick="openVTVRecorder('${ch.id}')">📺 ${ch.name}</button>`;
51
+ });
52
+ h += `<button class="hot-chip" style="cursor:pointer;background:#1a0a3a;border-color:#6a3a9a;color:#9b59b6" onclick="openVTVRecorder(null)">📋 Tất cả kênh</button>`;
53
+ miniWrap.innerHTML = h;
54
+ }
55
+
56
+ // Expand button
57
+ document.getElementById('rec-expand-btn')?.addEventListener('click', function() {
58
+ openVTVRecorder(null);
59
+ });
60
+ }
61
+ }
62
+
63
+ // ===== Open recorder full view =====
64
+ window.openVTVRecorder = function(channelId) {
65
+ showView('view-tiktok');
66
+ const el = document.getElementById('view-tiktok');
67
+ el.innerHTML = '';
68
+
69
+ // Back button
70
+ const backBtn = document.createElement('button');
71
+ backBtn.className = 'back-btn';
72
+ backBtn.textContent = '← Quay lại';
73
+ backBtn.onclick = () => switchCat('home');
74
+ el.appendChild(backBtn);
75
+
76
+ // Container for recorder
77
+ const container = document.createElement('div');
78
+ container.style.padding = '8px';
79
+ container.style.maxWidth = '500px';
80
+ container.style.margin = '0 auto';
81
+ el.appendChild(container);
82
+
83
+ // HLS.js check
84
+ if (typeof Hls === 'undefined') {
85
+ const script = document.createElement('script');
86
+ script.src = 'https://cdn.jsdelivr.net/npm/hls.js@1/dist/hls.min.js';
87
+ script.onload = () => renderVTVRecorder(container);
88
+ document.head.appendChild(script);
89
+ } else {
90
+ renderVTVRecorder(container);
91
+ }
92
+ };
93
+
94
+ // ===== Init =====
95
+ // Inject after home loads
96
+ const origLoadHome = window.loadHome;
97
+ if (origLoadHome) {
98
+ window.loadHome = async function() {
99
+ await origLoadHome();
100
+ setTimeout(injectRecorderSection, 200);
101
+ };
102
+ }
103
+
104
+ // Also try to inject on DOM ready
105
+ if (document.readyState === 'loading') {
106
+ document.addEventListener('DOMContentLoaded', () => setTimeout(injectRecorderSection, 1000));
107
+ } else {
108
+ setTimeout(injectRecorderSection, 1000);
109
+ }
110
+
111
+ })();