Cosplay

// 你的插件加载这段 JS,不需要任何额外的 PHP AJAX 接口 document.addEventListener('DOMContentLoaded', function() { // 只有游客状态才执行,登录用户不需要搞这些 if (document.body.classList.contains('logged-in')) return; // 监听所有常见的登录名输入框或密码框 const formInputs = document.querySelectorAll('input[name="log"], input[name="username"], input[name="pwd"], input[name="password"]'); let isFetched = false; formInputs.forEach(input => { // 用户只要点击输入框准备打字,立刻去抓新鲜的安检票 input.addEventListener('focus', function() { if (isFetched) return; isFetched = true; const nonceInputs = document.querySelectorAll('input[name="_wpnonce"], input[name="security"]'); if (nonceInputs.length === 0) return; // 带上时间戳绕过 Nginx 缓存,强刷当前页面的新鲜 DOM const currentUrl = new URL(window.location.href); currentUrl.searchParams.set('_nocache', Date.now()); fetch(currentUrl.toString(), { headers: { 'X-Requested-With': 'XMLHttpRequest' } }) .then(res => res.text()) .then(html => { const parser = new DOMParser(); const freshDoc = parser.parseFromString(html, 'text/html'); // 按顺序直接用新鲜页面的原配 Token 覆盖,根本不需要知道它的 Action 叫啥 nonceInputs.forEach((inputDOM, index) => { const freshInput = freshDoc.querySelectorAll(`input[name="${inputDOM.name}"]`)[index]; if (freshInput) { inputDOM.value = freshInput.value; } }); console.log('[Cache-Plugin] Nonce 偷换成功,避开主题校验报错'); }).catch(err => console.warn('抓取失败', err)); }); }); });