Spaces:
Running
Running
Fix: inline doShare same sync-copy pattern
Browse files- static/index_v2.html +5 -5
static/index_v2.html
CHANGED
|
@@ -45,11 +45,11 @@ function doShare(title,url,img,postId){
|
|
| 45 |
.substring(0,60) || 'article';
|
| 46 |
shareUrl = SPACE + '/s/' + slug + '?url=' + encodeURIComponent(url) + '&img=' + encodeURIComponent(img||'');
|
| 47 |
}
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
}
|
| 51 |
-
if(navigator.share)
|
| 52 |
-
|
| 53 |
}
|
| 54 |
async function init(){_cats=await fetch('/api/categories').then(r=>r.json()).catch(()=>[]);let bar='<div class="cat active" data-cat="home">🏠</div><div class="cat" data-cat="news-all">📰 Tin tức</div>';_cats.forEach(c=>{bar+='<div class="cat" data-cat="'+c.id+'">'+c.name+'</div>'});document.getElementById('cat-bar').innerHTML=bar;document.querySelectorAll('.cat').forEach(t=>{t.onclick=()=>switchCat(t.dataset.cat)});}
|
| 55 |
var SPACE=location.origin;
|
|
|
|
| 45 |
.substring(0,60) || 'article';
|
| 46 |
shareUrl = SPACE + '/s/' + slug + '?url=' + encodeURIComponent(url) + '&img=' + encodeURIComponent(img||'');
|
| 47 |
}
|
| 48 |
+
// Sync copy first (preserves user gesture)
|
| 49 |
+
var ok=false;
|
| 50 |
+
try{var ta=document.createElement('textarea');ta.value=shareUrl;ta.style.position='fixed';ta.style.left='-9999px';ta.style.top='-9999px';ta.style.opacity='0';document.body.appendChild(ta);ta.select();ta.setSelectionRange(0,99999);ok=document.execCommand('copy');document.body.removeChild(ta);}catch(e){}
|
| 51 |
+
try{if(navigator.share)navigator.share({title:title||'',url:shareUrl}).catch(function(){});}catch(e){}
|
| 52 |
+
if(ok){toast('📋 Đã sao chép link!');}else{try{prompt('Sao chép link:', shareUrl);}catch(e){toast('❌ Không thể chia sẻ');}}
|
| 53 |
}
|
| 54 |
async function init(){_cats=await fetch('/api/categories').then(r=>r.json()).catch(()=>[]);let bar='<div class="cat active" data-cat="home">🏠</div><div class="cat" data-cat="news-all">📰 Tin tức</div>';_cats.forEach(c=>{bar+='<div class="cat" data-cat="'+c.id+'">'+c.name+'</div>'});document.getElementById('cat-bar').innerHTML=bar;document.querySelectorAll('.cat').forEach(t=>{t.onclick=()=>switchCat(t.dataset.cat)});}
|
| 55 |
var SPACE=location.origin;
|