diff --git a/functions.php b/functions.php
index b007193..43bda6f 100644
--- a/functions.php
+++ b/functions.php
@@ -600,12 +600,14 @@ function argon_debug_console_script() {
// 获取版本信息
$theme_version = $GLOBALS['theme_version'];
+ $assets_version = function_exists('argon_get_assets_version') ? argon_get_assets_version() : $theme_version;
$wp_version = get_bloginfo('version');
$php_version = phpversion();
$git_info = function_exists('argon_get_git_info') ? argon_get_git_info() : null;
+ $force_refresh_enabled = function_exists('argon_is_force_refresh_enabled') ? argon_is_force_refresh_enabled() : false;
?>
@@ -647,6 +669,7 @@ function argon_debug_console_script() {
Theme:
+ Assets:
WP:
PHP:
Git:
@@ -657,6 +680,7 @@ function argon_debug_console_script() {
+
@@ -673,15 +697,101 @@ function argon_debug_console_script() {
var mutedHashes = ;
var ajaxUrl = '';
var nonce = '';
- var logs = [], counts = {all:0,log:0,warn:0,error:0}, currentFilter = 'all';
+ var forceRefreshEnabled = ;
+ var logs = [], counts = {all:0,log:0,warn:0,error:0,resources:0}, currentFilter = 'all';
+ var resourcesData = [];
var uaEl = document.getElementById('argon-debug-ua');
if(uaEl){uaEl.textContent=navigator.userAgent;uaEl.title=navigator.userAgent;}
+
+ // 收集页面资源信息
+ function collectResources() {
+ resourcesData = [];
+ var entries = performance.getEntriesByType('resource');
+ entries.forEach(function(entry) {
+ var url = entry.name;
+ var type = 'other';
+ var name = url.split('/').pop().split('?')[0];
+ var version = '';
+
+ // 提取版本号
+ var verMatch = url.match(/[?&]v(?:er)?=([^&]+)/);
+ if (verMatch) version = verMatch[1];
+
+ // 判断资源类型
+ if (/\.css(\?|$)/i.test(url)) type = 'css';
+ else if (/\.js(\?|$)/i.test(url)) type = 'js';
+ else if (/\.(woff2?|ttf|eot|otf)(\?|$)/i.test(url)) type = 'font';
+ else if (/\.(png|jpe?g|gif|svg|webp|ico)(\?|$)/i.test(url)) type = 'img';
+
+ // 只显示主题相关资源或有版本号的资源
+ var isThemeResource = url.indexOf('/themes/') !== -1 || url.indexOf('/argon') !== -1;
+ if (type === 'css' || type === 'js' || isThemeResource) {
+ resourcesData.push({
+ type: type,
+ name: name,
+ url: url,
+ version: version,
+ size: entry.transferSize || 0,
+ duration: Math.round(entry.duration),
+ cached: entry.transferSize === 0 && entry.decodedBodySize > 0
+ });
+ }
+ });
+ counts.resources = resourcesData.length;
+ document.getElementById('count-resources').textContent = counts.resources;
+ }
+
+ // 渲染资源列表
+ function renderResources() {
+ var body = document.getElementById('argon-debug-console-body');
+ if (!body) return;
+
+ var cssCount = 0, jsCount = 0, totalSize = 0, cachedCount = 0;
+ resourcesData.forEach(function(r) {
+ if (r.type === 'css') cssCount++;
+ if (r.type === 'js') jsCount++;
+ totalSize += r.size;
+ if (r.cached) cachedCount++;
+ });
+
+ var html = '';
+ html += forceRefreshEnabled ? '✓ ' : '';
+ html += '
';
+
+ html += '';
+ html += '
' + resourcesData.length + '
';
+ html += '
';
+ html += '
';
+ html += '
' + formatSize(totalSize) + '
';
+ html += '
';
+ html += '
';
+
+ resourcesData.forEach(function(r) {
+ html += '';
+ html += '' + r.type.toUpperCase() + '';
+ html += '' + r.name + '';
+ if (r.version) html += 'v' + r.version + '';
+ if (r.size > 0) html += '' + formatSize(r.size) + '';
+ html += '' + (r.cached ? '' : '') + '';
+ html += '
';
+ });
+
+ body.innerHTML = html;
+ }
+
+ function formatSize(bytes) {
+ if (bytes === 0) return '0 B';
+ if (bytes < 1024) return bytes + ' B';
+ if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(1) + ' KB';
+ return (bytes / (1024 * 1024)).toFixed(2) + ' MB';
+ }
+
function hashError(m,s){var str=(m||'')+'|'+(s||''),h=0;for(var i=0;i';t.querySelector('.message').textContent=dm.length>80?dm.substring(0,80)+'...':dm;t.classList.add('show');setTimeout(function(){t.classList.remove('show');},5000);}
+ 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);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 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;}
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);};
@@ -691,9 +801,15 @@ function argon_debug_console_script() {
window.addEventListener('unhandledrejection',function(e){addLog('error',['Promise: '+(e.reason?(e.reason.message||e.reason):'Unknown')]);});
var panel=document.getElementById('argon-debug-console'),header=document.getElementById('argon-debug-console-header');
if(window.innerWidth>768&&header&&panel){var isDragging=false,startX,startY,startLeft,startTop;header.addEventListener('mousedown',function(e){if(e.target.tagName==='BUTTON')return;isDragging=true;startX=e.clientX;startY=e.clientY;var rect=panel.getBoundingClientRect();startLeft=rect.left;startTop=rect.top;panel.style.transition='none';});document.addEventListener('mousemove',function(e){if(!isDragging)return;var newLeft=Math.max(0,Math.min(startLeft+e.clientX-startX,window.innerWidth-panel.offsetWidth));var newTop=Math.max(0,Math.min(startTop+e.clientY-startY,window.innerHeight-panel.offsetHeight));panel.style.left=newLeft+'px';panel.style.top=newTop+'px';panel.style.bottom='auto';panel.style.right='auto';});document.addEventListener('mouseup',function(){isDragging=false;panel.style.transition='';});}
- document.querySelectorAll('#argon-debug-console-tabs button').forEach(function(btn){btn.addEventListener('click',function(){document.querySelectorAll('#argon-debug-console-tabs button').forEach(function(b){b.classList.remove('active');});this.classList.add('active');currentFilter=this.dataset.filter;renderLogs();});});
- window.argonDebug={toggle:function(){panel.classList.toggle('show');},clear:function(){logs=[];counts={all:0,log:0,warn:0,error:0};updateCounts();renderLogs();},mute:function(hash,msg,source){if(!isAdmin)return;var xhr=new XMLHttpRequest();xhr.open('POST',ajaxUrl);xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');xhr.onload=function(){if(xhr.status===200){mutedHashes.push(hash);renderLogs();}};xhr.send('action=argon_mute_error&nonce='+nonce+'&error_hash='+hash+'&error_message='+msg+'&error_source='+source);}};
- console.log(' - Theme v');
+ document.querySelectorAll('#argon-debug-console-tabs button').forEach(function(btn){btn.addEventListener('click',function(){document.querySelectorAll('#argon-debug-console-tabs button').forEach(function(b){b.classList.remove('active');});this.classList.add('active');currentFilter=this.dataset.filter;if(currentFilter==='resources'){collectResources();renderResources();}else{renderLogs();}});});
+ window.argonDebug={toggle:function(){panel.classList.toggle('show');if(panel.classList.contains('show')&¤tFilter==='resources'){collectResources();renderResources();}},clear:function(){logs=[];counts={all:0,log:0,warn:0,error:0,resources:counts.resources};updateCounts();renderLogs();},mute:function(hash,msg,source){if(!isAdmin)return;var xhr=new XMLHttpRequest();xhr.open('POST',ajaxUrl);xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');xhr.onload=function(){if(xhr.status===200){mutedHashes.push(hash);renderLogs();}};xhr.send('action=argon_mute_error&nonce='+nonce+'&error_hash='+hash+'&error_message='+msg+'&error_source='+source);}};
+
+ // 页面加载完成后收集资源
+ window.addEventListener('load', function() {
+ setTimeout(collectResources, 100);
+ });
+
+ console.log(' - Theme v, Assets v');
})();