
(function(){
  window.MJToast=function(msg,type){ if(window.toastr){toastr[type||'info'](msg);return;} console.log(msg); };
  document.addEventListener('click',function(e){
    var t=e.target.closest('[data-copy]'); if(t){navigator.clipboard&&navigator.clipboard.writeText(t.getAttribute('data-copy')); t.classList.add('copied'); setTimeout(()=>t.classList.remove('copied'),800);}
  });
  window.addEventListener('error', function(e){
    try{ fetch((window.MJ_BASE_URL||'') + '/ajax/log-js-error.php',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({message:e.message,source:e.filename,line:e.lineno,column:e.colno,stack:e.error?e.error.stack:'',url:location.href,userAgent:navigator.userAgent})}); }catch(x){}
  });
  window.addEventListener('unhandledrejection', function(e){
    try{ fetch((window.MJ_BASE_URL||'') + '/ajax/log-js-error.php',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({message:'Unhandled Promise Rejection',stack:e.reason?(e.reason.stack||String(e.reason)):'',url:location.href,userAgent:navigator.userAgent})}); }catch(x){}
  });
})();
