Spaces:
Running
Running
Fix: don't delete new slides, keep Short AI button after rewrite, faster home"
Browse files- patch_extra.py +28 -11
patch_extra.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
"""Extra CSS/JS fixes: tiktok-right position,
|
| 2 |
EXTRA_FIX = r'''
|
| 3 |
<style>
|
| 4 |
/* Force correct position for Short AI interaction buttons */
|
|
@@ -10,18 +10,23 @@ EXTRA_FIX = r'''
|
|
| 10 |
#short-progress-toast{position:fixed;bottom:70px;left:50%;transform:translateX(-50%);background:#1a1a1a;border:1px solid #2d8659;color:#fff;padding:12px 20px;border-radius:14px;font-size:12px;z-index:99998;box-shadow:0 4px 16px rgba(0,0,0,.5);display:none;min-width:240px;text-align:center}
|
| 11 |
#short-progress-toast .bar{height:4px;background:#333;border-radius:2px;margin-top:8px;overflow:hidden}
|
| 12 |
#short-progress-toast .bar-fill{height:100%;background:#2d8659;border-radius:2px;width:0%;transition:width 1s linear}
|
| 13 |
-
/*
|
| 14 |
-
#ai-short-home,.ai-short-home,.ai-short-card-final
|
| 15 |
</style>
|
| 16 |
<div id="short-progress-toast"><span id="short-progress-text">Đang tạo...</span><div class="bar"><div class="bar-fill" id="short-progress-bar"></div></div></div>
|
| 17 |
<script>
|
| 18 |
(function(){
|
| 19 |
-
// Kill old renderers that create
|
| 20 |
-
window.renderAIShortHome=function(){};
|
| 21 |
window.renderAIShorts7=function(){};
|
| 22 |
window.renderTopicWallE=function(){};
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
// Progress bar for short creation
|
| 27 |
var _progressInterval=null;
|
|
@@ -29,7 +34,7 @@ window.showShortProgress=function(msg,pct){
|
|
| 29 |
var t=document.getElementById('short-progress-toast');
|
| 30 |
var txt=document.getElementById('short-progress-text');
|
| 31 |
var bar=document.getElementById('short-progress-bar');
|
| 32 |
-
if(t)
|
| 33 |
if(txt)txt.textContent=msg||'Đang tạo...';
|
| 34 |
if(bar)bar.style.width=(pct||0)+'%';
|
| 35 |
};
|
|
@@ -40,13 +45,12 @@ window.hideShortProgress=function(){
|
|
| 40 |
window.startShortProgressSimulation=function(){
|
| 41 |
var pct=0;showShortProgress('⏳ Đang tạo Short AI... 0%',0);
|
| 42 |
_progressInterval=setInterval(function(){
|
| 43 |
-
pct+=Math.random()*
|
| 44 |
-
if(pct>92)pct=92;
|
| 45 |
showShortProgress('⏳ Đang tạo Short AI... '+Math.round(pct)+'%',pct);
|
| 46 |
},2000);
|
| 47 |
};
|
| 48 |
|
| 49 |
-
// Override makeShortFromPost to use progress bar
|
| 50 |
window.makeShortFromPost=async function(pid,btn){
|
| 51 |
startShortProgressSimulation();
|
| 52 |
if(btn){btn.disabled=true;btn.textContent='Đang tạo...';}
|
|
@@ -64,6 +68,19 @@ window.makeShortFromPost=async function(pid,btn){
|
|
| 64 |
if(btn){btn.disabled=false;btn.textContent='🎬 Tạo Short AI';}
|
| 65 |
}
|
| 66 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
})();
|
| 68 |
</script>
|
| 69 |
'''
|
|
|
|
| 1 |
+
"""Extra CSS/JS fixes: tiktok-right position, progress bar, careful duplicate removal."""
|
| 2 |
EXTRA_FIX = r'''
|
| 3 |
<style>
|
| 4 |
/* Force correct position for Short AI interaction buttons */
|
|
|
|
| 10 |
#short-progress-toast{position:fixed;bottom:70px;left:50%;transform:translateX(-50%);background:#1a1a1a;border:1px solid #2d8659;color:#fff;padding:12px 20px;border-radius:14px;font-size:12px;z-index:99998;box-shadow:0 4px 16px rgba(0,0,0,.5);display:none;min-width:240px;text-align:center}
|
| 11 |
#short-progress-toast .bar{height:4px;background:#333;border-radius:2px;margin-top:8px;overflow:hidden}
|
| 12 |
#short-progress-toast .bar-fill{height:100%;background:#2d8659;border-radius:2px;width:0%;transition:width 1s linear}
|
| 13 |
+
/* Hide ONLY old duplicate Short AI slides - NOT our new #short-ai-final-slide */
|
| 14 |
+
#ai-short-home:not(#short-ai-final-slide),.ai-short-home:not(#short-ai-final-slide),.ai-short-card-final{display:none!important}
|
| 15 |
</style>
|
| 16 |
<div id="short-progress-toast"><span id="short-progress-text">Đang tạo...</span><div class="bar"><div class="bar-fill" id="short-progress-bar"></div></div></div>
|
| 17 |
<script>
|
| 18 |
(function(){
|
| 19 |
+
// Kill ONLY old renderers that create DUPLICATE slides. Do NOT kill renderShortAISlide (our new one).
|
| 20 |
+
if(window.renderAIShortHome && window.renderAIShortHome.toString().indexOf('short-ai-final-slide')===-1) window.renderAIShortHome=function(){};
|
| 21 |
window.renderAIShorts7=function(){};
|
| 22 |
window.renderTopicWallE=function(){};
|
| 23 |
+
|
| 24 |
+
// Remove only old duplicate slides (not our #short-ai-final-slide)
|
| 25 |
+
setInterval(function(){
|
| 26 |
+
document.querySelectorAll('#ai-short-home,.ai-short-home').forEach(function(el){
|
| 27 |
+
if(el.id!=='short-ai-final-slide')el.remove();
|
| 28 |
+
});
|
| 29 |
+
},3000);
|
| 30 |
|
| 31 |
// Progress bar for short creation
|
| 32 |
var _progressInterval=null;
|
|
|
|
| 34 |
var t=document.getElementById('short-progress-toast');
|
| 35 |
var txt=document.getElementById('short-progress-text');
|
| 36 |
var bar=document.getElementById('short-progress-bar');
|
| 37 |
+
if(t)t.style.display='block';
|
| 38 |
if(txt)txt.textContent=msg||'Đang tạo...';
|
| 39 |
if(bar)bar.style.width=(pct||0)+'%';
|
| 40 |
};
|
|
|
|
| 45 |
window.startShortProgressSimulation=function(){
|
| 46 |
var pct=0;showShortProgress('⏳ Đang tạo Short AI... 0%',0);
|
| 47 |
_progressInterval=setInterval(function(){
|
| 48 |
+
pct+=Math.random()*6+2;if(pct>94)pct=94;
|
|
|
|
| 49 |
showShortProgress('⏳ Đang tạo Short AI... '+Math.round(pct)+'%',pct);
|
| 50 |
},2000);
|
| 51 |
};
|
| 52 |
|
| 53 |
+
// Override makeShortFromPost to use progress bar (keeps Short AI button working after rewrite)
|
| 54 |
window.makeShortFromPost=async function(pid,btn){
|
| 55 |
startShortProgressSimulation();
|
| 56 |
if(btn){btn.disabled=true;btn.textContent='Đang tạo...';}
|
|
|
|
| 68 |
if(btn){btn.disabled=false;btn.textContent='🎬 Tạo Short AI';}
|
| 69 |
}
|
| 70 |
};
|
| 71 |
+
|
| 72 |
+
// Prevent old layers from triggering heavy YouTube refresh on first load
|
| 73 |
+
// (shorts already served from background cache via /api/shorts without refresh=1)
|
| 74 |
+
var _origFetch=window.fetch;
|
| 75 |
+
var _allowRefresh=false;
|
| 76 |
+
window.fetch=function(url,opts){
|
| 77 |
+
try{
|
| 78 |
+
var u=String(url||'');
|
| 79 |
+
if(u.includes('/api/shorts?refresh=1')&&!_allowRefresh)url='/api/shorts';
|
| 80 |
+
}catch(e){}
|
| 81 |
+
return _origFetch.call(this,url,opts);
|
| 82 |
+
};
|
| 83 |
+
setTimeout(function(){_allowRefresh=true;},8000);
|
| 84 |
})();
|
| 85 |
</script>
|
| 86 |
'''
|