From 0547e165ab769213e391c0e19f990835cbc64b36 Mon Sep 17 00:00:00 2001 From: nanhaoluo <3075912108@qq.com> Date: Thu, 15 Jan 2026 23:41:10 +0800 Subject: [PATCH] =?UTF-8?q?debug:=20=E6=B7=BB=E5=8A=A0=E6=9B=B4=E5=A4=9A?= =?UTF-8?q?=E8=B0=83=E8=AF=95=E6=97=A5=E5=BF=97=EF=BC=8C=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E6=8E=A7=E5=88=B6=E5=8F=B0=E6=94=AF=E6=8C=81=E9=95=BF=E6=8C=89?= =?UTF-8?q?=E5=A4=8D=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在侧边栏打开事件中添加日志 - 调试控制台日志项支持长按复制(移动端) - 复制时显示绿色高亮反馈 --- argontheme.js | 3 +++ functions.php | 13 +++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/argontheme.js b/argontheme.js index c484939..0f9d1bf 100644 --- a/argontheme.js +++ b/argontheme.js @@ -2437,12 +2437,15 @@ $(document).on("click" , "#blog_categories .tag" , function(){ /*侧栏 & 顶栏菜单手机适配*/ !function(){ $(document).on("click" , "#fabtn_open_sidebar, #open_sidebar" , function(){ + console.log('[Mobile Sidebar] Sidebar opened'); $("html").addClass("leftbar-opened"); // 侧边栏打开时初始化移动端文章目录 + console.log('[Mobile Sidebar] Calling initMobileCatalog'); initMobileCatalog(); // 如果有文章目录,默认展开 setTimeout(function() { var catalogSection = $("#mobile_catalog_toggle").closest(".leftbar-mobile-collapse-section"); + console.log('[Mobile Sidebar] Catalog section found:', catalogSection.length); if (catalogSection.length > 0 && !catalogSection.hasClass("expanded")) { catalogSection.addClass("expanded"); initMobileCatalog(); diff --git a/functions.php b/functions.php index 43bda6f..9e6e5f1 100644 --- a/functions.php +++ b/functions.php @@ -626,7 +626,7 @@ function argon_debug_console_script() { #argon-debug-console-body{flex:1;overflow-y:auto;padding:10px} #argon-debug-console-body::-webkit-scrollbar{width:8px} #argon-debug-console-body::-webkit-scrollbar-thumb{background:#444;border-radius:4px} - .debug-log-item{padding:8px 12px;margin-bottom:4px;border-radius:4px;background:#2d2d2d;color:#d4d4d4;word-break:break-all;position:relative;font-size:11px;line-height:1.6} + .debug-log-item{padding:8px 12px;margin-bottom:4px;border-radius:4px;background:#2d2d2d;color:#d4d4d4;word-break:break-all;position:relative;font-size:11px;line-height:1.6;user-select:text;-webkit-user-select:text} .debug-log-item.log{border-left:3px solid #6c757d} .debug-log-item.warn{border-left:3px solid #ffc107;background:#3d3520;color:#ffc107} .debug-log-item.error{border-left:3px solid #f5365c;background:#3d2020;color:#ff6b6b} @@ -635,6 +635,8 @@ function argon_debug_console_script() { .debug-log-item .mute-btn{position:absolute;top:6px;right:6px;background:#f5365c;color:#fff;border:none;padding:3px 10px;border-radius:4px;font-size:10px;cursor:pointer;opacity:0} .debug-log-item:hover .mute-btn{opacity:1} .debug-log-item.muted{opacity:0.5} + .debug-log-item.copying{background:#3a5a3a !important} + .debug-copy-toast{position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);background:rgba(0,0,0,0.8);color:#fff;padding:10px 20px;border-radius:8px;z-index:100001;font-size:12px} #argon-error-toast{position:fixed;top:20px;left:50%;transform:translateX(-50%);background:#f5365c;color:#fff;padding:12px 20px;border-radius:8px;box-shadow:0 4px 20px rgba(245,54,92,0.4);z-index:100000;display:none;align-items:center;gap:12px;max-width:90vw;animation:argonToastIn .3s ease} @keyframes argonToastIn{from{opacity:0;transform:translateX(-50%) translateY(-20px)}to{opacity:1;transform:translateX(-50%) translateY(0)}} #argon-error-toast.show{display:flex} @@ -791,7 +793,14 @@ function argon_debug_console_script() { function showErrorToast(m,h){if(isMuted(h))return;var t=document.getElementById('argon-error-toast');if(!t)return;var dm=isAdmin?m:'';t.querySelector('.message').textContent=dm.length>80?dm.substring(0,80)+'...':dm;t.classList.add('show');setTimeout(function(){t.classList.remove('show');},5000);} function updateCounts(){document.getElementById('count-all').textContent=counts.all;document.getElementById('count-log').textContent=counts.log;document.getElementById('count-warn').textContent=counts.warn;document.getElementById('count-error').textContent=counts.error;var b=document.getElementById('argon-debug-error-count');if(b){b.textContent=counts.error;b.style.display=counts.error>0?'inline':'none';}} function addLog(type,args,source){var msg=Array.prototype.slice.call(args).map(function(a){if(typeof a==='object'){try{return JSON.stringify(a,null,2);}catch(e){return String(a);}}return String(a);}).join(' ');var hash=hashError(msg,source),time=new Date().toLocaleTimeString();logs.push({type:type,msg:msg,source:source,time:time,hash:hash});counts.all++;counts[type]=(counts[type]||0)+1;updateCounts();if(type==='error')showErrorToast(msg,hash);if(currentFilter!=='resources')renderLogs();} - function renderLogs(){var body=document.getElementById('argon-debug-console-body');if(!body)return;var filtered=currentFilter==='all'?logs:logs.filter(function(l){return l.type===currentFilter;});body.innerHTML=filtered.map(function(log){var muted=isMuted(log.hash);var muteBtn=isAdmin&&log.type==='error'?'':'';return '
'+muteBtn+'['+log.time+'] '+log.msg.replace(//g,'>').replace(/\n/g,'
')+(log.source?''+log.source+'':'')+'
';}).join('');body.scrollTop=body.scrollHeight;} + function renderLogs(){var body=document.getElementById('argon-debug-console-body');if(!body)return;var filtered=currentFilter==='all'?logs:logs.filter(function(l){return l.type===currentFilter;});body.innerHTML=filtered.map(function(log,idx){var muted=isMuted(log.hash);var muteBtn=isAdmin&&log.type==='error'?'':'';return '
'+muteBtn+'['+log.time+'] '+log.msg.replace(//g,'>').replace(/\n/g,'
')+(log.source?''+log.source+'':'')+'
';}).join('');body.scrollTop=body.scrollHeight;} + // 长按复制功能 + var longPressTimer=null,longPressTarget=null; + document.addEventListener('touchstart',function(e){var item=e.target.closest('.debug-log-item');if(item){longPressTarget=item;longPressTimer=setTimeout(function(){var idx=parseInt(item.dataset.logIdx);if(!isNaN(idx)&&logs[idx]){var text='['+logs[idx].time+'] '+logs[idx].msg+(logs[idx].source?' ('+logs[idx].source+')':'');copyToClipboard(text);item.classList.add('copying');setTimeout(function(){item.classList.remove('copying');},300);}},500);}},{passive:true}); + document.addEventListener('touchend',function(){if(longPressTimer){clearTimeout(longPressTimer);longPressTimer=null;}},{passive:true}); + document.addEventListener('touchmove',function(){if(longPressTimer){clearTimeout(longPressTimer);longPressTimer=null;}},{passive:true}); + function copyToClipboard(text){if(navigator.clipboard){navigator.clipboard.writeText(text).then(function(){showCopyToast('');});}else{var ta=document.createElement('textarea');ta.value=text;ta.style.position='fixed';ta.style.opacity='0';document.body.appendChild(ta);ta.select();document.execCommand('copy');document.body.removeChild(ta);showCopyToast('');}} + function showCopyToast(msg){var t=document.createElement('div');t.className='debug-copy-toast';t.textContent=msg;document.body.appendChild(t);setTimeout(function(){t.remove();},1000);} var oc={log:console.log,warn:console.warn,error:console.error,info:console.info}; console.log=function(){addLog('log',arguments);}; console.info=function(){addLog('log',arguments);};