mg696 commited on
Commit
dbfa340
·
verified ·
1 Parent(s): 032e6f3

v115: force debug copy button status on all pointer events

Browse files
Files changed (1) hide show
  1. copy-fix-v115.js +12 -27
copy-fix-v115.js CHANGED
@@ -5,43 +5,28 @@
5
  const logEl=document.getElementById('debug-log');
6
  if(!btn||!logEl||btn.__copyFixV115)return;
7
  btn.__copyFixV115=true;
8
- function setStatus(ok){
9
  btn.textContent=ok?'✅コピー完了':'⚠コピー失敗';
10
  btn.style.background=ok?'#064':'#700';
11
  btn.style.color='#fff';
12
  setTimeout(()=>{btn.textContent='📋 Copy All';btn.style.background='';btn.style.color='';},1800);
13
  }
14
- async function doCopy(e){
15
- if(e){e.preventDefault();e.stopPropagation();e.stopImmediatePropagation&&e.stopImmediatePropagation();}
16
  const text=logEl.innerText||'';
17
  try{
18
- if(navigator.clipboard&&navigator.clipboard.writeText){
19
- await navigator.clipboard.writeText(text);
20
- setStatus(true);
21
- return;
22
- }
23
- }catch(err){}
24
  try{
25
  const ta=document.createElement('textarea');
26
- ta.value=text;
27
- ta.setAttribute('readonly','');
28
- ta.style.position='fixed';
29
- ta.style.left='0';
30
- ta.style.top='0';
31
- ta.style.width='2px';
32
- ta.style.height='2px';
33
- ta.style.opacity='0.01';
34
- document.body.appendChild(ta);
35
- ta.focus();
36
- ta.select();
37
- ta.setSelectionRange(0,ta.value.length);
38
- const ok=document.execCommand('copy');
39
- document.body.removeChild(ta);
40
- setStatus(!!ok);
41
- }catch(err){setStatus(false)}
42
  }
43
- ['click','touchend','pointerup'].forEach(ev=>btn.addEventListener(ev,doCopy,true));
44
  }
45
  if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',install);else install();
46
- setInterval(install,1000);
47
  })();
 
5
  const logEl=document.getElementById('debug-log');
6
  if(!btn||!logEl||btn.__copyFixV115)return;
7
  btn.__copyFixV115=true;
8
+ function status(ok){
9
  btn.textContent=ok?'✅コピー完了':'⚠コピー失敗';
10
  btn.style.background=ok?'#064':'#700';
11
  btn.style.color='#fff';
12
  setTimeout(()=>{btn.textContent='📋 Copy All';btn.style.background='';btn.style.color='';},1800);
13
  }
14
+ async function run(e){
15
+ if(e){e.preventDefault();e.stopPropagation();if(e.stopImmediatePropagation)e.stopImmediatePropagation();}
16
  const text=logEl.innerText||'';
17
  try{
18
+ if(navigator.clipboard&&navigator.clipboard.writeText){await navigator.clipboard.writeText(text);status(true);return;}
19
+ }catch(_e){}
 
 
 
 
20
  try{
21
  const ta=document.createElement('textarea');
22
+ ta.value=text;ta.readOnly=true;
23
+ ta.style.position='fixed';ta.style.left='0';ta.style.top='0';ta.style.width='2px';ta.style.height='2px';ta.style.opacity='0.01';ta.style.zIndex='999999';
24
+ document.body.appendChild(ta);ta.focus();ta.select();ta.setSelectionRange(0,ta.value.length);
25
+ const ok=document.execCommand('copy');document.body.removeChild(ta);status(!!ok);
26
+ }catch(_e){status(false)}
 
 
 
 
 
 
 
 
 
 
 
27
  }
28
+ ['touchstart','touchend','pointerdown','pointerup','click'].forEach(ev=>btn.addEventListener(ev,run,true));
29
  }
30
  if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',install);else install();
31
+ setInterval(install,500);
32
  })();