bep40 commited on
Commit
79e3d33
·
verified ·
1 Parent(s): c034140

Upload static/wc_shorts_inject.js

Browse files
Files changed (1) hide show
  1. static/wc_shorts_inject.js +54 -38
static/wc_shorts_inject.js CHANGED
@@ -1,60 +1,76 @@
1
  /**
2
  * WC Shorts Inject — Chạy SAU app_v2.js
3
- * Tạo WC Shorts slide riêng nằm TRÊN World Cup section
4
- * Gắn vào #wc-shorts-slide-anchor
5
  */
6
  (function(){
7
  'use strict';
8
 
9
- // Chờ đến khi loadHome chạy xong (WC section đã render)
10
- function tryInject(){
11
- const anchor = document.getElementById('wc-shorts-slide-anchor');
12
- if(!anchor) return false;
 
13
 
14
- // Đã inject rồi
15
- if(anchor.dataset.injected) return true;
16
- anchor.dataset.injected = '1';
17
 
18
- // Gọi renderWCSSlideSection nếu đã load
19
- if(typeof renderWCSSlideSection === 'function'){
20
- renderWCSSlideSection(anchor);
 
 
 
 
 
 
 
 
 
 
 
 
21
  } else {
22
- // Chờ wc_shorts_slide.js load xong
23
- let tries = 0;
24
- const wait = setInterval(()=>{
25
- tries++;
26
- if(typeof renderWCSSlideSection === 'function'){
27
- clearInterval(wait);
28
- renderWCSSlideSection(anchor);
29
- } else if(tries > 40){ // 8 seconds
30
- clearInterval(wait);
31
- anchor.innerHTML = '<div style="text-align:center;padding:10px;color:#666;font-size:11px">Shorts đang cập nhật...</div>';
32
- }
33
- }, 200);
 
 
34
  }
35
- return true;
36
  }
37
 
38
- // Thử ngay
39
- if(!tryInject()){
40
- // Chờ DOM ready
41
- let attempts = 0;
42
- const iv = setInterval(()=>{
43
- attempts++;
44
- if(tryInject() || attempts > 60) clearInterval(iv);
45
- }, 500);
46
  }
47
 
48
- // Cũng chạy lại sau khi loadHome xong (vì loadHome rebuild DOM)
49
  const origLoadHome = window.loadHome;
50
  if(origLoadHome){
51
  window.loadHome = function(){
52
  const result = origLoadHome.apply(this, arguments);
53
- // Sau khi loadHome chạy, inject lại
54
- setTimeout(tryInject, 100);
55
- setTimeout(tryInject, 500);
56
- setTimeout(tryInject, 1500);
57
  return result;
58
  };
59
  }
 
 
 
 
 
 
 
 
60
  })();
 
1
  /**
2
  * WC Shorts Inject — Chạy SAU app_v2.js
3
+ * Tự tạo anchor DIV rồi render WC Shorts slide TRÊN World Cup section
 
4
  */
5
  (function(){
6
  'use strict';
7
 
8
+ function inject(){
9
+ // Tìm WC section
10
+ const wcSection = document.getElementById('wc2026-live-section');
11
+ const homeEl = document.getElementById('view-home');
12
+ if(!homeEl) return;
13
 
14
+ // Đã inject?
15
+ if(document.getElementById('wc-shorts-slide-section')) return;
 
16
 
17
+ // Đảm bảo renderWCSSlideSection đã load
18
+ if(typeof renderWCSSlideSection !== 'function'){
19
+ // Chờ rồi thử lại
20
+ setTimeout(inject, 500);
21
+ return;
22
+ }
23
+
24
+ // Tạo container rồi render vào
25
+ const div = document.createElement('div');
26
+ div.id = 'wc-shorts-slide-container-tmp';
27
+ div.style.display = 'none';
28
+
29
+ // Insert TRƯỚC WC section, hoặc vào đầu home
30
+ if(wcSection && wcSection.parentNode){
31
+ wcSection.parentNode.insertBefore(div, wcSection);
32
  } else {
33
+ homeEl.insertBefore(div, homeEl.firstChild);
34
+ }
35
+
36
+ // Render slide section vào div
37
+ renderWCSSlideSection(div);
38
+
39
+ // Bỏ wrapper thừa, di chuyển section ra đúng vị trí
40
+ const section = div.querySelector('.wc-shorts-slide-section');
41
+ if(section){
42
+ section.id = 'wc-shorts-slide-section';
43
+ if(wcSection && wcSection.parentNode){
44
+ wcSection.parentNode.insertBefore(section, wcSection);
45
+ }
46
+ div.remove();
47
  }
 
48
  }
49
 
50
+ // Chạy khi DOM sẵn sàng
51
+ if(document.readyState === 'loading'){
52
+ document.addEventListener('DOMContentLoaded', ()=> setTimeout(inject, 800));
53
+ } else {
54
+ setTimeout(inject, 800);
 
 
 
55
  }
56
 
57
+ // Cũng chạy sau khi loadHome xong
58
  const origLoadHome = window.loadHome;
59
  if(origLoadHome){
60
  window.loadHome = function(){
61
  const result = origLoadHome.apply(this, arguments);
62
+ setTimeout(inject, 200);
63
+ setTimeout(inject, 800);
64
+ setTimeout(inject, 2000);
 
65
  return result;
66
  };
67
  }
68
+
69
+ // Fallback: retry nhiều lần
70
+ let retries = 0;
71
+ const retryIv = setInterval(()=>{
72
+ retries++;
73
+ inject();
74
+ if(retries > 20) clearInterval(retryIv);
75
+ }, 1000);
76
  })();