Spaces:
Running
Running
FINAL FIX: native value setter + Textbox.input() + sr-only visible
Browse files
app.py
CHANGED
|
@@ -637,7 +637,7 @@ body,html{margin:0!important;padding:0!important;overflow-x:hidden;background:#1
|
|
| 637 |
.gradio-container>.main>.contain{padding-top:0!important}
|
| 638 |
.gap{gap:0!important}
|
| 639 |
footer,.built-with{display:none!important}
|
| 640 |
-
#article-url-input{
|
| 641 |
.bdp-header{background:linear-gradient(135deg,#0d1117,#1a3a2a 50%,#8b7500);padding:14px 16px;text-align:center}
|
| 642 |
.bdp-header h1{color:#fff;font-size:20px;margin:0;font-weight:800;text-shadow:0 2px 6px rgba(0,0,0,.4)}
|
| 643 |
.bdp-header p{color:rgba(255,255,255,.6);font-size:11px;margin:2px 0 0}
|
|
@@ -774,24 +774,14 @@ var SPACE='https://bep40-bongdaplus-news.hf.space';
|
|
| 774 |
window.bdpOpen=function(url,aid,sl){
|
| 775 |
window.location.hash='#/'+sl+'/'+aid;
|
| 776 |
try{localStorage.setItem('bdp_url_'+aid,url);}catch(e){}
|
| 777 |
-
|
| 778 |
-
|
| 779 |
-
|
| 780 |
-
|
| 781 |
-
|
| 782 |
-
|
| 783 |
-
|
| 784 |
-
});
|
| 785 |
-
if(!found){
|
| 786 |
-
/* Fallback: search all Gradio textboxes */
|
| 787 |
-
document.querySelectorAll('textarea, input[type="text"]').forEach(function(ta){
|
| 788 |
-
if(ta.closest('#article-url-input')||ta.closest('[id*="article-url"]')){
|
| 789 |
-
ta.value=url;
|
| 790 |
-
ta.dispatchEvent(new Event('input',{bubbles:true}));
|
| 791 |
-
ta.dispatchEvent(new KeyboardEvent('keydown',{key:'Enter',code:'Enter',keyCode:13,which:13,bubbles:true}));
|
| 792 |
-
}
|
| 793 |
-
});
|
| 794 |
-
}
|
| 795 |
window.scrollTo({top:0,behavior:'smooth'});
|
| 796 |
};
|
| 797 |
|
|
@@ -958,7 +948,7 @@ window.addEventListener('load',function(){var h=window.location.hash;if(h&&h.sta
|
|
| 958 |
# ══════════════════════════════════════════════════════════════════════════════
|
| 959 |
with gr.Blocks(title="Tin Tức Việt Nam",css=CSS,head=JS_HEAD,theme=gr.themes.Base(),fill_width=True) as demo:
|
| 960 |
gr.HTML('<div class="bdp-header"><h1>📰 Tin Tức Việt Nam</h1><p>VnExpress · BongDaPlus · Thời sự · Thế giới · Kinh doanh · Công nghệ · Thể thao · Giải trí · Video</p></div>')
|
| 961 |
-
article_url=gr.Textbox(value="",elem_id="article-url-input",
|
| 962 |
with gr.Row(elem_classes=["controls-row"]):
|
| 963 |
cat=gr.Dropdown(choices=list(CATEGORIES.keys()),value="🏠 Trang Chủ (Nổi Bật)",label="Chuyên mục",scale=3,interactive=True)
|
| 964 |
ref_btn=gr.Button("🔄 Làm mới",variant="primary",scale=1)
|
|
@@ -971,8 +961,8 @@ with gr.Blocks(title="Tin Tức Việt Nam",css=CSS,head=JS_HEAD,theme=gr.themes
|
|
| 971 |
return (gr.update(visible=False),gr.update(value=read_article(url),visible=True),gr.update(visible=False),gr.update(visible=True),"")
|
| 972 |
def show_list(c):
|
| 973 |
return (gr.update(value=fetch_news_list(c),visible=True),gr.update(visible=False),gr.update(visible=True),gr.update(visible=False))
|
| 974 |
-
#
|
| 975 |
-
article_url.
|
| 976 |
back_btn.click(fn=show_list,inputs=[cat],outputs=[news_list,article_view,ref_btn,back_btn])
|
| 977 |
ref_btn.click(fn=show_list,inputs=[cat],outputs=[news_list,article_view,ref_btn,back_btn])
|
| 978 |
cat.change(fn=show_list,inputs=[cat],outputs=[news_list,article_view,ref_btn,back_btn])
|
|
|
|
| 637 |
.gradio-container>.main>.contain{padding-top:0!important}
|
| 638 |
.gap{gap:0!important}
|
| 639 |
footer,.built-with{display:none!important}
|
| 640 |
+
#article-url-input,.sr-only{position:absolute!important;width:1px!important;height:1px!important;padding:0!important;margin:-1px!important;overflow:hidden!important;clip:rect(0,0,0,0)!important;border:0!important}
|
| 641 |
.bdp-header{background:linear-gradient(135deg,#0d1117,#1a3a2a 50%,#8b7500);padding:14px 16px;text-align:center}
|
| 642 |
.bdp-header h1{color:#fff;font-size:20px;margin:0;font-weight:800;text-shadow:0 2px 6px rgba(0,0,0,.4)}
|
| 643 |
.bdp-header p{color:rgba(255,255,255,.6);font-size:11px;margin:2px 0 0}
|
|
|
|
| 774 |
window.bdpOpen=function(url,aid,sl){
|
| 775 |
window.location.hash='#/'+sl+'/'+aid;
|
| 776 |
try{localStorage.setItem('bdp_url_'+aid,url);}catch(e){}
|
| 777 |
+
var w=document.querySelector('#article-url-input');
|
| 778 |
+
if(!w) return;
|
| 779 |
+
var el=w.querySelector('input')||w.querySelector('textarea');
|
| 780 |
+
if(!el) return;
|
| 781 |
+
var d=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,'value');
|
| 782 |
+
if(el.tagName==='TEXTAREA') d=Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype,'value');
|
| 783 |
+
if(d&&d.set) d.set.call(el,url);
|
| 784 |
+
el.dispatchEvent(new Event('input',{bubbles:true}));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 785 |
window.scrollTo({top:0,behavior:'smooth'});
|
| 786 |
};
|
| 787 |
|
|
|
|
| 948 |
# ══════════════════════════════════════════════════════════════════════════════
|
| 949 |
with gr.Blocks(title="Tin Tức Việt Nam",css=CSS,head=JS_HEAD,theme=gr.themes.Base(),fill_width=True) as demo:
|
| 950 |
gr.HTML('<div class="bdp-header"><h1>📰 Tin Tức Việt Nam</h1><p>VnExpress · BongDaPlus · Thời sự · Thế giới · Kinh doanh · Công nghệ · Thể thao · Giải trí · Video</p></div>')
|
| 951 |
+
article_url=gr.Textbox(value="",elem_id="article-url-input",elem_classes=["sr-only"],max_lines=1)
|
| 952 |
with gr.Row(elem_classes=["controls-row"]):
|
| 953 |
cat=gr.Dropdown(choices=list(CATEGORIES.keys()),value="🏠 Trang Chủ (Nổi Bật)",label="Chuyên mục",scale=3,interactive=True)
|
| 954 |
ref_btn=gr.Button("🔄 Làm mới",variant="primary",scale=1)
|
|
|
|
| 961 |
return (gr.update(visible=False),gr.update(value=read_article(url),visible=True),gr.update(visible=False),gr.update(visible=True),"")
|
| 962 |
def show_list(c):
|
| 963 |
return (gr.update(value=fetch_news_list(c),visible=True),gr.update(visible=False),gr.update(visible=True),gr.update(visible=False))
|
| 964 |
+
# Triggered by JS setting value via native setter + dispatching 'input' event
|
| 965 |
+
article_url.input(fn=show_article,inputs=[article_url],outputs=[news_list,article_view,ref_btn,back_btn,article_url])
|
| 966 |
back_btn.click(fn=show_list,inputs=[cat],outputs=[news_list,article_view,ref_btn,back_btn])
|
| 967 |
ref_btn.click(fn=show_list,inputs=[cat],outputs=[news_list,article_view,ref_btn,back_btn])
|
| 968 |
cat.change(fn=show_list,inputs=[cat],outputs=[news_list,article_view,ref_btn,back_btn])
|