Spaces:
Running
Running
Fix: doShare uses navigator.clipboard.writeText as primary (works on Chrome mobile); overflow:clip for inline comments
Browse files- static/app_v2.js +29 -21
static/app_v2.js
CHANGED
|
@@ -395,7 +395,7 @@ function showView(id){document.querySelectorAll('.view').forEach(v=>v.classList.
|
|
| 395 |
function switchCat(id){document.querySelectorAll('.cat').forEach(c=>c.classList.remove('active'));document.querySelector(`[data-cat="${id}"]`)?.classList.add('active');document.querySelectorAll('.view').forEach(v=>v.classList.remove('active'));document.querySelectorAll('video').forEach(v=>{v.pause();if(v._hls){v._hls.destroy();v._hls=null}});document.querySelectorAll('iframe[data-yt-src]').forEach(f=>{f.src=''});if(id==='home')document.getElementById('view-home').classList.add('active');else if(id==='news-all'){document.getElementById('view-cat').classList.add('active');loadNewsTab()}else{document.getElementById('view-cat').classList.add('active');loadCat(id)}}
|
| 396 |
function toast(msg){let t=document.getElementById('progress-toast');if(t){t.textContent=msg;t.style.display='block';setTimeout(()=>{t.style.display='none'},3500)}}
|
| 397 |
|
| 398 |
-
// =====
|
| 399 |
function doShare(title,url,img,postId){
|
| 400 |
var shareUrl;
|
| 401 |
if(postId){
|
|
@@ -403,26 +403,34 @@ function doShare(title,url,img,postId){
|
|
| 403 |
} else {
|
| 404 |
shareUrl = SPACE+'/s?url='+encodeURIComponent(url)+'&title='+encodeURIComponent(title)+'&img='+encodeURIComponent(img||'');
|
| 405 |
}
|
| 406 |
-
//
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
else{
|
| 424 |
-
//
|
| 425 |
-
try{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 426 |
}
|
| 427 |
}
|
| 428 |
|
|
|
|
| 395 |
function switchCat(id){document.querySelectorAll('.cat').forEach(c=>c.classList.remove('active'));document.querySelector(`[data-cat="${id}"]`)?.classList.add('active');document.querySelectorAll('.view').forEach(v=>v.classList.remove('active'));document.querySelectorAll('video').forEach(v=>{v.pause();if(v._hls){v._hls.destroy();v._hls=null}});document.querySelectorAll('iframe[data-yt-src]').forEach(f=>{f.src=''});if(id==='home')document.getElementById('view-home').classList.add('active');else if(id==='news-all'){document.getElementById('view-cat').classList.add('active');loadNewsTab()}else{document.getElementById('view-cat').classList.add('active');loadCat(id)}}
|
| 396 |
function toast(msg){let t=document.getElementById('progress-toast');if(t){t.textContent=msg;t.style.display='block';setTimeout(()=>{t.style.display='none'},3500)}}
|
| 397 |
|
| 398 |
+
// ===== doShare: COPY link to clipboard, then try native share as bonus =====
|
| 399 |
function doShare(title,url,img,postId){
|
| 400 |
var shareUrl;
|
| 401 |
if(postId){
|
|
|
|
| 403 |
} else {
|
| 404 |
shareUrl = SPACE+'/s?url='+encodeURIComponent(url)+'&title='+encodeURIComponent(title)+'&img='+encodeURIComponent(img||'');
|
| 405 |
}
|
| 406 |
+
// Try clipboard API first (modern, works on HTTPS)
|
| 407 |
+
if(navigator.clipboard && navigator.clipboard.writeText){
|
| 408 |
+
navigator.clipboard.writeText(shareUrl).then(function(){
|
| 409 |
+
toast('📋 Đã sao chép link!');
|
| 410 |
+
try{if(navigator.share)navigator.share({title:title||'',url:shareUrl}).catch(function(){});}catch(e){}
|
| 411 |
+
}).catch(function(){
|
| 412 |
+
// Fallback: execCommand (deprecated but works on some browsers)
|
| 413 |
+
try{
|
| 414 |
+
var ta=document.createElement('textarea');
|
| 415 |
+
ta.value=shareUrl;ta.style.position='fixed';ta.style.left='-9999px';ta.style.top='-9999px';ta.style.opacity='0';
|
| 416 |
+
document.body.appendChild(ta);ta.select();ta.setSelectionRange(0,99999);
|
| 417 |
+
if(document.execCommand('copy')){toast('📋 Đã sao chép link!');}
|
| 418 |
+
else{prompt('📋 Sao chép link:', shareUrl);}
|
| 419 |
+
document.body.removeChild(ta);
|
| 420 |
+
}catch(e){prompt('📋 Sao chép link:', shareUrl);}
|
| 421 |
+
try{if(navigator.share)navigator.share({title:title||'',url:shareUrl}).catch(function(){});}catch(e){}
|
| 422 |
+
});
|
| 423 |
+
} else {
|
| 424 |
+
// execCommand approach
|
| 425 |
+
try{
|
| 426 |
+
var ta=document.createElement('textarea');
|
| 427 |
+
ta.value=shareUrl;ta.style.position='fixed';ta.style.left='-9999px';ta.style.top='-9999px';ta.style.opacity='0';
|
| 428 |
+
document.body.appendChild(ta);ta.select();ta.setSelectionRange(0,99999);
|
| 429 |
+
if(document.execCommand('copy')){toast('📋 Đã sao chép link!');}
|
| 430 |
+
else{prompt('📋 Sao chép link:', shareUrl);}
|
| 431 |
+
document.body.removeChild(ta);
|
| 432 |
+
}catch(e){prompt('📋 Sao chép link:', shareUrl);}
|
| 433 |
+
try{if(navigator.share)navigator.share({title:title||'',url:shareUrl}).catch(function(){});}catch(e){}
|
| 434 |
}
|
| 435 |
}
|
| 436 |
|