Spaces:
Running
Running
Upload static/wc_shorts_inject.js
Browse files- 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 |
-
*
|
| 4 |
-
* Gắn vào #wc-shorts-slide-anchor
|
| 5 |
*/
|
| 6 |
(function(){
|
| 7 |
'use strict';
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
const
|
| 12 |
-
|
|
|
|
| 13 |
|
| 14 |
-
// Đã inject
|
| 15 |
-
if(
|
| 16 |
-
anchor.dataset.injected = '1';
|
| 17 |
|
| 18 |
-
//
|
| 19 |
-
if(typeof renderWCSSlideSection ==
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
} else {
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
| 34 |
}
|
| 35 |
-
return true;
|
| 36 |
}
|
| 37 |
|
| 38 |
-
//
|
| 39 |
-
if(
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
attempts++;
|
| 44 |
-
if(tryInject() || attempts > 60) clearInterval(iv);
|
| 45 |
-
}, 500);
|
| 46 |
}
|
| 47 |
|
| 48 |
-
// Cũng chạy
|
| 49 |
const origLoadHome = window.loadHome;
|
| 50 |
if(origLoadHome){
|
| 51 |
window.loadHome = function(){
|
| 52 |
const result = origLoadHome.apply(this, arguments);
|
| 53 |
-
|
| 54 |
-
setTimeout(
|
| 55 |
-
setTimeout(
|
| 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 |
})();
|