bep40 commited on
Commit
883b31a
·
verified ·
1 Parent(s): 213cd45

Fix: inline doShare same sync-copy pattern

Browse files
Files changed (1) hide show
  1. 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
- function copyFb(){
49
- try{var ta=document.createElement('textarea');ta.value=shareUrl;ta.style.position='fixed';ta.style.opacity='0';document.body.appendChild(ta);ta.select();document.execCommand('copy');document.body.removeChild(ta);toast('Đã sao chép!');}catch(e){toast('❌ Không thể chia sẻ');}
50
- }
51
- if(navigator.share){navigator.share({title:title||'',url:shareUrl}).catch(function(){copyFb();});}
52
- else{if(navigator.clipboard&&navigator.clipboard.writeText){navigator.clipboard.writeText(shareUrl).then(function(){toast('Đã sao chép!');}).catch(function(){copyFb();});}else{copyFb();}}
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;