Spaces:
Running
Running
Fix: hide duplicate wall from loadHome, ensure wall renders after bg refresh"
Browse files- app_final.py +38 -5
app_final.py
CHANGED
|
@@ -1,11 +1,9 @@
|
|
| 1 |
-
"""
|
| 2 |
from app_patch_unified import *
|
| 3 |
from app_patch_unified import app, UNIFIED_INJECT, f5, f6, rt, PATCH_INJECT
|
| 4 |
from fastapi.responses import HTMLResponse
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
# 1. Add more functions to PRE_KILL
|
| 8 |
-
# 2. Fix highlight fetch from API when _hlLeagueData empty
|
| 9 |
UNIFIED_INJECT_FIXED = UNIFIED_INJECT.replace(
|
| 10 |
"""Object.defineProperty(window,'renderAIShorts7',{get:function(){return function(){}},set:function(){},configurable:true});""",
|
| 11 |
"""Object.defineProperty(window,'renderAIShorts7',{get:function(){return function(){}},set:function(){},configurable:true});
|
|
@@ -23,7 +21,41 @@ UNIFIED_INJECT_FIXED = UNIFIED_INJECT_FIXED.replace(
|
|
| 23 |
"var articles=(window._hlLeagueData||{})[league]||[];\n if(!articles.length){try{var _r=await fetch('/api/highlights/'+league);articles=await _r.json();if(!Array.isArray(articles))articles=[];}catch(e){articles=[];}}\n if(!articles.length){el.innerHTML="
|
| 24 |
)
|
| 25 |
|
| 26 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
app.router.routes = [r for r in app.router.routes if not (getattr(r,'path',None)=='/' and 'GET' in getattr(r,'methods',set()))]
|
| 28 |
|
| 29 |
@app.get('/')
|
|
@@ -37,4 +69,5 @@ async def _index_fixed():
|
|
| 37 |
body += getattr(f6,'FINAL6E_INJECT','')
|
| 38 |
body += PATCH_INJECT
|
| 39 |
body += UNIFIED_INJECT_FIXED
|
|
|
|
| 40 |
return HTMLResponse(html.replace('</body>', body + '\n</body>') if '</body>' in html else html + body)
|
|
|
|
| 1 |
+
"""Final wrapper: block destroyers, fix highlights, fix duplicate wall, ensure wall after bg refresh."""
|
| 2 |
from app_patch_unified import *
|
| 3 |
from app_patch_unified import app, UNIFIED_INJECT, f5, f6, rt, PATCH_INJECT
|
| 4 |
from fastapi.responses import HTMLResponse
|
| 5 |
|
| 6 |
+
# Build fixed UNIFIED_INJECT
|
|
|
|
|
|
|
| 7 |
UNIFIED_INJECT_FIXED = UNIFIED_INJECT.replace(
|
| 8 |
"""Object.defineProperty(window,'renderAIShorts7',{get:function(){return function(){}},set:function(){},configurable:true});""",
|
| 9 |
"""Object.defineProperty(window,'renderAIShorts7',{get:function(){return function(){}},set:function(){},configurable:true});
|
|
|
|
| 21 |
"var articles=(window._hlLeagueData||{})[league]||[];\n if(!articles.length){try{var _r=await fetch('/api/highlights/'+league);articles=await _r.json();if(!Array.isArray(articles))articles=[];}catch(e){articles=[];}}\n if(!articles.length){el.innerHTML="
|
| 22 |
)
|
| 23 |
|
| 24 |
+
# Add CSS to hide duplicate wall from loadHome + JS to ensure wall renders after bg refresh
|
| 25 |
+
EXTRA_WALL_FIX = r'''
|
| 26 |
+
<style>
|
| 27 |
+
/* Hide the wall slide from loadHome (data-wall-live) to avoid duplicate — we use renderShortAISlide/PATCH_INJECT wall only */
|
| 28 |
+
[data-wall-live="1"]{display:none!important}
|
| 29 |
+
</style>
|
| 30 |
+
<script>
|
| 31 |
+
(function(){
|
| 32 |
+
// After homepage background loads, re-trigger renderShortAISlide to show Tường AI + Short AI
|
| 33 |
+
var _wallCheck=setInterval(function(){
|
| 34 |
+
var home=document.getElementById('view-home');
|
| 35 |
+
if(!home||!home.classList.contains('active'))return;
|
| 36 |
+
// Check if slides exist
|
| 37 |
+
var hasWall=document.getElementById('short-ai-final-slide')||document.querySelector('[data-wall-live="1"]:not([style*="display:none"])');
|
| 38 |
+
if(!hasWall&&typeof renderShortAISlide==='function'){
|
| 39 |
+
renderShortAISlide();
|
| 40 |
+
}
|
| 41 |
+
// Also ensure AI wall from PATCH_INJECT is visible
|
| 42 |
+
var patchWall=document.querySelector('.ai-wall-patched,.slider-wrap[data-wall-live]');
|
| 43 |
+
if(!patchWall){
|
| 44 |
+
// Try to render wall from /api/ai_wall
|
| 45 |
+
fetch('/api/ai_wall').then(function(r){return r.json()}).then(function(j){
|
| 46 |
+
var posts=(j&&j.posts)||[];
|
| 47 |
+
if(!posts.length)return;
|
| 48 |
+
if(typeof window._serverWall!=='undefined')window._serverWall=posts;
|
| 49 |
+
if(typeof prependWallPost==='function'&&posts[0])prependWallPost(posts[0]);
|
| 50 |
+
}).catch(function(){});
|
| 51 |
+
}
|
| 52 |
+
},4000);
|
| 53 |
+
// Stop checking after 30s
|
| 54 |
+
setTimeout(function(){clearInterval(_wallCheck);},30000);
|
| 55 |
+
})();
|
| 56 |
+
</script>
|
| 57 |
+
'''
|
| 58 |
+
|
| 59 |
app.router.routes = [r for r in app.router.routes if not (getattr(r,'path',None)=='/' and 'GET' in getattr(r,'methods',set()))]
|
| 60 |
|
| 61 |
@app.get('/')
|
|
|
|
| 69 |
body += getattr(f6,'FINAL6E_INJECT','')
|
| 70 |
body += PATCH_INJECT
|
| 71 |
body += UNIFIED_INJECT_FIXED
|
| 72 |
+
body += EXTRA_WALL_FIX
|
| 73 |
return HTMLResponse(html.replace('</body>', body + '\n</body>') if '</body>' in html else html + body)
|