Spaces:
Running
Running
Upload static/wc_shorts_inject.js
Browse files- static/wc_shorts_inject.js +60 -0
static/wc_shorts_inject.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
})();
|